Merge "PostReview: update and insert comments/approvals in a single step"

This commit is contained in:
Shawn Pearce
2014-02-08 01:00:38 +00:00
committed by Gerrit Code Review

View File

@@ -309,16 +309,14 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
}
List<PatchLineComment> del = Lists.newArrayList();
List<PatchLineComment> ins = Lists.newArrayList();
List<PatchLineComment> upd = Lists.newArrayList();
List<PatchLineComment> ups = Lists.newArrayList();
for (Map.Entry<String, List<Comment>> ent : in.entrySet()) {
String path = ent.getKey();
for (Comment c : ent.getValue()) {
String parent = Url.decode(c.inReplyTo);
PatchLineComment e = drafts.remove(Url.decode(c.id));
boolean create = e == null;
if (create) {
if (e == null) {
e = new PatchLineComment(
new PatchLineComment.Key(
new Patch.Key(rsrc.getPatchSet().getId(), path),
@@ -340,7 +338,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
c.range.endLine,
c.range.endCharacter));
}
(create ? ins : upd).add(e);
ups.add(e);
}
}
@@ -355,16 +353,14 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
for (PatchLineComment e : drafts.values()) {
e.setStatus(PatchLineComment.Status.PUBLISHED);
e.setWrittenOn(timestamp);
upd.add(e);
ups.add(e);
}
break;
}
db.get().patchComments().delete(del);
db.get().patchComments().insert(ins);
db.get().patchComments().update(upd);
comments.addAll(ins);
comments.addAll(upd);
return !del.isEmpty() || !ins.isEmpty() || !upd.isEmpty();
db.get().patchComments().upsert(ups);
comments.addAll(ups);
return !del.isEmpty() || !ups.isEmpty();
}
private Map<String, PatchLineComment> scanDraftComments(
@@ -385,8 +381,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
}
List<PatchSetApproval> del = Lists.newArrayList();
List<PatchSetApproval> ins = Lists.newArrayList();
List<PatchSetApproval> upd = Lists.newArrayList();
List<PatchSetApproval> ups = Lists.newArrayList();
Map<String, PatchSetApproval> current = scanLabels(rsrc, del);
LabelTypes labelTypes = rsrc.getControl().getLabelTypes();
@@ -412,7 +407,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
} else if (c != null && c.getValue() != ent.getValue()) {
c.setValue(ent.getValue());
c.setGranted(timestamp);
upd.add(c);
ups.add(c);
addLabelDelta(normName, c.getValue());
categories.put(normName, c.getValue());
update.putApproval(ent.getKey(), ent.getValue());
@@ -425,24 +420,23 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
lt.getLabelId()),
ent.getValue(), TimeUtil.nowTs());
c.setGranted(timestamp);
ins.add(c);
ups.add(c);
addLabelDelta(normName, c.getValue());
categories.put(normName, c.getValue());
update.putApproval(ent.getKey(), ent.getValue());
}
}
forceCallerAsReviewer(rsrc, current, ins, upd, del);
forceCallerAsReviewer(rsrc, current, ups, del);
db.get().patchSetApprovals().delete(del);
db.get().patchSetApprovals().insert(ins);
db.get().patchSetApprovals().update(upd);
return !del.isEmpty() || !ins.isEmpty() || !upd.isEmpty();
db.get().patchSetApprovals().upsert(ups);
return !del.isEmpty() || !ups.isEmpty();
}
private void forceCallerAsReviewer(RevisionResource rsrc,
Map<String, PatchSetApproval> current, List<PatchSetApproval> ins,
List<PatchSetApproval> upd, List<PatchSetApproval> del) {
if (current.isEmpty() && ins.isEmpty() && upd.isEmpty()) {
Map<String, PatchSetApproval> current, List<PatchSetApproval> ups,
List<PatchSetApproval> del) {
if (current.isEmpty() && ups.isEmpty()) {
// TODO Find another way to link reviewers to changes.
if (del.isEmpty()) {
// If no existing label is being set to 0, hack in the caller
@@ -454,7 +448,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
.getLabelId()),
(short) 0, TimeUtil.nowTs());
c.setGranted(timestamp);
ins.add(c);
ups.add(c);
} else {
// Pick a random label that is about to be deleted and keep it.
Iterator<PatchSetApproval> i = del.iterator();
@@ -462,7 +456,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
c.setValue((short) 0);
c.setGranted(timestamp);
i.remove();
upd.add(c);
ups.add(c);
}
}
}