MergeOp: Check commit status separately after merge strategies

The updateChangeStatus method was a little weird, basically following
disjoint codepaths depending on the value of the boolean dryRun
argument. The first time through, which happened immediately after
running the submit strategies, might throw exceptions for missing
dependencies or other invalid statuses. The second time through, after
executing ref updates, was actually responsible for setting the status
on the change objects in the database. (It could theoretically throw
in the same cases as the first time it was called, but those should
have already thrown already so it's essentially dead code.)

Split the first set of checks into a new method,
checkMergeStrategyResults, that has an explicit name for what it does,
and uses the same problem/failFast structure as we've started adopting
elsewhere.

Change-Id: I3ea6e5a47d3173749773c0cf7fa175c8048b1a0a
This commit is contained in:
Dave Borowitz
2015-12-22 14:28:43 -05:00
parent 9c259f32a7
commit 479e700631
7 changed files with 124 additions and 67 deletions

View File

@@ -179,6 +179,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -270,6 +271,9 @@ public class ReceiveCommits {
public RestApiException apply(Exception input) {
if (input instanceof RestApiException) {
return (RestApiException) input;
} else if ((input instanceof ExecutionException)
&& (input.getCause() instanceof RestApiException)) {
return (RestApiException) input.getCause();
}
return new RestApiException("Error inserting change/patchset", input);
}
@@ -844,6 +848,9 @@ public class ReceiveCommits {
f.checkedGet();
}
magicBranch.cmd.setResult(OK);
} catch (ResourceConflictException e) {
addMessage(e.getMessage());
reject(magicBranch.cmd, "conflict");
} catch (RestApiException err) {
log.error("Can't insert change/patchset for " + project.getName()
+ ". " + err.getMessage(), err);