Merge "Minor refactors prompted by abandon changes in ChangeUtil."
This commit is contained in:
@@ -81,7 +81,7 @@ class SubmitAction extends Handler<ChangeDetail> {
|
||||
CanSubmitResult err =
|
||||
changeControl.canSubmit(patchSetId, db, approvalTypes, functionState);
|
||||
if (err == CanSubmitResult.OK) {
|
||||
ChangeUtil.submit(opFactory, patchSetId, user, db, merger);
|
||||
ChangeUtil.submit(patchSetId, user, db, opFactory, merger);
|
||||
return changeDetailFactory.create(changeId).call();
|
||||
} else {
|
||||
throw new IllegalStateException(err.getMessage());
|
||||
|
||||
@@ -145,14 +145,17 @@ public class ChangeUtil {
|
||||
db.trackingIds().delete(toDelete);
|
||||
}
|
||||
|
||||
public static void submit(MergeOp.Factory opFactory, PatchSet.Id patchSetId,
|
||||
IdentifiedUser user, ReviewDb db, MergeQueue merger) throws OrmException {
|
||||
public static void submit(final PatchSet.Id patchSetId,
|
||||
final IdentifiedUser user, final ReviewDb db,
|
||||
final MergeOp.Factory opFactory, final MergeQueue merger)
|
||||
throws OrmException {
|
||||
final Change.Id changeId = patchSetId.getParentKey();
|
||||
final PatchSetApproval approval = createSubmitApproval(patchSetId, user, db);
|
||||
|
||||
db.patchSetApprovals().upsert(Collections.singleton(approval));
|
||||
|
||||
final Change change = db.changes().atomicUpdate(changeId, new AtomicUpdate<Change>() {
|
||||
final Change updatedChange = db.changes().atomicUpdate(changeId,
|
||||
new AtomicUpdate<Change>() {
|
||||
@Override
|
||||
public Change update(Change change) {
|
||||
if (change.getStatus() == Change.Status.NEW) {
|
||||
@@ -163,13 +166,14 @@ public class ChangeUtil {
|
||||
}
|
||||
});
|
||||
|
||||
if (change.getStatus() == Change.Status.SUBMITTED) {
|
||||
merger.merge(opFactory, change.getDest());
|
||||
if (updatedChange.getStatus() == Change.Status.SUBMITTED) {
|
||||
merger.merge(opFactory, updatedChange.getDest());
|
||||
}
|
||||
}
|
||||
|
||||
public static PatchSetApproval createSubmitApproval(PatchSet.Id patchSetId, IdentifiedUser user, ReviewDb db)
|
||||
throws OrmException {
|
||||
public static PatchSetApproval createSubmitApproval(
|
||||
final PatchSet.Id patchSetId, final IdentifiedUser user, final ReviewDb db
|
||||
) throws OrmException {
|
||||
final List<PatchSetApproval> allApprovals =
|
||||
new ArrayList<PatchSetApproval>(db.patchSetApprovals().byPatchSet(
|
||||
patchSetId).toList());
|
||||
@@ -209,7 +213,7 @@ public class ChangeUtil {
|
||||
}
|
||||
cmsg.setMessage(msgBuf.toString());
|
||||
|
||||
final Change change = db.changes().atomicUpdate(changeId,
|
||||
final Change updatedChange = db.changes().atomicUpdate(changeId,
|
||||
new AtomicUpdate<Change>() {
|
||||
@Override
|
||||
public Change update(Change change) {
|
||||
@@ -224,24 +228,24 @@ public class ChangeUtil {
|
||||
}
|
||||
});
|
||||
|
||||
if (change != null) {
|
||||
if (updatedChange != null) {
|
||||
db.changeMessages().insert(Collections.singleton(cmsg));
|
||||
|
||||
final List<PatchSetApproval> approvals =
|
||||
db.patchSetApprovals().byChange(changeId).toList();
|
||||
for (PatchSetApproval a : approvals) {
|
||||
a.cache(change);
|
||||
a.cache(updatedChange);
|
||||
}
|
||||
db.patchSetApprovals().update(approvals);
|
||||
|
||||
// Email the reviewers
|
||||
final AbandonedSender cm = abandonedSenderFactory.create(change);
|
||||
final AbandonedSender cm = abandonedSenderFactory.create(updatedChange);
|
||||
cm.setFrom(user.getAccountId());
|
||||
cm.setChangeMessage(cmsg);
|
||||
cm.send();
|
||||
}
|
||||
|
||||
hooks.doChangeAbandonedHook(change, user.getAccount(), message);
|
||||
hooks.doChangeAbandonedHook(updatedChange, user.getAccount(), message);
|
||||
}
|
||||
|
||||
public static void restore(final PatchSet.Id patchSetId,
|
||||
@@ -266,7 +270,8 @@ public class ChangeUtil {
|
||||
}
|
||||
cmsg.setMessage(msgBuf.toString());
|
||||
|
||||
Change change = db.changes().atomicUpdate(changeId, new AtomicUpdate<Change>() {
|
||||
final Change updatedChange = db.changes().atomicUpdate(changeId,
|
||||
new AtomicUpdate<Change>() {
|
||||
@Override
|
||||
public Change update(Change change) {
|
||||
if (change.getStatus() == Change.Status.ABANDONED
|
||||
@@ -280,24 +285,24 @@ public class ChangeUtil {
|
||||
}
|
||||
});
|
||||
|
||||
if (change != null) {
|
||||
if (updatedChange != null) {
|
||||
db.changeMessages().insert(Collections.singleton(cmsg));
|
||||
|
||||
final List<PatchSetApproval> approvals =
|
||||
db.patchSetApprovals().byChange(changeId).toList();
|
||||
for (PatchSetApproval a : approvals) {
|
||||
a.cache(change);
|
||||
a.cache(updatedChange);
|
||||
}
|
||||
db.patchSetApprovals().update(approvals);
|
||||
|
||||
// Email the reviewers
|
||||
final AbandonedSender cm = abandonedSenderFactory.create(change);
|
||||
final AbandonedSender cm = abandonedSenderFactory.create(updatedChange);
|
||||
cm.setFrom(user.getAccountId());
|
||||
cm.setChangeMessage(cmsg);
|
||||
cm.send();
|
||||
}
|
||||
|
||||
hooks.doChangeRestoreHook(change, user.getAccount(), message);
|
||||
hooks.doChangeRestoreHook(updatedChange, user.getAccount(), message);
|
||||
}
|
||||
|
||||
public static String sortKey(long lastUpdated, int id){
|
||||
|
||||
@@ -174,7 +174,7 @@ public class ReviewCommand extends BaseCommand {
|
||||
final Set<Branch.NameKey> toMerge = new HashSet<Branch.NameKey>();
|
||||
try {
|
||||
for (PatchSet.Id patchSetId : toSubmit) {
|
||||
ChangeUtil.submit(opFactory, patchSetId, currentUser, db,
|
||||
ChangeUtil.submit(patchSetId, currentUser, db, opFactory,
|
||||
new MergeQueue() {
|
||||
@Override
|
||||
public void merge(MergeOp.Factory mof, Branch.NameKey branch) {
|
||||
|
||||
Reference in New Issue
Block a user