return null;
}
}
final PatchSet ps;
final ChangeMessage msg;
db.changes().beginTransaction(change.getId());
try {
change =
db.changes().atomicUpdate(change.getId(), new AtomicUpdate<Change>() {
@Override
public Change update(Change change) {
if (change.getStatus().isOpen()) {
change.nextPatchSetId();
change.setLastSha1MergeTested(null);
return change;
} else {
return null;
}
}
});
if (change == null) {
reject(request.cmd, "change is closed");
return null;
}
ps = new PatchSet(change.currPatchSetId());
ps.setCreatedOn(new Timestamp(System.currentTimeMillis()));
ps.setUploader(currentUser.getAccountId());
ps.setRevision(toRevId(c));
if (MagicBranch.isDraft(request.cmd.getRefName())) {
ps.setDraft(true);
}
insertAncestors(ps.getId(), c);
db.patchSets().insert(Collections.singleton(ps));
if (request.checkMergedInto) {
final Ref mergedInto = findMergedInto(change.getDest().get(), c);
result.mergedIntoRef = mergedInto != null ? mergedInto.getName() : null;
}
final PatchSetInfo info = patchSetInfoFactory.get(c, ps.getId());
change.setCurrentPatchSet(info);
result.change = change;
result.patchSet = ps;
result.info = info;
List<PatchSetApproval> patchSetApprovals = approvalsUtil.copyVetosToLatestPatchSet(change);
final Set<Account.Id> haveApprovals = new HashSet<Account.Id>();
oldReviewers.clear();
oldCC.clear();
for (PatchSetApproval a : patchSetApprovals) {
haveApprovals.add(a.getAccountId());
if (a.getValue() != 0) {
oldReviewers.add(a.getAccountId());
} else {
oldCC.add(a.getAccountId());
}
}
approvalsUtil.addReviewers(change, ps, info, reviewers, haveApprovals);
msg =
new ChangeMessage(new ChangeMessage.Key(change.getId(), ChangeUtil
.messageUUID(db)), me, ps.getCreatedOn(), ps.getId());
msg.setMessage("Uploaded patch set " + ps.getPatchSetId() + ".");
db.changeMessages().insert(Collections.singleton(msg));
ChangeUtil.updateTrackingIds(db, change, trackingFooters, footerLines);
result.msg = msg;
if (result.mergedIntoRef == null) {