Remove method getNumberOfPatchSets() from Change. Removed the only use of the method. Fixed RebaseChange to pass in the db object. Some other minor cleanups are included too. This is part of the code cleanup to remove the nbrPatchSets field. Change-Id: Iaa7431ea9c96e19c008d8ec25d774e0f7240ba35
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 cbd1157..9ffdb3c 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 @@ 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 afbfd8d3..032d486 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 @@ } /** - * Moves the PatchSetApprovals to the last PatchSet on the change while - * keeping the vetos. - * - * @param change Change to update - * @throws OrmException - * @return List<PatchSetApproval> The previous approvals - */ - public List<PatchSetApproval> 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<PatchSetApproval> The previous approvals */ - public List<PatchSetApproval> copyVetosToLatestPatchSet(ReviewDb db, - Change change) throws OrmException { + public List<PatchSetApproval> 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<PatchSetApproval> patchSetApprovals = db.patchSetApprovals().byChange(change.getId()).toList(); + List<PatchSetApproval> 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 bdd799b..504fe14 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 @@ * @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 @@ "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 952ecde..1e677ac 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.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 @@ List<AdvertiseRefsHook> advHooks = new ArrayList<AdvertiseRefsHook>(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 @@ } @Override - public void advertiseRefs(UploadPack uploadPack) - throws ServiceMayNotContinueException { + public void advertiseRefs(UploadPack uploadPack) { } }); advHooks.add(rp.getAdvertiseRefsHook()); @@ -1723,7 +1720,7 @@ } List<PatchSetApproval> patchSetApprovals = - approvalsUtil.copyVetosToLatestPatchSet(db, change); + approvalsUtil.copyVetosToPatchSet(db, newPatchSet.getId()); final Set<Account.Id> haveApprovals = new HashSet<Account.Id>(); oldReviewers.clear();