Executing CherryPick.writeCherryPickCommit() in a transaction.
This would at least allow the partial changes to the database to rollback and not get users in a bad state when e.g. in the case of OrmDuplicateKeyException: patch_set_ancestors'. Bug: issue 2034 Bug: issue 2246 Change-Id: I65e111bedc3cec033299b5b5360aaee733d4b5c6
This commit is contained in:
@@ -162,26 +162,36 @@ public class CherryPick extends SubmitStrategy {
|
|||||||
ps.setCreatedOn(TimeUtil.nowTs());
|
ps.setCreatedOn(TimeUtil.nowTs());
|
||||||
ps.setUploader(submitAudit.getAccountId());
|
ps.setUploader(submitAudit.getAccountId());
|
||||||
ps.setRevision(new RevId(newCommit.getId().getName()));
|
ps.setRevision(new RevId(newCommit.getId().getName()));
|
||||||
insertAncestors(args.db, ps.getId(), newCommit);
|
|
||||||
args.db.patchSets().insert(Collections.singleton(ps));
|
|
||||||
|
|
||||||
n.change.setCurrentPatchSet(patchSetInfoFactory.get(newCommit, ps.getId()));
|
final RefUpdate ru;
|
||||||
args.db.changes().update(Collections.singletonList(n.change));
|
|
||||||
|
|
||||||
final List<PatchSetApproval> approvals = Lists.newArrayList();
|
args.db.changes().beginTransaction(n.change.getId());
|
||||||
for (PatchSetApproval a : args.mergeUtil.getApprovalsForCommit(n)) {
|
try {
|
||||||
approvals.add(new PatchSetApproval(ps.getId(), a));
|
insertAncestors(args.db, ps.getId(), newCommit);
|
||||||
}
|
args.db.patchSets().insert(Collections.singleton(ps));
|
||||||
args.db.patchSetApprovals().insert(approvals);
|
n.change
|
||||||
|
.setCurrentPatchSet(patchSetInfoFactory.get(newCommit, ps.getId()));
|
||||||
|
args.db.changes().update(Collections.singletonList(n.change));
|
||||||
|
|
||||||
final RefUpdate ru = args.repo.updateRef(ps.getRefName());
|
final List<PatchSetApproval> approvals = Lists.newArrayList();
|
||||||
ru.setExpectedOldObjectId(ObjectId.zeroId());
|
for (PatchSetApproval a : args.mergeUtil.getApprovalsForCommit(n)) {
|
||||||
ru.setNewObjectId(newCommit);
|
approvals.add(new PatchSetApproval(ps.getId(), a));
|
||||||
ru.disableRefLog();
|
}
|
||||||
if (ru.update(args.rw) != RefUpdate.Result.NEW) {
|
args.db.patchSetApprovals().insert(approvals);
|
||||||
throw new IOException(String.format("Failed to create ref %s in %s: %s",
|
|
||||||
ps.getRefName(), n.change.getDest().getParentKey().get(),
|
ru = args.repo.updateRef(ps.getRefName());
|
||||||
ru.getResult()));
|
ru.setExpectedOldObjectId(ObjectId.zeroId());
|
||||||
|
ru.setNewObjectId(newCommit);
|
||||||
|
ru.disableRefLog();
|
||||||
|
if (ru.update(args.rw) != RefUpdate.Result.NEW) {
|
||||||
|
throw new IOException(String.format(
|
||||||
|
"Failed to create ref %s in %s: %s", ps.getRefName(), n.change
|
||||||
|
.getDest().getParentKey().get(), ru.getResult()));
|
||||||
|
}
|
||||||
|
|
||||||
|
args.db.commit();
|
||||||
|
} finally {
|
||||||
|
args.db.rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
gitRefUpdated.fire(n.change.getProject(), ru);
|
gitRefUpdated.fire(n.change.getProject(), ru);
|
||||||
|
|||||||
Reference in New Issue
Block a user