diff --git a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/Change.java b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/Change.java index cbd1157f2e..9ffdb3cc9f 100644 --- a/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/Change.java +++ b/gerrit-reviewdb/src/main/java/com/google/gerrit/reviewdb/client/Change.java @@ -436,10 +436,6 @@ public final class Change { lastUpdatedOn = new Timestamp(System.currentTimeMillis()); } - public int getNumberOfPatchSets() { - return nbrPatchSets; - } - public String getSortKey() { return sortKey; } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/ApprovalsUtil.java b/gerrit-server/src/main/java/com/google/gerrit/server/ApprovalsUtil.java index afbfd8d38a..032d486504 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/ApprovalsUtil.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/ApprovalsUtil.java @@ -68,38 +68,25 @@ public class ApprovalsUtil { } /** - * Moves the PatchSetApprovals to the last PatchSet on the change while - * keeping the vetos. - * - * @param change Change to update - * @throws OrmException - * @return List The previous approvals - */ - public List copyVetosToLatestPatchSet(Change change) - throws OrmException { - return copyVetosToLatestPatchSet(db, change); - } - - /** - * Moves the PatchSetApprovals to the last PatchSet on the change while - * keeping the vetos. + * Moves the PatchSetApprovals to the specified PatchSet on the change from + * the prior PatchSet, while keeping the vetos. * * @param db database connection to use for updates. - * @param change Change to update + * @param dest PatchSet to copy to * @throws OrmException * @return List The previous approvals */ - public List copyVetosToLatestPatchSet(ReviewDb db, - Change change) throws OrmException { + public List copyVetosToPatchSet(ReviewDb db, + PatchSet.Id dest) throws OrmException { PatchSet.Id source; - if (change.getNumberOfPatchSets() > 1) { - source = new PatchSet.Id(change.getId(), change.getNumberOfPatchSets() - 1); + if (dest.get() > 1) { + source = new PatchSet.Id(dest.getParentKey(), dest.get() - 1); } else { throw new OrmException("Previous patch set could not be found"); } - PatchSet.Id dest = change.currPatchSetId(); - List patchSetApprovals = db.patchSetApprovals().byChange(change.getId()).toList(); + List patchSetApprovals = + db.patchSetApprovals().byChange(dest.getParentKey()).toList(); for (PatchSetApproval a : patchSetApprovals) { // ApprovalCategory.SUBMIT is still in db but not relevant in git-store if (!ApprovalCategory.SUBMIT.equals(a.getCategoryId())) { diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/changedetail/RebaseChange.java b/gerrit-server/src/main/java/com/google/gerrit/server/changedetail/RebaseChange.java index bdd799b72a..504fe14b4d 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/changedetail/RebaseChange.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/changedetail/RebaseChange.java @@ -189,7 +189,6 @@ public class RebaseChange { * @param db the ReviewDb * @param destBranch the destination branch * @param git the repository - * @param rw the RevWalk * @param patchSetAncestors the original PatchSetAncestor of the given patch * set that should be based * @param depPatchSetList the original patch set list on which the rebased @@ -393,7 +392,7 @@ public class RebaseChange { "Change %s was modified", change.getId())); } - approvalsUtil.copyVetosToLatestPatchSet(change); + approvalsUtil.copyVetosToPatchSet(db, change.currentPatchSetId()); final ChangeMessage cmsg = new ChangeMessage(new ChangeMessage.Key(change.getId(), diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveCommits.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveCommits.java index 952ecdec1b..1e677ac39d 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveCommits.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveCommits.java @@ -111,7 +111,6 @@ import org.eclipse.jgit.transport.BaseReceivePack; import org.eclipse.jgit.transport.ReceiveCommand; import org.eclipse.jgit.transport.ReceiveCommand.Result; import org.eclipse.jgit.transport.ReceivePack; -import org.eclipse.jgit.transport.ServiceMayNotContinueException; import org.eclipse.jgit.transport.UploadPack; import org.eclipse.jgit.util.SystemReader; import org.slf4j.Logger; @@ -362,8 +361,7 @@ public class ReceiveCommits { List advHooks = new ArrayList(3); advHooks.add(new AdvertiseRefsHook() { @Override - public void advertiseRefs(BaseReceivePack rp) - throws ServiceMayNotContinueException { + public void advertiseRefs(BaseReceivePack rp) { allRefs = rp.getAdvertisedRefs(); if (allRefs == null) { allRefs = rp.getRepository().getAllRefs(); @@ -372,8 +370,7 @@ public class ReceiveCommits { } @Override - public void advertiseRefs(UploadPack uploadPack) - throws ServiceMayNotContinueException { + public void advertiseRefs(UploadPack uploadPack) { } }); advHooks.add(rp.getAdvertiseRefsHook()); @@ -1723,7 +1720,7 @@ public class ReceiveCommits { } List patchSetApprovals = - approvalsUtil.copyVetosToLatestPatchSet(db, change); + approvalsUtil.copyVetosToPatchSet(db, newPatchSet.getId()); final Set haveApprovals = new HashSet(); oldReviewers.clear();