use of com.google.gerrit.server.update.BatchUpdate in project gerrit by GerritCodeReview.
the class Rebase method applyImpl.
@Override
protected ChangeInfo applyImpl(BatchUpdate.Factory updateFactory, RevisionResource rsrc, RebaseInput input) throws EmailException, OrmException, UpdateException, RestApiException, IOException, NoSuchChangeException, PermissionBackendException {
rsrc.permissions().database(dbProvider).check(ChangePermission.REBASE);
ChangeControl control = rsrc.getControl();
Change change = rsrc.getChange();
try (Repository repo = repoManager.openRepository(change.getProject());
ObjectInserter oi = repo.newObjectInserter();
ObjectReader reader = oi.newReader();
RevWalk rw = new RevWalk(reader);
BatchUpdate bu = updateFactory.create(dbProvider.get(), change.getProject(), rsrc.getUser(), TimeUtil.nowTs())) {
if (!change.getStatus().isOpen()) {
throw new ResourceConflictException("change is " + ChangeUtil.status(change));
} else if (!hasOneParent(rw, rsrc.getPatchSet())) {
throw new ResourceConflictException("cannot rebase merge commits or commit with no ancestor");
}
bu.setRepository(repo, rw, oi);
bu.addOp(change.getId(), rebaseFactory.create(control, rsrc.getPatchSet(), findBaseRev(repo, rw, rsrc, input)).setForceContentMerge(true).setFireRevisionCreated(true));
bu.execute();
}
return json.create(OPTIONS).format(change.getProject(), change.getId());
}
use of com.google.gerrit.server.update.BatchUpdate in project gerrit by GerritCodeReview.
the class DeleteDraftComment method applyImpl.
@Override
protected Response<CommentInfo> applyImpl(BatchUpdate.Factory updateFactory, DraftCommentResource rsrc, Input input) throws RestApiException, UpdateException {
try (BatchUpdate bu = updateFactory.create(db.get(), rsrc.getChange().getProject(), rsrc.getControl().getUser(), TimeUtil.nowTs())) {
Op op = new Op(rsrc.getComment().key);
bu.addOp(rsrc.getChange().getId(), op);
bu.execute();
}
return Response.none();
}
use of com.google.gerrit.server.update.BatchUpdate in project gerrit by GerritCodeReview.
the class DeleteDraftPatchSet method applyImpl.
@Override
protected Response<?> applyImpl(BatchUpdate.Factory updateFactory, RevisionResource rsrc, Input input) throws RestApiException, UpdateException, OrmException, PermissionBackendException {
if (isDeletingOnlyPatchSet(rsrc)) {
// A change cannot have zero patch sets; the change is deleted instead.
rsrc.permissions().database(db).check(ChangePermission.DELETE);
}
try (BatchUpdate bu = updateFactory.create(db.get(), rsrc.getProject(), rsrc.getUser(), TimeUtil.nowTs())) {
bu.setOrder(Order.DB_BEFORE_REPO);
bu.addOp(rsrc.getChange().getId(), new Op(rsrc.getPatchSet().getId()));
bu.execute();
}
return Response.none();
}
use of com.google.gerrit.server.update.BatchUpdate in project gerrit by GerritCodeReview.
the class DeletePrivate method applyImpl.
@Override
protected Response<String> applyImpl(BatchUpdate.Factory updateFactory, ChangeResource rsrc, SetPrivateOp.Input input) throws RestApiException, UpdateException {
if (!canDeletePrivate(rsrc)) {
throw new AuthException("not allowed to unmark private");
}
if (!rsrc.getChange().isPrivate()) {
throw new ResourceConflictException("change is not private");
}
ChangeControl control = rsrc.getControl();
SetPrivateOp op = new SetPrivateOp(cmUtil, false, input);
try (BatchUpdate u = updateFactory.create(dbProvider.get(), control.getProject().getNameKey(), control.getUser(), TimeUtil.nowTs())) {
u.addOp(control.getId(), op).execute();
}
return Response.none();
}
use of com.google.gerrit.server.update.BatchUpdate in project gerrit by GerritCodeReview.
the class DeleteReviewer method applyImpl.
@Override
protected Response<?> applyImpl(BatchUpdate.Factory updateFactory, ReviewerResource rsrc, DeleteReviewerInput input) throws RestApiException, UpdateException {
if (input == null) {
input = new DeleteReviewerInput();
}
if (input.notify == null) {
input.notify = NotifyHandling.ALL;
}
try (BatchUpdate bu = updateFactory.create(dbProvider.get(), rsrc.getChangeResource().getProject(), rsrc.getChangeResource().getUser(), TimeUtil.nowTs())) {
BatchUpdateOp op;
if (rsrc.isByEmail()) {
op = deleteReviewerByEmailOpFactory.create(rsrc.getReviewerByEmail(), input);
} else {
op = deleteReviewerOpFactory.create(rsrc.getReviewerUser().getAccount(), input);
}
bu.addOp(rsrc.getChange().getId(), op);
bu.execute();
}
return Response.none();
}
Aggregations