Merge changes from topic 'already-merged-message'
* changes: Insert ChangeMessage when repairing ALREADY_MERGED change Don't reuse ALREADY_MERGED for an identical tree
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.git.strategy;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.gerrit.server.git.strategy.CommitMergeStatus.SKIPPED_IDENTICAL_TREE;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.extensions.restapi.MergeConflictException;
|
||||
@@ -126,7 +127,7 @@ public class CherryPick extends SubmitStrategy {
|
||||
toMerge.setStatusCode(CommitMergeStatus.PATH_CONFLICT);
|
||||
return;
|
||||
} catch (MergeIdenticalTreeException mie) {
|
||||
toMerge.setStatusCode(CommitMergeStatus.ALREADY_MERGED);
|
||||
toMerge.setStatusCode(SKIPPED_IDENTICAL_TREE);
|
||||
return;
|
||||
}
|
||||
// Initial copy doesn't have new patch set ID since change hasn't been
|
||||
@@ -146,6 +147,10 @@ public class CherryPick extends SubmitStrategy {
|
||||
@Override
|
||||
public PatchSet updateChangeImpl(ChangeContext ctx) throws OrmException,
|
||||
NoSuchChangeException, IOException {
|
||||
if (newCommit == null
|
||||
&& toMerge.getStatusCode() == SKIPPED_IDENTICAL_TREE) {
|
||||
return null;
|
||||
}
|
||||
checkState(newCommit != null,
|
||||
"no new commit produced by CherryPick of %s, expected to fail fast",
|
||||
toMerge.change().getId());
|
||||
|
||||
@@ -36,6 +36,9 @@ public enum CommitMergeStatus {
|
||||
+ "\n"
|
||||
+ "Please rebase the change locally and upload the rebased commit for review."),
|
||||
|
||||
SKIPPED_IDENTICAL_TREE(
|
||||
"Marking change merged without cherry-picking to branch, as the resulting commit would be empty."),
|
||||
|
||||
MISSING_DEPENDENCY(""),
|
||||
|
||||
MANUAL_RECURSIVE_MERGE("The change requires a local merge to resolve.\n"
|
||||
|
||||
@@ -78,6 +78,7 @@ public abstract class SubmitStrategy {
|
||||
static class Arguments {
|
||||
interface Factory {
|
||||
Arguments create(
|
||||
SubmitType submitType,
|
||||
Branch.NameKey destBranch,
|
||||
CommitStatus commits,
|
||||
CodeReviewRevWalk rw,
|
||||
@@ -118,6 +119,7 @@ public abstract class SubmitStrategy {
|
||||
final ReviewDb db;
|
||||
final Set<RevCommit> alreadyAccepted;
|
||||
final String submissionId;
|
||||
final SubmitType submitType;
|
||||
|
||||
final ProjectState project;
|
||||
final MergeSorter mergeSorter;
|
||||
@@ -151,7 +153,8 @@ public abstract class SubmitStrategy {
|
||||
@Assisted RevFlag canMergeFlag,
|
||||
@Assisted ReviewDb db,
|
||||
@Assisted Set<RevCommit> alreadyAccepted,
|
||||
@Assisted String submissionId) {
|
||||
@Assisted String submissionId,
|
||||
@Assisted SubmitType submitType) {
|
||||
this.accountCache = accountCache;
|
||||
this.approvalsUtil = approvalsUtil;
|
||||
this.batchUpdateFactory = batchUpdateFactory;
|
||||
@@ -179,6 +182,7 @@ public abstract class SubmitStrategy {
|
||||
this.db = db;
|
||||
this.alreadyAccepted = alreadyAccepted;
|
||||
this.submissionId = submissionId;
|
||||
this.submitType = submitType;
|
||||
|
||||
this.project = checkNotNull(projectCache.get(destBranch.getParentKey()),
|
||||
"project not found: %s", destBranch.getParentKey());
|
||||
|
||||
@@ -53,9 +53,9 @@ public class SubmitStrategyFactory {
|
||||
Branch.NameKey destBranch, IdentifiedUser caller, MergeTip mergeTip,
|
||||
CommitStatus commits, String submissionId)
|
||||
throws IntegrationException {
|
||||
SubmitStrategy.Arguments args = argsFactory.create(destBranch, commits, rw,
|
||||
caller, mergeTip, inserter, repo, canMergeFlag, db, alreadyAccepted,
|
||||
submissionId);
|
||||
SubmitStrategy.Arguments args = argsFactory.create(submitType, destBranch,
|
||||
commits, rw, caller, mergeTip, inserter, repo, canMergeFlag, db,
|
||||
alreadyAccepted, submissionId);
|
||||
switch (submitType) {
|
||||
case CHERRY_PICK:
|
||||
return new CherryPick(args);
|
||||
|
||||
@@ -106,6 +106,7 @@ public class SubmitStrategyListener extends BatchUpdate.Listener {
|
||||
case CLEAN_MERGE:
|
||||
case CLEAN_REBASE:
|
||||
case CLEAN_PICK:
|
||||
case SKIPPED_IDENTICAL_TREE:
|
||||
break; // Merge strategy accepted this change.
|
||||
|
||||
case ALREADY_MERGED:
|
||||
|
||||
@@ -265,22 +265,7 @@ abstract class SubmitStrategyOp extends BatchUpdate.Op {
|
||||
// corresponding to the merge result. This results in a different
|
||||
// ChangeMergedEvent in the fixup case, but we'll just live with that.
|
||||
: alreadyMerged;
|
||||
String txt = s.getMessage();
|
||||
|
||||
ChangeMessage msg;
|
||||
if (s == CommitMergeStatus.CLEAN_MERGE) {
|
||||
msg = message(ctx, commit.getPatchsetId(), txt + getByAccountName());
|
||||
} else if (s == CommitMergeStatus.CLEAN_REBASE
|
||||
|| s == CommitMergeStatus.CLEAN_PICK) {
|
||||
msg = message(ctx, commit.getPatchsetId(),
|
||||
txt + " as " + commit.name() + getByAccountName());
|
||||
} else if (s == CommitMergeStatus.ALREADY_MERGED) {
|
||||
msg = null;
|
||||
} else {
|
||||
throw new IllegalStateException("unexpected status " + s +
|
||||
" for change " + c.getId() + "; expected to previously fail fast");
|
||||
}
|
||||
setMerged(ctx, msg);
|
||||
setMerged(ctx, message(ctx, commit, s));
|
||||
} catch (OrmException err) {
|
||||
String msg = "Error updating change status for " + id;
|
||||
log.error(msg, err);
|
||||
@@ -425,6 +410,39 @@ abstract class SubmitStrategyOp extends BatchUpdate.Op {
|
||||
return "";
|
||||
}
|
||||
|
||||
private ChangeMessage message(ChangeContext ctx, CodeReviewCommit commit,
|
||||
CommitMergeStatus s) {
|
||||
String txt = s.getMessage();
|
||||
if (s == CommitMergeStatus.CLEAN_MERGE) {
|
||||
return message(ctx, commit.getPatchsetId(), txt + getByAccountName());
|
||||
} else if (s == CommitMergeStatus.CLEAN_REBASE
|
||||
|| s == CommitMergeStatus.CLEAN_PICK) {
|
||||
return message(ctx, commit.getPatchsetId(),
|
||||
txt + " as " + commit.name() + getByAccountName());
|
||||
} else if (s == CommitMergeStatus.SKIPPED_IDENTICAL_TREE) {
|
||||
return message(ctx, commit.getPatchsetId(), txt);
|
||||
} else if (s == CommitMergeStatus.ALREADY_MERGED) {
|
||||
// Best effort to mimic the message that would have happened had this
|
||||
// succeeded the first time around.
|
||||
switch (args.submitType) {
|
||||
case FAST_FORWARD_ONLY:
|
||||
case MERGE_ALWAYS:
|
||||
case MERGE_IF_NECESSARY:
|
||||
return message(ctx, commit, CommitMergeStatus.CLEAN_MERGE);
|
||||
case CHERRY_PICK:
|
||||
return message(ctx, commit, CommitMergeStatus.CLEAN_PICK);
|
||||
case REBASE_IF_NECESSARY:
|
||||
return message(ctx, commit, CommitMergeStatus.CLEAN_REBASE);
|
||||
default:
|
||||
return message(ctx, commit, null);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException("unexpected status " + s
|
||||
+ " for change " + commit.change().getId()
|
||||
+ "; expected to previously fail fast");
|
||||
}
|
||||
}
|
||||
|
||||
private ChangeMessage message(ChangeContext ctx, PatchSet.Id psId,
|
||||
String body) {
|
||||
checkNotNull(psId);
|
||||
|
||||
Reference in New Issue
Block a user