use of com.google.gerrit.server.git.MergeOp in project gerrit by GerritCodeReview.
the class PreviewSubmit method getBundles.
private BinaryResult getBundles(BatchUpdate.Factory updateFactory, RevisionResource rsrc, ArchiveFormat f) throws OrmException, RestApiException {
ReviewDb db = dbProvider.get();
ChangeControl control = rsrc.getControl();
IdentifiedUser caller = control.getUser().asIdentifiedUser();
Change change = rsrc.getChange();
// Returned BinaryResult takes ownership and handles closing.
@SuppressWarnings("resource") MergeOp op = mergeOpFactory.create(updateFactory);
try {
op.merge(db, change, caller, false, new SubmitInput(), true);
BinaryResult bin = new SubmitPreviewResult(op, f, maxBundleSize);
bin.disableGzip().setContentType(f.getMimeType()).setAttachmentName("submit-preview-" + change.getChangeId() + "." + format);
return bin;
} catch (OrmException | RestApiException | RuntimeException e) {
op.close();
throw e;
}
}
use of com.google.gerrit.server.git.MergeOp in project gerrit by GerritCodeReview.
the class Submit method mergeChange.
public Change mergeChange(BatchUpdate.Factory updateFactory, RevisionResource rsrc, IdentifiedUser submitter, SubmitInput input) throws OrmException, RestApiException, IOException {
Change change = rsrc.getChange();
if (!change.getStatus().isOpen()) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} else if (!ProjectUtil.branchExists(repoManager, change.getDest())) {
throw new ResourceConflictException(String.format("destination branch \"%s\" not found.", change.getDest().get()));
} else if (!rsrc.getPatchSet().getId().equals(change.currentPatchSetId())) {
// TODO Allow submitting non-current revision by changing the current.
throw new ResourceConflictException(String.format("revision %s is not current revision", rsrc.getPatchSet().getRevision().get()));
}
try (MergeOp op = mergeOpFactory.create(updateFactory)) {
ReviewDb db = dbProvider.get();
op.merge(db, change, submitter, true, input, false);
try {
change = changeNotesFactory.createChecked(db, change.getProject(), change.getId()).getChange();
} catch (NoSuchChangeException e) {
throw new ResourceConflictException("change is deleted");
}
}
switch(change.getStatus()) {
case MERGED:
return change;
case NEW:
ChangeMessage msg = getConflictMessage(rsrc);
if (msg != null) {
throw new ResourceConflictException(msg.getMessage());
}
//$FALL-THROUGH$
case ABANDONED:
case DRAFT:
default:
throw new ResourceConflictException("change is " + ChangeUtil.status(change));
}
}
Aggregations