From 961904c8fa521db440ed37054cd04896e20b63bc Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 10 Aug 2009 17:21:55 -0700 Subject: [PATCH] Preserve negative approvals when replacing patch sets Prior versions of Gerrit correctly saved a negative approval when a replacement patch set was uploaded. This was a specific feature we added to allow project leads to reject a change until they are satisfied with the replacement, even if other developers on that project were able to review and approve subsequent patch sets. Since approvals are now per-patch set we have to copy the approval records from the prior patch set to this one, if the value is < 0. Signed-off-by: Shawn O. Pearce --- .../gerrit/client/reviewdb/PatchSetApproval.java | 8 ++++++++ .../google/gerrit/server/ssh/commands/Receive.java | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/com/google/gerrit/client/reviewdb/PatchSetApproval.java b/src/main/java/com/google/gerrit/client/reviewdb/PatchSetApproval.java index b99f5916a9..75a4660446 100644 --- a/src/main/java/com/google/gerrit/client/reviewdb/PatchSetApproval.java +++ b/src/main/java/com/google/gerrit/client/reviewdb/PatchSetApproval.java @@ -98,6 +98,14 @@ public final class PatchSetApproval { setGranted(); } + public PatchSetApproval(final PatchSet.Id psId, final PatchSetApproval src) { + key = + new PatchSetApproval.Key(psId, src.getAccountId(), src.getCategoryId()); + changeOpen = true; + value = src.getValue(); + granted = src.granted; + } + public PatchSetApproval.Key getKey() { return key; } diff --git a/src/main/java/com/google/gerrit/server/ssh/commands/Receive.java b/src/main/java/com/google/gerrit/server/ssh/commands/Receive.java index b52117c7ea..a62b49cd49 100644 --- a/src/main/java/com/google/gerrit/server/ssh/commands/Receive.java +++ b/src/main/java/com/google/gerrit/server/ssh/commands/Receive.java @@ -810,6 +810,7 @@ final class Receive extends AbstractGitCommand { change = changeCache.get(changeId); } + final PatchSet.Id priorPatchSet = change.currentPatchSetId(); final HashSet existingRevisions = new HashSet(); for (final PatchSet ps : db.patchSets().byChange(changeId)) { if (ps.getRevision() != null) { @@ -893,6 +894,17 @@ final class Receive extends AbstractGitCommand { oldCC.add(a.getAccountId()); } + if (a.getValue() < 0 + && a.getPatchSetId().equals(priorPatchSet)) { + // If there was a negative vote on the prior patch set, carry it + // into this patch set. + // + db.patchSetApprovals() + .insert( + Collections.singleton(new PatchSetApproval(ps.getId(), a)), + txn); + } + if (!haveAuthor && authorId != null && a.getAccountId().equals(authorId)) { haveAuthor = true;