Rename MergeException to IntegrationException

It's confusing to have MergeException and MergeConflictException be
two different types that don't share a hierarchy: if I have a merge
conflict, which one should I throw?

We've already started using the term "integrate" to mean "submit a
change and make it a part of the target branch". This is specifically
the situation in which MergeException was used, so let's just rename
it to IntegrationException.

Change-Id: I344c70bf8ffeb3a2823a65b5fcf09ea9bff82e72
This commit is contained in:
Dave Borowitz
2015-10-28 15:51:40 -04:00
parent f0112b9a74
commit bae5d689b0
14 changed files with 102 additions and 94 deletions

View File

@@ -25,7 +25,7 @@ import com.google.gerrit.extensions.webui.UiAction;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.RefNames; import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.git.MergeException; import com.google.gerrit.server.git.IntegrationException;
import com.google.gerrit.server.git.UpdateException; import com.google.gerrit.server.git.UpdateException;
import com.google.gerrit.server.project.ChangeControl; import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.InvalidChangeOperationException; import com.google.gerrit.server.project.InvalidChangeOperationException;
@@ -87,7 +87,7 @@ public class CherryPick implements RestModifyView<RevisionResource, CherryPickIn
return json.create(ChangeJson.NO_OPTIONS).format(cherryPickedChangeId); return json.create(ChangeJson.NO_OPTIONS).format(cherryPickedChangeId);
} catch (InvalidChangeOperationException e) { } catch (InvalidChangeOperationException e) {
throw new BadRequestException(e.getMessage()); throw new BadRequestException(e.getMessage());
} catch (MergeException | NoSuchChangeException e) { } catch (IntegrationException | NoSuchChangeException e) {
throw new ResourceConflictException(e.getMessage()); throw new ResourceConflictException(e.getMessage());
} }
} }

View File

