diff options
Diffstat (limited to 'gerrit-server/src/main/java/com/google/gerrit/server/change/Submit.java')
-rw-r--r-- | gerrit-server/src/main/java/com/google/gerrit/server/change/Submit.java | 53 |
1 files changed, 21 insertions, 32 deletions
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/Submit.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/Submit.java index 03bc7f1c72..41151ae8da 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/Submit.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/Submit.java @@ -169,7 +169,7 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>, this.titlePattern = new ParameterizedString(MoreObjects.firstNonNull( cfg.getString("change", null, "submitTooltip"), DEFAULT_TOOLTIP)); - submitWholeTopic = wholeTopicEnabled(cfg); + submitWholeTopic = cfg.getBoolean("change", null, "submitWholeTopic" , false); this.submitTopicLabel = MoreObjects.firstNonNull( Strings.emptyToNull(cfg.getString("change", null, "submitTopicLabel")), "Submit whole topic"); @@ -206,19 +206,17 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>, rsrc.getPatchSet().getRevision().get())); } - List<Change> submittedChanges = submit(rsrc, caller, false); + change = submit(rsrc, caller, false); + if (change == null) { + throw new ResourceConflictException("change is " + + status(dbProvider.get().changes().get(rsrc.getChange().getId()))); + } if (input.waitForMerge) { - for (Change c : submittedChanges) { - // TODO(sbeller): We should make schedule return a Future, then we - // could do these all in parallel and still block until they're done. - mergeQueue.merge(c.getDest()); - } + mergeQueue.merge(change.getDest()); change = dbProvider.get().changes().get(change.getId()); } else { - for (Change c : submittedChanges) { - mergeQueue.schedule(c.getDest()); - } + mergeQueue.schedule(change.getDest()); } if (change == null) { @@ -347,10 +345,9 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>, .orNull(); } - private Change submitToDatabase(final ReviewDb db, final Change.Id changeId, - final Timestamp timestamp) throws OrmException, - ResourceConflictException { - Change ret = db.changes().atomicUpdate(changeId, + private Change submitToDatabase(ReviewDb db, Change.Id changeId, + final Timestamp timestamp) throws OrmException { + return db.changes().atomicUpdate(changeId, new AtomicUpdate<Change>() { @Override public Change update(Change change) { @@ -362,12 +359,6 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>, return null; } }); - if (ret != null) { - return ret; - } else { - throw new ResourceConflictException("change " + changeId + " is " - + status(db.changes().get(changeId))); - } } private Change submitThisChange(RevisionResource rsrc, IdentifiedUser caller, @@ -389,6 +380,9 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>, // Write update commit after all normalized label commits. batch.write(update, new CommitBuilder()); change = submitToDatabase(db, change.getId(), timestamp); + if (change == null) { + return null; + } db.commit(); } finally { db.rollback(); @@ -397,7 +391,7 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>, return change; } - private List<Change> submitWholeTopic(RevisionResource rsrc, IdentifiedUser caller, + private Change submitWholeTopic(RevisionResource rsrc, IdentifiedUser caller, boolean force, String topic) throws ResourceConflictException, OrmException, IOException { Preconditions.checkNotNull(topic); @@ -426,31 +420,30 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>, batch.write(update, new CommitBuilder()); for (ChangeData c : changesByTopic) { - submitToDatabase(db, c.getId(), timestamp); + if (submitToDatabase(db, c.getId(), timestamp) == null) { + return null; + } } db.commit(); } finally { db.rollback(); } List<Change.Id> ids = new ArrayList<>(changesByTopic.size()); - List<Change> ret = new ArrayList<>(changesByTopic.size()); for (ChangeData c : changesByTopic) { ids.add(c.getId()); - ret.add(c.change()); } indexer.indexAsync(ids).checkedGet(); - - return ret; + return change; } - public List<Change> submit(RevisionResource rsrc, IdentifiedUser caller, + public Change submit(RevisionResource rsrc, IdentifiedUser caller, boolean force) throws ResourceConflictException, OrmException, IOException { String topic = rsrc.getChange().getTopic(); if (submitWholeTopic && !Strings.isNullOrEmpty(topic)) { return submitWholeTopic(rsrc, caller, force, topic); } else { - return Arrays.asList(submitThisChange(rsrc, caller, force)); + return submitThisChange(rsrc, caller, force); } } @@ -661,10 +654,6 @@ public class Submit implements RestModifyView<RevisionResource, SubmitInput>, return new RevisionResource(changes.parse(target), rsrc.getPatchSet()); } - static boolean wholeTopicEnabled(Config config) { - return config.getBoolean("change", null, "submitWholeTopic" , false); - } - public static class CurrentRevision implements RestModifyView<ChangeResource, SubmitInput> { private final Provider<ReviewDb> dbProvider; |