Merge "Disable commit validation in RebaseIfNecessary"

This commit is contained in:
Shawn Pearce 2013-07-29 18:48:02 +00:00 committed by Gerrit Code Review
commit d64aefbcde
4 changed files with 30 additions and 9 deletions

View File

@ -14,6 +14,8 @@
package com.google.gerrit.server;
import static com.google.gerrit.server.change.PatchSetInserter.ValidatePolicy.RECEIVE_COMMITS;
import com.google.gerrit.common.ChangeHooks;
import com.google.gerrit.common.errors.EmailException;
import com.google.gerrit.reviewdb.client.Change;
@ -381,7 +383,7 @@ public class ChangeUtil {
.setPatchSet(newPatchSet)
.setMessage(msg)
.setCopyLabels(true)
.setValidateForReceiveCommits(true)
.setValidatePolicy(RECEIVE_COMMITS)
.insert();
return change.getId();

View File

@ -15,6 +15,7 @@
package com.google.gerrit.server.change;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Sets;
import com.google.gerrit.common.ChangeHooks;
@ -71,6 +72,15 @@ public class PatchSetInserter {
IdentifiedUser user, Change change, RevCommit commit);
}
/**
* Whether to use {@link CommitValidators#validateForGerritCommits},
* {@link CommitValidators#validateForReceiveCommits}, or no commit
* validation.
*/
public static enum ValidatePolicy {
GERRIT, RECEIVE_COMMITS, NONE;
}
private final ChangeHooks hooks;
private final TrackingFooters trackingFooters;
private final PatchSetInfoFactory patchSetInfoFactory;
@ -79,7 +89,6 @@ public class PatchSetInserter {
private final GitReferenceUpdated gitRefUpdated;
private final CommitValidators.Factory commitValidatorsFactory;
private final ChangeIndexer indexer;
private boolean validateForReceiveCommits;
private final ReplacePatchSetSender.Factory replacePatchSetFactory;
private final Repository git;
@ -92,6 +101,7 @@ public class PatchSetInserter {
private ChangeMessage changeMessage;
private boolean copyLabels;
private SshInfo sshInfo;
private ValidatePolicy validatePolicy = ValidatePolicy.GERRIT;
private boolean draft;
private boolean runHooks;
private boolean sendMail;
@ -163,8 +173,8 @@ public class PatchSetInserter {
return this;
}
public PatchSetInserter setValidateForReceiveCommits(boolean validate) {
this.validateForReceiveCommits = validate;
public PatchSetInserter setValidatePolicy(ValidatePolicy validate) {
this.validatePolicy = checkNotNull(validate);
return this;
}
@ -316,10 +326,13 @@ public class PatchSetInserter {
commit, user);
try {
if (validateForReceiveCommits) {
switch (validatePolicy) {
case RECEIVE_COMMITS:
cv.validateForReceiveCommits(event);
} else {
break;
case GERRIT:
cv.validateForGerritCommits(event);
break;
}
} catch (CommitValidationException e) {
throw new InvalidChangeOperationException(e.getMessage());

View File

@ -14,6 +14,8 @@
package com.google.gerrit.server.changedetail;
import static com.google.gerrit.server.change.PatchSetInserter.ValidatePolicy;
import com.google.gerrit.common.errors.EmailException;
import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change;
@ -131,7 +133,7 @@ public class RebaseChange {
rebase(git, rw, inserter, patchSetId, change,
uploader, baseCommit, mergeUtilFactory.create(
changeControl.getProjectControl().getProjectState(), true),
committerIdent, true, true);
committerIdent, true, true, ValidatePolicy.GERRIT);
} catch (PathConflictException e) {
throw new IOException(e.getMessage());
} finally {
@ -257,6 +259,7 @@ public class RebaseChange {
* @param committerIdent the committer's identity
* @param sendMail if a mail notification should be sent for the new patch set
* @param runHooks if hooks should be run for the new patch set
* @param validate if commit validation should be run for the new patch set
* @return the new patch set which is based on the given base commit
* @throws NoSuchChangeException thrown if the change to which the patch set
* belongs does not exist or is not visible to the user
@ -268,7 +271,7 @@ public class RebaseChange {
final ObjectInserter inserter, final PatchSet.Id patchSetId,
final Change change, final IdentifiedUser uploader, final RevCommit baseCommit,
final MergeUtil mergeUtil, PersonIdent committerIdent,
boolean sendMail, boolean runHooks)
boolean sendMail, boolean runHooks, ValidatePolicy validate)
throws NoSuchChangeException,
OrmException, IOException, InvalidChangeOperationException,
PathConflictException {
@ -290,6 +293,7 @@ public class RebaseChange {
PatchSetInserter patchSetinserter = patchSetInserterFactory
.create(git, revWalk, changeControl.getRefControl(), uploader, change, rebasedCommit)
.setCopyLabels(true)
.setValidatePolicy(validate)
.setDraft(originalPatchSet.isDraft())
.setSendMail(sendMail)
.setRunHooks(runHooks);

View File

@ -14,6 +14,8 @@
package com.google.gerrit.server.git;
import static com.google.gerrit.server.change.PatchSetInserter.ValidatePolicy;
import com.google.common.collect.Lists;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
@ -84,7 +86,7 @@ public class RebaseIfNecessary extends SubmitStrategy {
rebaseChange.rebase(args.repo, args.rw, args.inserter,
n.patchsetId, n.change, uploader,
newMergeTip, args.mergeUtil, committerIdent,
false, false);
false, false, ValidatePolicy.NONE);
List<PatchSetApproval> approvals = Lists.newArrayList();
for (PatchSetApproval a : args.mergeUtil.getApprovalsForCommit(n)) {
approvals.add(new PatchSetApproval(newPatchSet.getId(), a));