@@ -34,7 +34,7 @@ import com.google.gerrit.server.git.BatchUpdate;
import com.google.gerrit.server.git.CodeReviewCommit; import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk; import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk;
import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.MergeException; import com.google.gerrit.server.git.IntegrationException;
import com.google.gerrit.server.git.MergeIdenticalTreeException; import com.google.gerrit.server.git.MergeIdenticalTreeException;
import com.google.gerrit.server.git.MergeUtil; import com.google.gerrit.server.git.MergeUtil;
import com.google.gerrit.server.git.UpdateException; import com.google.gerrit.server.git.UpdateException;
@@ -112,7 +112,7 @@ public class CherryPickChange {
final RefControl refControl) throws NoSuchChangeException, final RefControl refControl) throws NoSuchChangeException,
OrmException, MissingObjectException, OrmException, MissingObjectException,
IncorrectObjectTypeException, IOException, IncorrectObjectTypeException, IOException,
InvalidChangeOperationException, MergeException, UpdateException, InvalidChangeOperationException, IntegrationException, UpdateException,
RestApiException { RestApiException {
if (Strings.isNullOrEmpty(ref)) { if (Strings.isNullOrEmpty(ref)) {
@@ -195,7 +195,7 @@ public class CherryPickChange {
return newChange.getId(); return newChange.getId();
} }
} catch (MergeIdenticalTreeException | MergeConflictException e) { } catch (MergeIdenticalTreeException | MergeConflictException e) {
throw new MergeException("Cherry pick failed: " + e.getMessage()); throw new IntegrationException("Cherry pick failed: " + e.getMessage());
} }
} catch (RepositoryNotFoundException e) { } catch (RepositoryNotFoundException e) {
throw new NoSuchChangeException(change.getId(), e); throw new NoSuchChangeException(change.getId(), e);

View File

@@ -34,7 +34,7 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.cache.CacheModule; import com.google.gerrit.server.cache.CacheModule;
import com.google.gerrit.server.git.CodeReviewCommit; import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk; import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk;
import com.google.gerrit.server.git.MergeException; import com.google.gerrit.server.git.IntegrationException;
import com.google.gerrit.server.git.strategy.SubmitStrategyFactory; import com.google.gerrit.server.git.strategy.SubmitStrategyFactory;
import com.google.gerrit.server.project.NoSuchProjectException; import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.inject.Inject; import com.google.inject.Inject;
@@ -199,7 +199,7 @@ public class MergeabilityCacheImpl implements MergeabilityCache {
@Override @Override
public Boolean call() public Boolean call()
throws NoSuchProjectException, MergeException, IOException { throws NoSuchProjectException, IntegrationException, IOException {
if (key.into.equals(ObjectId.zeroId())) { if (key.into.equals(ObjectId.zeroId())) {
return true; // Assume yes on new branch. return true; // Assume yes on new branch.
} }

View File

@@ -14,19 +14,19 @@
package com.google.gerrit.server.git; package com.google.gerrit.server.git;
/** Indicates the current branch's queue cannot be processed at this time. */ /** Indicates an integration operation (see {@link MergeOp}) failed. */
public class MergeException extends Exception { public class IntegrationException extends Exception {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public MergeException(String msg) { public IntegrationException(String msg) {
super(msg); super(msg);
} }
public MergeException(Throwable why) { public IntegrationException(Throwable why) {
super(why); super(why);
} }
public MergeException(String msg, Throwable why) { public IntegrationException(String msg, Throwable why) {
super(msg, why); super(msg, why);
} }
} }

View File

@@ -226,10 +226,12 @@ public class MergeOp {
mergeTips = new HashMap<>(); mergeTips = new HashMap<>();
} }
private void setDestProject(Branch.NameKey destBranch) throws MergeException { private void setDestProject(Branch.NameKey destBranch)
throws IntegrationException {
destProject = projectCache.get(destBranch.getParentKey()); destProject = projectCache.get(destBranch.getParentKey());
if (destProject == null) { if (destProject == null) {
throw new MergeException("No such project: " + destBranch.getParentKey()); throw new IntegrationException(
"No such project: " + destBranch.getParentKey());
} }
} }
@@ -376,7 +378,7 @@ public class MergeOp {
} }
try { try {
integrateIntoHistory(cs, caller); integrateIntoHistory(cs, caller);
} catch (MergeException e) { } catch (IntegrationException e) {
logError("Merge Conflict", e); logError("Merge Conflict", e);
throw new ResourceConflictException("Merge Conflict", e); throw new ResourceConflictException("Merge Conflict", e);
} }
@@ -387,7 +389,8 @@ public class MergeOp {
} }
private void integrateIntoHistory(ChangeSet cs, IdentifiedUser caller) private void integrateIntoHistory(ChangeSet cs, IdentifiedUser caller)
throws MergeException, NoSuchChangeException, ResourceConflictException { throws IntegrationException, NoSuchChangeException,
ResourceConflictException {
logDebug("Beginning merge attempt on {}", cs); logDebug("Beginning merge attempt on {}", cs);
Map<Branch.NameKey, ListMultimap<SubmitType, ChangeData>> toSubmit = Map<Branch.NameKey, ListMultimap<SubmitType, ChangeData>> toSubmit =
new HashMap<>(); new HashMap<>();
@@ -450,9 +453,9 @@ public class MergeOp {
+ "abandoning open changes"); + "abandoning open changes");
abandonAllOpenChanges(noProject.project()); abandonAllOpenChanges(noProject.project());
} catch (OrmException e) { } catch (OrmException e) {
throw new MergeException("Cannot query the database", e); throw new IntegrationException("Cannot query the database", e);
} catch (IOException e) { } catch (IOException e) {
throw new MergeException("Cannot query the database", e); throw new IntegrationException("Cannot query the database", e);
} finally { } finally {
closeRepository(); closeRepository();
} }
@@ -460,7 +463,7 @@ public class MergeOp {
private MergeTip preMerge(SubmitStrategy strategy, private MergeTip preMerge(SubmitStrategy strategy,
List<ChangeData> submitted, CodeReviewCommit branchTip) List<ChangeData> submitted, CodeReviewCommit branchTip)
throws MergeException, OrmException { throws IntegrationException, OrmException {
logDebug("Running submit strategy {} for {} commits {}", logDebug("Running submit strategy {} for {} commits {}",
strategy.getClass().getSimpleName(), submitted.size(), submitted); strategy.getClass().getSimpleName(), submitted.size(), submitted);
List<CodeReviewCommit> toMerge = new ArrayList<>(submitted.size()); List<CodeReviewCommit> toMerge = new ArrayList<>(submitted.size());
@@ -479,20 +482,20 @@ public class MergeOp {
private SubmitStrategy createStrategy(Branch.NameKey destBranch, private SubmitStrategy createStrategy(Branch.NameKey destBranch,
SubmitType submitType, CodeReviewCommit branchTip, IdentifiedUser caller) SubmitType submitType, CodeReviewCommit branchTip, IdentifiedUser caller)
throws MergeException, NoSuchProjectException { throws IntegrationException, NoSuchProjectException {
return submitStrategyFactory.create(submitType, db, repo, rw, inserter, return submitStrategyFactory.create(submitType, db, repo, rw, inserter,
canMergeFlag, getAlreadyAccepted(branchTip), destBranch, caller); canMergeFlag, getAlreadyAccepted(branchTip), destBranch, caller);
} }
private void openRepository(Project.NameKey name) private void openRepository(Project.NameKey name)
throws MergeException, NoSuchProjectException { throws IntegrationException, NoSuchProjectException {
try { try {
repo = repoManager.openRepository(name); repo = repoManager.openRepository(name);
} catch (RepositoryNotFoundException notFound) { } catch (RepositoryNotFoundException notFound) {
throw new NoSuchProjectException(name, notFound); throw new NoSuchProjectException(name, notFound);
} catch (IOException err) { } catch (IOException err) {
String m = "Error opening repository \"" + name.get() + '"'; String m = "Error opening repository \"" + name.get() + '"';
throw new MergeException(m, err); throw new IntegrationException(m, err);
} }
rw = CodeReviewCommit.newRevWalk(repo); rw = CodeReviewCommit.newRevWalk(repo);
@@ -517,7 +520,7 @@ public class MergeOp {
} }
private RefUpdate getPendingRefUpdate(Branch.NameKey destBranch) private RefUpdate getPendingRefUpdate(Branch.NameKey destBranch)
throws MergeException { throws IntegrationException {
if (pendingRefUpdates.containsKey(destBranch)) { if (pendingRefUpdates.containsKey(destBranch)) {
logDebug("Access cached open branch {}: {}", destBranch.get(), logDebug("Access cached open branch {}: {}", destBranch.get(),
@@ -534,8 +537,8 @@ public class MergeOp {
branchTip = null; branchTip = null;
branchUpdate.setExpectedOldObjectId(ObjectId.zeroId()); branchUpdate.setExpectedOldObjectId(ObjectId.zeroId());
} else { } else {
throw new MergeException("The destination branch " + destBranch.get() throw new IntegrationException("The destination branch "
+ " does not exist anymore."); + destBranch.get() + " does not exist anymore.");
} }
logDebug("Opened branch {}: {}", destBranch.get(), branchTip); logDebug("Opened branch {}: {}", destBranch.get(), branchTip);
@@ -543,12 +546,12 @@ public class MergeOp {
openBranches.put(destBranch, branchTip); openBranches.put(destBranch, branchTip);
return branchUpdate; return branchUpdate;
} catch (IOException e) { } catch (IOException e) {
throw new MergeException("Cannot open branch", e); throw new IntegrationException("Cannot open branch", e);
} }
} }
private CodeReviewCommit getBranchTip(Branch.NameKey destBranch) private CodeReviewCommit getBranchTip(Branch.NameKey destBranch)
throws MergeException { throws IntegrationException {
if (openBranches.containsKey(destBranch)) { if (openBranches.containsKey(destBranch)) {
return openBranches.get(destBranch); return openBranches.get(destBranch);
} else { } else {
@@ -558,7 +561,7 @@ public class MergeOp {
} }
private Set<RevCommit> getAlreadyAccepted(CodeReviewCommit branchTip) private Set<RevCommit> getAlreadyAccepted(CodeReviewCommit branchTip)
throws MergeException { throws IntegrationException {
Set<RevCommit> alreadyAccepted = new HashSet<>(); Set<RevCommit> alreadyAccepted = new HashSet<>();
if (branchTip != null) { if (branchTip != null) {
@@ -574,7 +577,7 @@ public class MergeOp {
} }
} }
} catch (IOException e) { } catch (IOException e) {
throw new MergeException( throw new IntegrationException(
"Failed to determine already accepted commits.", e); "Failed to determine already accepted commits.", e);
} }
@@ -583,7 +586,7 @@ public class MergeOp {
} }
private ListMultimap<SubmitType, ChangeData> validateChangeList( private ListMultimap<SubmitType, ChangeData> validateChangeList(
Collection<ChangeData> submitted) throws MergeException { Collection<ChangeData> submitted) throws IntegrationException {
logDebug("Validating {} changes", submitted.size()); logDebug("Validating {} changes", submitted.size());
ListMultimap<SubmitType, ChangeData> toSubmit = ArrayListMultimap.create(); ListMultimap<SubmitType, ChangeData> toSubmit = ArrayListMultimap.create();
@@ -591,7 +594,7 @@ public class MergeOp {
try { try {
allRefs = repo.getRefDatabase().getRefs(ALL); allRefs = repo.getRefDatabase().getRefs(ALL);
} catch (IOException e) { } catch (IOException e) {
throw new MergeException(e.getMessage(), e); throw new IntegrationException(e.getMessage(), e);
} }
Set<ObjectId> tips = new HashSet<>(); Set<ObjectId> tips = new HashSet<>();
@@ -607,7 +610,7 @@ public class MergeOp {
// Reload change in case index was stale. // Reload change in case index was stale.
chg = cd.reloadChange(); chg = cd.reloadChange();
} catch (OrmException e) { } catch (OrmException e) {
throw new MergeException("Failed to validate changes", e); throw new IntegrationException("Failed to validate changes", e);
} }
Change.Id changeId = cd.getId(); Change.Id changeId = cd.getId();
if (chg.getStatus() != Change.Status.NEW) { if (chg.getStatus() != Change.Status.NEW) {
@@ -625,7 +628,7 @@ public class MergeOp {
try { try {
ps = cd.currentPatchSet(); ps = cd.currentPatchSet();
} catch (OrmException e) { } catch (OrmException e) {
throw new MergeException("Cannot query the database", e); throw new IntegrationException("Cannot query the database", e);
} }
if (ps == null || ps.getRevision() == null if (ps == null || ps.getRevision() == null
|| ps.getRevision().get() == null) { || ps.getRevision().get() == null) {
@@ -718,7 +721,7 @@ public class MergeOp {
} }
private RefUpdate updateBranch(Branch.NameKey destBranch) private RefUpdate updateBranch(Branch.NameKey destBranch)
throws MergeException { throws IntegrationException {
RefUpdate branchUpdate = getPendingRefUpdate(destBranch); RefUpdate branchUpdate = getPendingRefUpdate(destBranch);
CodeReviewCommit branchTip = getBranchTip(destBranch); CodeReviewCommit branchTip = getBranchTip(destBranch);
@@ -746,7 +749,7 @@ public class MergeOp {
new ProjectConfig(destProject.getProject().getNameKey()); new ProjectConfig(destProject.getProject().getNameKey());
cfg.load(repo, currentTip); cfg.load(repo, currentTip);
} catch (Exception e) { } catch (Exception e) {
throw new MergeException("Submit would store invalid" throw new IntegrationException("Submit would store invalid"
+ " project configuration " + currentTip.name() + " for " + " project configuration " + currentTip.name() + " for "
+ destProject.getProject().getName(), e); + destProject.getProject().getName(), e);
} }
@@ -782,13 +785,13 @@ public class MergeOp {
return branchUpdate; return branchUpdate;
case LOCK_FAILURE: case LOCK_FAILURE:
throw new MergeException("Failed to lock " + branchUpdate.getName()); throw new IntegrationException("Failed to lock " + branchUpdate.getName());
default: default:
throw new IOException(branchUpdate.getResult().name() throw new IOException(branchUpdate.getResult().name()
+ '\n' + branchUpdate); + '\n' + branchUpdate);
} }
} catch (IOException e) { } catch (IOException e) {
throw new MergeException("Cannot update " + branchUpdate.getName(), e); throw new IntegrationException("Cannot update " + branchUpdate.getName(), e);
} }
} }
@@ -820,7 +823,7 @@ public class MergeOp {
private void updateChangeStatus(List<ChangeData> submitted, private void updateChangeStatus(List<ChangeData> submitted,
Branch.NameKey destBranch, boolean dryRun, IdentifiedUser caller) Branch.NameKey destBranch, boolean dryRun, IdentifiedUser caller)
throws NoSuchChangeException, MergeException, ResourceConflictException, throws NoSuchChangeException, IntegrationException, ResourceConflictException,
OrmException { OrmException {
if (!dryRun) { if (!dryRun) {
logDebug("Updating change status for {} changes", submitted.size()); logDebug("Updating change status for {} changes", submitted.size());
@@ -896,8 +899,8 @@ public class MergeOp {
case MISSING_DEPENDENCY: case MISSING_DEPENDENCY:
logDebug("Change {} is missing dependency", c.getId()); logDebug("Change {} is missing dependency", c.getId());
throw new MergeException("Cannot merge " + commit.name() + "\n" throw new IntegrationException(
+ s.getMessage()); "Cannot merge " + commit.name() + "\n" + s.getMessage());
case REVISION_GONE: case REVISION_GONE:
logDebug("Commit not found for change {}", c.getId()); logDebug("Commit not found for change {}", c.getId());
@@ -910,12 +913,12 @@ public class MergeOp {
c.currentPatchSetId()); c.currentPatchSetId());
msg.setMessage("Failed to read commit for this patch set"); msg.setMessage("Failed to read commit for this patch set");
setNew(commit.notes(), msg); setNew(commit.notes(), msg);
throw new MergeException(msg.getMessage()); throw new IntegrationException(msg.getMessage());
default: default:
msg = message(c, "Unspecified merge failure: " + s.name()); msg = message(c, "Unspecified merge failure: " + s.name());
setNew(commit.notes(), msg); setNew(commit.notes(), msg);
throw new MergeException(msg.getMessage()); throw new IntegrationException(msg.getMessage());
} }
} catch (OrmException | IOException err) { } catch (OrmException | IOException err) {
logWarn("Error updating change status for " + c.getId(), err); logWarn("Error updating change status for " + c.getId(), err);

View File

@@ -139,7 +139,7 @@ public class MergeUtil {
public CodeReviewCommit getFirstFastForward( public CodeReviewCommit getFirstFastForward(
final CodeReviewCommit mergeTip, final RevWalk rw, final CodeReviewCommit mergeTip, final RevWalk rw,
final List<CodeReviewCommit> toMerge) throws MergeException { final List<CodeReviewCommit> toMerge) throws IntegrationException {
for (final Iterator<CodeReviewCommit> i = toMerge.iterator(); i.hasNext();) { for (final Iterator<CodeReviewCommit> i = toMerge.iterator(); i.hasNext();) {
try { try {
final CodeReviewCommit n = i.next(); final CodeReviewCommit n = i.next();
@@ -148,19 +148,20 @@ public class MergeUtil {
return n; return n;
} }
} catch (IOException e) { } catch (IOException e) {
throw new MergeException("Cannot fast-forward test during merge", e); throw new IntegrationException(
"Cannot fast-forward test during merge", e);
} }
} }
return mergeTip; return mergeTip;
} }
public List<CodeReviewCommit> reduceToMinimalMerge(MergeSorter mergeSorter, public List<CodeReviewCommit> reduceToMinimalMerge(MergeSorter mergeSorter,
Collection<CodeReviewCommit> toSort) throws MergeException { Collection<CodeReviewCommit> toSort) throws IntegrationException {
List<CodeReviewCommit> result = new ArrayList<>(); List<CodeReviewCommit> result = new ArrayList<>();
try { try {
result.addAll(mergeSorter.sort(toSort)); result.addAll(mergeSorter.sort(toSort));
} catch (IOException e) { } catch (IOException e) {
throw new MergeException("Branch head sorting failed", e); throw new IntegrationException("Branch head sorting failed", e);
} }
Collections.sort(result, CodeReviewCommit.ORDER); Collections.sort(result, CodeReviewCommit.ORDER);
return result; return result;
@@ -346,7 +347,7 @@ public class MergeUtil {
public boolean canMerge(final MergeSorter mergeSorter, public boolean canMerge(final MergeSorter mergeSorter,
final Repository repo, final CodeReviewCommit mergeTip, final Repository repo, final CodeReviewCommit mergeTip,
final CodeReviewCommit toMerge) final CodeReviewCommit toMerge)
throws MergeException { throws IntegrationException {
if (hasMissingDependencies(mergeSorter, toMerge)) { if (hasMissingDependencies(mergeSorter, toMerge)) {
return false; return false;
} }
@@ -360,13 +361,13 @@ public class MergeUtil {
} catch (NoMergeBaseException e) { } catch (NoMergeBaseException e) {
return false; return false;
} catch (IOException e) { } catch (IOException e) {
throw new MergeException("Cannot merge " + toMerge.name(), e); throw new IntegrationException("Cannot merge " + toMerge.name(), e);
} }
} }
public boolean canFastForward(MergeSorter mergeSorter, public boolean canFastForward(MergeSorter mergeSorter,
CodeReviewCommit mergeTip, CodeReviewRevWalk rw, CodeReviewCommit toMerge) CodeReviewCommit mergeTip, CodeReviewRevWalk rw, CodeReviewCommit toMerge)
throws MergeException { throws IntegrationException {
if (hasMissingDependencies(mergeSorter, toMerge)) { if (hasMissingDependencies(mergeSorter, toMerge)) {
return false; return false;
} }
@@ -374,13 +375,13 @@ public class MergeUtil {
try { try {
return mergeTip == null || rw.isMergedInto(mergeTip, toMerge); return mergeTip == null || rw.isMergedInto(mergeTip, toMerge);
} catch (IOException e) { } catch (IOException e) {
throw new MergeException("Cannot fast-forward test during merge", e); throw new IntegrationException("Cannot fast-forward test during merge", e);
} }
} }
public boolean canCherryPick(MergeSorter mergeSorter, Repository repo, public boolean canCherryPick(MergeSorter mergeSorter, Repository repo,
CodeReviewCommit mergeTip, CodeReviewRevWalk rw, CodeReviewCommit toMerge) CodeReviewCommit mergeTip, CodeReviewRevWalk rw, CodeReviewCommit toMerge)
throws MergeException { throws IntegrationException {
if (mergeTip == null) { if (mergeTip == null) {
// The branch is unborn. Fast-forward is possible. // The branch is unborn. Fast-forward is possible.
// //
@@ -404,7 +405,7 @@ public class MergeUtil {
m.setBase(toMerge.getParent(0)); m.setBase(toMerge.getParent(0));
return m.merge(mergeTip, toMerge); return m.merge(mergeTip, toMerge);
} catch (IOException e) { } catch (IOException e) {
throw new MergeException("Cannot merge " + toMerge.name(), e); throw new IntegrationException("Cannot merge " + toMerge.name(), e);
} }
} }
@@ -419,11 +420,11 @@ public class MergeUtil {
} }
public boolean hasMissingDependencies(final MergeSorter mergeSorter, public boolean hasMissingDependencies(final MergeSorter mergeSorter,
final CodeReviewCommit toMerge) throws MergeException { final CodeReviewCommit toMerge) throws IntegrationException {
try { try {
return !mergeSorter.sort(Collections.singleton(toMerge)).contains(toMerge); return !mergeSorter.sort(Collections.singleton(toMerge)).contains(toMerge);
} catch (IOException e) { } catch (IOException e) {
throw new MergeException("Branch head sorting failed", e); throw new IntegrationException("Branch head sorting failed", e);
} }
} }
@@ -450,7 +451,8 @@ public class MergeUtil {
public CodeReviewCommit mergeOneCommit(PersonIdent author, public CodeReviewCommit mergeOneCommit(PersonIdent author,
PersonIdent committer, Repository repo, CodeReviewRevWalk rw, PersonIdent committer, Repository repo, CodeReviewRevWalk rw,
ObjectInserter inserter, RevFlag canMergeFlag, Branch.NameKey destBranch, ObjectInserter inserter, RevFlag canMergeFlag, Branch.NameKey destBranch,
CodeReviewCommit mergeTip, CodeReviewCommit n) throws MergeException { CodeReviewCommit mergeTip, CodeReviewCommit n)
throws IntegrationException {
final ThreeWayMerger m = newThreeWayMerger(repo, inserter); final ThreeWayMerger m = newThreeWayMerger(repo, inserter);
try { try {
if (m.merge(new AnyObjectId[] {mergeTip, n})) { if (m.merge(new AnyObjectId[] {mergeTip, n})) {
@@ -464,10 +466,10 @@ public class MergeUtil {
failed(rw, canMergeFlag, mergeTip, n, failed(rw, canMergeFlag, mergeTip, n,
getCommitMergeStatus(e.getReason())); getCommitMergeStatus(e.getReason()));
} catch (IOException e2) { } catch (IOException e2) {
throw new MergeException("Cannot merge " + n.name(), e); throw new IntegrationException("Cannot merge " + n.name(), e);
} }
} catch (IOException e) { } catch (IOException e) {
throw new MergeException("Cannot merge " + n.name(), e); throw new IntegrationException("Cannot merge " + n.name(), e);
} }
return mergeTip; return mergeTip;
} }
@@ -640,7 +642,7 @@ public class MergeUtil {
public void markCleanMerges(final RevWalk rw, public void markCleanMerges(final RevWalk rw,
final RevFlag canMergeFlag, final CodeReviewCommit mergeTip, final RevFlag canMergeFlag, final CodeReviewCommit mergeTip,
final Set<RevCommit> alreadyAccepted) throws MergeException { final Set<RevCommit> alreadyAccepted) throws IntegrationException {
if (mergeTip == null) { if (mergeTip == null) {
// If mergeTip is null here, branchTip was null, indicating a new branch // If mergeTip is null here, branchTip was null, indicating a new branch
// at the start of the merge process. We also elected to merge nothing, // at the start of the merge process. We also elected to merge nothing,
@@ -665,7 +667,7 @@ public class MergeUtil {
} }
} }
} catch (IOException e) { } catch (IOException e) {
throw new MergeException("Cannot mark clean merges", e); throw new IntegrationException("Cannot mark clean merges", e);
} }
} }
} }

View File

@@ -30,7 +30,7 @@ import com.google.gerrit.server.git.BatchUpdate.RepoContext;
import com.google.gerrit.server.git.CodeReviewCommit; import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.git.CommitMergeStatus; import com.google.gerrit.server.git.CommitMergeStatus;
import com.google.gerrit.server.git.GroupCollector; import com.google.gerrit.server.git.GroupCollector;
import com.google.gerrit.server.git.MergeException; import com.google.gerrit.server.git.IntegrationException;
import com.google.gerrit.server.git.MergeIdenticalTreeException; import com.google.gerrit.server.git.MergeIdenticalTreeException;
import com.google.gerrit.server.git.MergeTip; import com.google.gerrit.server.git.MergeTip;
import com.google.gerrit.server.git.UpdateException; import com.google.gerrit.server.git.UpdateException;
@@ -62,7 +62,7 @@ public class CherryPick extends SubmitStrategy {
@Override @Override
protected MergeTip _run(CodeReviewCommit branchTip, protected MergeTip _run(CodeReviewCommit branchTip,
Collection<CodeReviewCommit> toMerge) throws MergeException { Collection<CodeReviewCommit> toMerge) throws IntegrationException {
MergeTip mergeTip = new MergeTip(branchTip, toMerge); MergeTip mergeTip = new MergeTip(branchTip, toMerge);
List<CodeReviewCommit> sorted = CodeReviewCommit.ORDER.sortedCopy(toMerge); List<CodeReviewCommit> sorted = CodeReviewCommit.ORDER.sortedCopy(toMerge);
boolean first = true; boolean first = true;
@@ -83,7 +83,8 @@ public class CherryPick extends SubmitStrategy {
} }
u.execute(); u.execute();
} catch (UpdateException | RestApiException e) { } catch (UpdateException | RestApiException e) {
throw new MergeException("Cannot cherry-pick onto " + args.destBranch); throw new IntegrationException(
"Cannot cherry-pick onto " + args.destBranch);
} }
// TODO(dborowitz): When BatchUpdate is hoisted out of CherryPick, // TODO(dborowitz): When BatchUpdate is hoisted out of CherryPick,
// SubmitStrategy should probably no longer return MergeTip, instead just // SubmitStrategy should probably no longer return MergeTip, instead just
@@ -214,7 +215,8 @@ public class CherryPick extends SubmitStrategy {
} }
@Override @Override
public void updateRepo(RepoContext ctx) throws MergeException, IOException { public void updateRepo(RepoContext ctx)
throws IntegrationException, IOException {
if (args.mergeUtil.hasMissingDependencies(args.mergeSorter, toMerge)) { if (args.mergeUtil.hasMissingDependencies(args.mergeSorter, toMerge)) {
// One or more dependencies were not met. The status was already marked // One or more dependencies were not met. The status was already marked
// on the commit so we have nothing further to perform at this time. // on the commit so we have nothing further to perform at this time.
@@ -249,7 +251,7 @@ public class CherryPick extends SubmitStrategy {
@Override @Override
public boolean dryRun(CodeReviewCommit mergeTip, CodeReviewCommit toMerge) public boolean dryRun(CodeReviewCommit mergeTip, CodeReviewCommit toMerge)
throws MergeException { throws IntegrationException {
return args.mergeUtil.canCherryPick(args.mergeSorter, args.repo, return args.mergeUtil.canCherryPick(args.mergeSorter, args.repo,
mergeTip, args.rw, toMerge); mergeTip, args.rw, toMerge);
} }

View File

@@ -16,7 +16,7 @@ package com.google.gerrit.server.git.strategy;
import com.google.gerrit.server.git.CodeReviewCommit; import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.git.CommitMergeStatus; import com.google.gerrit.server.git.CommitMergeStatus;
import com.google.gerrit.server.git.MergeException; import com.google.gerrit.server.git.IntegrationException;
import com.google.gerrit.server.git.MergeTip; import com.google.gerrit.server.git.MergeTip;
import java.util.Collection; import java.util.Collection;
@@ -29,7 +29,7 @@ public class FastForwardOnly extends SubmitStrategy {
@Override @Override
protected MergeTip _run(final CodeReviewCommit branchTip, protected MergeTip _run(final CodeReviewCommit branchTip,
final Collection<CodeReviewCommit> toMerge) throws MergeException { final Collection<CodeReviewCommit> toMerge) throws IntegrationException {
MergeTip mergeTip = new MergeTip(branchTip, toMerge); MergeTip mergeTip = new MergeTip(branchTip, toMerge);
List<CodeReviewCommit> sorted = args.mergeUtil.reduceToMinimalMerge( List<CodeReviewCommit> sorted = args.mergeUtil.reduceToMinimalMerge(
args.mergeSorter, toMerge); args.mergeSorter, toMerge);
@@ -56,7 +56,7 @@ public class FastForwardOnly extends SubmitStrategy {
@Override @Override
public boolean dryRun(CodeReviewCommit mergeTip, public boolean dryRun(CodeReviewCommit mergeTip,
CodeReviewCommit toMerge) throws MergeException { CodeReviewCommit toMerge) throws IntegrationException {
return args.mergeUtil.canFastForward(args.mergeSorter, mergeTip, args.rw, return args.mergeUtil.canFastForward(args.mergeSorter, mergeTip, args.rw,
toMerge); toMerge);
} }

View File

@@ -15,7 +15,7 @@
package com.google.gerrit.server.git.strategy; package com.google.gerrit.server.git.strategy;
import com.google.gerrit.server.git.CodeReviewCommit; import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.git.MergeException; import com.google.gerrit.server.git.IntegrationException;
import com.google.gerrit.server.git.MergeTip; import com.google.gerrit.server.git.MergeTip;
import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.PersonIdent;
@@ -30,7 +30,7 @@ public class MergeAlways extends SubmitStrategy {
@Override @Override
protected MergeTip _run(CodeReviewCommit branchTip, protected MergeTip _run(CodeReviewCommit branchTip,
Collection<CodeReviewCommit> toMerge) throws MergeException { Collection<CodeReviewCommit> toMerge) throws IntegrationException {
List<CodeReviewCommit> sorted = args.mergeUtil.reduceToMinimalMerge(args.mergeSorter, toMerge); List<CodeReviewCommit> sorted = args.mergeUtil.reduceToMinimalMerge(args.mergeSorter, toMerge);
MergeTip mergeTip; MergeTip mergeTip;
if (branchTip == null) { if (branchTip == null) {
@@ -62,7 +62,7 @@ public class MergeAlways extends SubmitStrategy {
@Override @Override
public boolean dryRun(CodeReviewCommit mergeTip, CodeReviewCommit toMerge) public boolean dryRun(CodeReviewCommit mergeTip, CodeReviewCommit toMerge)
throws MergeException { throws IntegrationException {
return args.mergeUtil.canMerge(args.mergeSorter, args.repo, mergeTip, return args.mergeUtil.canMerge(args.mergeSorter, args.repo, mergeTip,
toMerge); toMerge);
} }

View File

@@ -15,7 +15,7 @@
package com.google.gerrit.server.git.strategy; package com.google.gerrit.server.git.strategy;
import com.google.gerrit.server.git.CodeReviewCommit; import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.git.MergeException; import com.google.gerrit.server.git.IntegrationException;
import com.google.gerrit.server.git.MergeTip; import com.google.gerrit.server.git.MergeTip;
import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.PersonIdent;
@@ -30,7 +30,7 @@ public class MergeIfNecessary extends SubmitStrategy {
@Override @Override
protected MergeTip _run(CodeReviewCommit branchTip, protected MergeTip _run(CodeReviewCommit branchTip,
Collection<CodeReviewCommit> toMerge) throws MergeException { Collection<CodeReviewCommit> toMerge) throws IntegrationException {
List<CodeReviewCommit> sorted = List<CodeReviewCommit> sorted =
args.mergeUtil.reduceToMinimalMerge(args.mergeSorter, toMerge); args.mergeUtil.reduceToMinimalMerge(args.mergeSorter, toMerge);
MergeTip mergeTip; MergeTip mergeTip;
@@ -67,7 +67,7 @@ public class MergeIfNecessary extends SubmitStrategy {
@Override @Override
public boolean dryRun(CodeReviewCommit mergeTip, CodeReviewCommit toMerge) public boolean dryRun(CodeReviewCommit mergeTip, CodeReviewCommit toMerge)
throws MergeException { throws IntegrationException {
return args.mergeUtil.canFastForward( return args.mergeUtil.canFastForward(
args.mergeSorter, mergeTip, args.rw, toMerge) args.mergeSorter, mergeTip, args.rw, toMerge)
|| args.mergeUtil.canMerge( || args.mergeUtil.canMerge(

View File

@@ -25,7 +25,7 @@ import com.google.gerrit.server.change.RebaseChangeOp;
import com.google.gerrit.server.git.BatchUpdate; import com.google.gerrit.server.git.BatchUpdate;
import com.google.gerrit.server.git.CodeReviewCommit; import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.git.CommitMergeStatus; import com.google.gerrit.server.git.CommitMergeStatus;
import com.google.gerrit.server.git.MergeException; import com.google.gerrit.server.git.IntegrationException;
import com.google.gerrit.server.git.MergeTip; import com.google.gerrit.server.git.MergeTip;
import com.google.gerrit.server.git.RebaseSorter; import com.google.gerrit.server.git.RebaseSorter;
import com.google.gerrit.server.git.UpdateException; import com.google.gerrit.server.git.UpdateException;
@@ -60,7 +60,7 @@ public class RebaseIfNecessary extends SubmitStrategy {
@Override @Override
protected MergeTip _run(final CodeReviewCommit branchTip, protected MergeTip _run(final CodeReviewCommit branchTip,
final Collection<CodeReviewCommit> toMerge) throws MergeException { final Collection<CodeReviewCommit> toMerge) throws IntegrationException {
MergeTip mergeTip = new MergeTip(branchTip, toMerge); MergeTip mergeTip = new MergeTip(branchTip, toMerge);
List<CodeReviewCommit> sorted = sort(toMerge); List<CodeReviewCommit> sorted = sort(toMerge);
while (!sorted.isEmpty()) { while (!sorted.isEmpty()) {
@@ -113,11 +113,11 @@ public class RebaseIfNecessary extends SubmitStrategy {
setRefLogIdent(); setRefLogIdent();
} catch (MergeConflictException e) { } catch (MergeConflictException e) {
n.setStatusCode(CommitMergeStatus.REBASE_MERGE_CONFLICT); n.setStatusCode(CommitMergeStatus.REBASE_MERGE_CONFLICT);
throw new MergeException( throw new IntegrationException(
"Cannot rebase " + n.name() + ": " + e.getMessage(), e); "Cannot rebase " + n.name() + ": " + e.getMessage(), e);
} catch (NoSuchChangeException | OrmException | IOException } catch (NoSuchChangeException | OrmException | IOException
| RestApiException | UpdateException e) { | RestApiException | UpdateException e) {
throw new MergeException("Cannot rebase " + n.name(), e); throw new IntegrationException("Cannot rebase " + n.name(), e);
} }
} }
@@ -142,7 +142,7 @@ public class RebaseIfNecessary extends SubmitStrategy {
mergeTip.getCurrentTip(), args.alreadyAccepted); mergeTip.getCurrentTip(), args.alreadyAccepted);
setRefLogIdent(); setRefLogIdent();
} catch (IOException e) { } catch (IOException e) {
throw new MergeException("Cannot merge " + n.name(), e); throw new IntegrationException("Cannot merge " + n.name(), e);
} }
} }
@@ -153,14 +153,14 @@ public class RebaseIfNecessary extends SubmitStrategy {
} }
private List<CodeReviewCommit> sort(Collection<CodeReviewCommit> toSort) private List<CodeReviewCommit> sort(Collection<CodeReviewCommit> toSort)
throws MergeException { throws IntegrationException {
try { try {
List<CodeReviewCommit> result = new RebaseSorter( List<CodeReviewCommit> result = new RebaseSorter(
args.rw, args.alreadyAccepted, args.canMergeFlag).sort(toSort); args.rw, args.alreadyAccepted, args.canMergeFlag).sort(toSort);
Collections.sort(result, CodeReviewCommit.ORDER); Collections.sort(result, CodeReviewCommit.ORDER);
return result; return result;
} catch (IOException e) { } catch (IOException e) {
throw new MergeException("Commit sorting failed", e); throw new IntegrationException("Commit sorting failed", e);
} }
} }
@@ -187,7 +187,7 @@ public class RebaseIfNecessary extends SubmitStrategy {
@Override @Override
public boolean dryRun(CodeReviewCommit mergeTip, CodeReviewCommit toMerge) public boolean dryRun(CodeReviewCommit mergeTip, CodeReviewCommit toMerge)
throws MergeException { throws IntegrationException {
return !args.mergeUtil.hasMissingDependencies(args.mergeSorter, toMerge) return !args.mergeUtil.hasMissingDependencies(args.mergeSorter, toMerge)
&& args.mergeUtil.canCherryPick(args.mergeSorter, args.repo, mergeTip, && args.mergeUtil.canCherryPick(args.mergeSorter, args.repo, mergeTip,
args.rw, toMerge); args.rw, toMerge);

View File

@@ -25,7 +25,7 @@ import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.git.BatchUpdate; import com.google.gerrit.server.git.BatchUpdate;
import com.google.gerrit.server.git.CodeReviewCommit; import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk; import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk;
import com.google.gerrit.server.git.MergeException; import com.google.gerrit.server.git.IntegrationException;
import com.google.gerrit.server.git.MergeSorter; import com.google.gerrit.server.git.MergeSorter;
import com.google.gerrit.server.git.MergeTip; import com.google.gerrit.server.git.MergeTip;
import com.google.gerrit.server.git.MergeUtil; import com.google.gerrit.server.git.MergeUtil;
@@ -124,10 +124,10 @@ public abstract class SubmitStrategy {
* this submit strategy. Implementations are responsible for ordering * this submit strategy. Implementations are responsible for ordering
* of commits, and should not modify the input in place. * of commits, and should not modify the input in place.
* @return the new merge tip. * @return the new merge tip.
* @throws MergeException * @throws IntegrationException
*/ */
public final MergeTip run(final CodeReviewCommit currentTip, public final MergeTip run(final CodeReviewCommit currentTip,
final Collection<CodeReviewCommit> toMerge) throws MergeException { final Collection<CodeReviewCommit> toMerge) throws IntegrationException {
refLogIdent = null; refLogIdent = null;
checkState(args.caller != null); checkState(args.caller != null);
return _run(currentTip, toMerge); return _run(currentTip, toMerge);
@@ -135,7 +135,7 @@ public abstract class SubmitStrategy {
/** @see #run(CodeReviewCommit, Collection) */ /** @see #run(CodeReviewCommit, Collection) */
protected abstract MergeTip _run(CodeReviewCommit currentTip, protected abstract MergeTip _run(CodeReviewCommit currentTip,
Collection<CodeReviewCommit> toMerge) throws MergeException; Collection<CodeReviewCommit> toMerge) throws IntegrationException;
/** /**
* Checks whether the given commit can be merged. * Checks whether the given commit can be merged.
@@ -147,10 +147,10 @@ public abstract class SubmitStrategy {
* @param toMerge the commit that should be checked. * @param toMerge the commit that should be checked.
* @return {@code true} if the given commit can be merged, otherwise * @return {@code true} if the given commit can be merged, otherwise
* {@code false} * {@code false}
* @throws MergeException * @throws IntegrationException
*/ */
public abstract boolean dryRun(CodeReviewCommit mergeTip, public abstract boolean dryRun(CodeReviewCommit mergeTip,
CodeReviewCommit toMerge) throws MergeException; CodeReviewCommit toMerge) throws IntegrationException;
/** /**
* Returns the identity that should be used for reflog entries when updating * Returns the identity that should be used for reflog entries when updating

View File

@@ -23,7 +23,7 @@ import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.change.RebaseChangeOp; import com.google.gerrit.server.change.RebaseChangeOp;
import com.google.gerrit.server.git.BatchUpdate; import com.google.gerrit.server.git.BatchUpdate;
import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk; import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk;
import com.google.gerrit.server.git.MergeException; import com.google.gerrit.server.git.IntegrationException;
import com.google.gerrit.server.git.MergeUtil; import com.google.gerrit.server.git.MergeUtil;
import com.google.gerrit.server.index.ChangeIndexer; import com.google.gerrit.server.index.ChangeIndexer;
import com.google.gerrit.server.patch.PatchSetInfoFactory; import com.google.gerrit.server.patch.PatchSetInfoFactory;
@@ -90,7 +90,7 @@ public class SubmitStrategyFactory {
Repository repo, CodeReviewRevWalk rw, ObjectInserter inserter, Repository repo, CodeReviewRevWalk rw, ObjectInserter inserter,
RevFlag canMergeFlag, Set<RevCommit> alreadyAccepted, RevFlag canMergeFlag, Set<RevCommit> alreadyAccepted,
Branch.NameKey destBranch, IdentifiedUser caller) Branch.NameKey destBranch, IdentifiedUser caller)
throws MergeException, NoSuchProjectException { throws IntegrationException, NoSuchProjectException {
ProjectState project = getProject(destBranch); ProjectState project = getProject(destBranch);
SubmitStrategy.Arguments args = new SubmitStrategy.Arguments( SubmitStrategy.Arguments args = new SubmitStrategy.Arguments(
identifiedUserFactory, myIdent, db, batchUpdateFactory, identifiedUserFactory, myIdent, db, batchUpdateFactory,
@@ -111,7 +111,7 @@ public class SubmitStrategyFactory {
default: default:
final String errorMsg = "No submit strategy for: " + submitType; final String errorMsg = "No submit strategy for: " + submitType;
log.error(errorMsg); log.error(errorMsg);
throw new MergeException(errorMsg); throw new IntegrationException(errorMsg);
} }
} }

View File

@@ -22,7 +22,7 @@ import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.git.CodeReviewCommit; import com.google.gerrit.server.git.CodeReviewCommit;
import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk; import com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk;
import com.google.gerrit.server.git.MergeException; import com.google.gerrit.server.git.IntegrationException;
import com.google.gerrit.server.git.strategy.SubmitStrategy; import com.google.gerrit.server.git.strategy.SubmitStrategy;
import com.google.gerrit.server.project.NoSuchProjectException; import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.ProjectCache; import com.google.gerrit.server.project.ProjectCache;
@@ -129,7 +129,8 @@ class ConflictsPredicate extends OrPredicate<ChangeData> {
conflicts = !strategy.dryRun(commit, otherCommit); conflicts = !strategy.dryRun(commit, otherCommit);
args.conflictsCache.put(conflictsKey, conflicts); args.conflictsCache.put(conflictsKey, conflicts);
return conflicts; return conflicts;
} catch (MergeException | NoSuchProjectException | IOException e) { } catch (IntegrationException | NoSuchProjectException
| IOException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }
} }
@@ -148,7 +149,7 @@ class ConflictsPredicate extends OrPredicate<ChangeData> {
} }
private Set<RevCommit> getAlreadyAccepted(Repository repo, RevWalk rw, private Set<RevCommit> getAlreadyAccepted(Repository repo, RevWalk rw,
CodeReviewCommit tip) throws MergeException { CodeReviewCommit tip) throws IntegrationException {
Set<RevCommit> alreadyAccepted = Sets.newHashSet(); Set<RevCommit> alreadyAccepted = Sets.newHashSet();
if (tip != null) { if (tip != null) {
@@ -164,7 +165,7 @@ class ConflictsPredicate extends OrPredicate<ChangeData> {
} }
} }
} catch (IOException e) { } catch (IOException e) {
throw new MergeException( throw new IntegrationException(
"Failed to determine already accepted commits.", e); "Failed to determine already accepted commits.", e);
} }