Merge "Fix: failed to validate Change-Id of some new patch-sets pushed by 'refs/changes'" into stable-2.6

This commit is contained in:
Shawn Pearce 2013-06-10 16:48:49 +00:00 committed by Gerrit Code Review
commit ea2a0d8c95
3 changed files with 16 additions and 11 deletions

View File

@ -42,6 +42,7 @@ import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.RefControl;
import com.google.gerrit.server.util.IdGenerator;
import com.google.gerrit.server.util.MagicBranch;
import com.google.gwtorm.server.AtomicUpdate;
import com.google.gwtorm.server.OrmConcurrencyException;
import com.google.gwtorm.server.OrmException;
@ -256,11 +257,14 @@ public class ChangeUtil {
ps.setUploader(change.getOwner());
ps.setRevision(new RevId(revertCommit.name()));
String ref = refControl.getRefName();
final String cmdRef =
MagicBranch.NEW_PUBLISH_CHANGE
+ ref.substring(ref.lastIndexOf("/") + 1);
CommitReceivedEvent commitReceivedEvent =
new CommitReceivedEvent(new ReceiveCommand(ObjectId.zeroId(),
revertCommit.getId(), ps.getRefName()), refControl
.getProjectControl().getProject(), refControl.getRefName(),
revertCommit, user);
revertCommit.getId(), cmdRef), refControl.getProjectControl()
.getProject(), refControl.getRefName(), revertCommit, user);
try {
commitValidators.validateForGerritCommits(commitReceivedEvent);
@ -377,9 +381,11 @@ public class ChangeUtil {
final PatchSetInfo info =
patchSetInfoFactory.get(newCommit, newPatchSet.getId());
final String refName = newPatchSet.getRefName();
CommitReceivedEvent commitReceivedEvent =
new CommitReceivedEvent(new ReceiveCommand(ObjectId.zeroId(),
newCommit.getId(), newPatchSet.getRefName()), refControl
newCommit.getId(), refName.substring(0,
refName.lastIndexOf("/") + 1) + "new"), refControl
.getProjectControl().getProject(), refControl.getRefName(),
newCommit, user);

View File

@ -144,7 +144,7 @@ public class ReceiveCommits {
private static final Logger log =
LoggerFactory.getLogger(ReceiveCommits.class);
private static final Pattern NEW_PATCHSET =
public static final Pattern NEW_PATCHSET =
Pattern.compile("^refs/changes/(?:[0-9][0-9]/)?([1-9][0-9]*)(?:/new)?$");
private static final FooterKey CHANGE_ID = new FooterKey("Change-Id");

View File

@ -22,6 +22,7 @@ import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.events.CommitReceivedEvent;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.ProjectConfig;
import com.google.gerrit.server.git.ReceiveCommits;
import com.google.gerrit.server.git.ValidationError;
import com.google.gerrit.server.project.ProjectControl;
import com.google.gerrit.server.project.RefControl;
@ -47,7 +48,6 @@ import java.net.URL;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
@ -57,9 +57,6 @@ public class CommitValidators {
private static final FooterKey CHANGE_ID = new FooterKey("Change-Id");
private static final Pattern NEW_PATCHSET = Pattern
.compile("^refs/changes/(?:[0-9][0-9])?(/[1-9][0-9]*){1,2}(?:/new)?$");
public interface Factory {
CommitValidators create(RefControl refControl, SshInfo sshInfo,
Repository repo);
@ -99,7 +96,8 @@ public class CommitValidators {
validators.add(new CommitterUploaderValidator(refControl, canonicalWebUrl));
validators.add(new SignedOffByValidator(refControl, canonicalWebUrl));
if (MagicBranch.isMagicBranch(receiveEvent.command.getRefName())
|| NEW_PATCHSET.matcher(receiveEvent.command.getRefName()).matches()) {
|| ReceiveCommits.NEW_PATCHSET.matcher(
receiveEvent.command.getRefName()).matches()) {
validators.add(new ChangeIdValidator(refControl, canonicalWebUrl, sshInfo));
}
validators.add(new ConfigValidator(refControl, repo));
@ -132,7 +130,8 @@ public class CommitValidators {
validators.add(new AuthorUploaderValidator(refControl, canonicalWebUrl));
validators.add(new SignedOffByValidator(refControl, canonicalWebUrl));
if (MagicBranch.isMagicBranch(receiveEvent.command.getRefName())
|| NEW_PATCHSET.matcher(receiveEvent.command.getRefName()).matches()) {
|| ReceiveCommits.NEW_PATCHSET.matcher(
receiveEvent.command.getRefName()).matches()) {
validators.add(new ChangeIdValidator(refControl, canonicalWebUrl, sshInfo));
}
validators.add(new ConfigValidator(refControl, repo));