diff options
3 files changed, 34 insertions, 5 deletions
diff --git a/java/com/google/gerrit/server/approval/RecursiveApprovalCopier.java b/java/com/google/gerrit/server/approval/RecursiveApprovalCopier.java index 87df46523e..0926dafd52 100644 --- a/java/com/google/gerrit/server/approval/RecursiveApprovalCopier.java +++ b/java/com/google/gerrit/server/approval/RecursiveApprovalCopier.java @@ -101,7 +101,7 @@ public class RecursiveApprovalCopier { @Override public boolean updateChange(ChangeContext ctx) throws IOException { Change change = ctx.getChange(); - ChangeUpdate update = ctx.getUpdate(change.currentPatchSetId()); + ChangeUpdate update = ctx.getUpdate(change.currentPatchSetId(), change.getLastUpdatedOn()); approvalsUtil.persistCopiedApprovals( ctx.getNotes(), ctx.getNotes().getCurrentPatchSet(), diff --git a/java/com/google/gerrit/server/update/BatchUpdate.java b/java/com/google/gerrit/server/update/BatchUpdate.java index 917e96721a..232aa98f5c 100644 --- a/java/com/google/gerrit/server/update/BatchUpdate.java +++ b/java/com/google/gerrit/server/update/BatchUpdate.java @@ -311,9 +311,14 @@ public class BatchUpdate implements AutoCloseable { @Override public ChangeUpdate getUpdate(PatchSet.Id psId) { + return getUpdate(psId, when); + } + + @Override + public ChangeUpdate getUpdate(PatchSet.Id psId, Timestamp whenOverride) { ChangeUpdate u = defaultUpdates.get(psId); if (u == null) { - u = getNewChangeUpdate(psId); + u = getNewChangeUpdate(psId, whenOverride); defaultUpdates.put(psId, u); } return u; @@ -321,13 +326,18 @@ public class BatchUpdate implements AutoCloseable { @Override public ChangeUpdate getDistinctUpdate(PatchSet.Id psId) { - ChangeUpdate u = getNewChangeUpdate(psId); + return getDistinctUpdate(psId, when); + } + + @Override + public ChangeUpdate getDistinctUpdate(PatchSet.Id psId, Timestamp whenOverride) { + ChangeUpdate u = getNewChangeUpdate(psId, whenOverride); distinctUpdates.put(psId, u); return u; } - private ChangeUpdate getNewChangeUpdate(PatchSet.Id psId) { - ChangeUpdate u = changeUpdateFactory.create(notes, user, when); + private ChangeUpdate getNewChangeUpdate(PatchSet.Id psId, Timestamp whenOverride) { + ChangeUpdate u = changeUpdateFactory.create(notes, user, whenOverride); if (newChanges.containsKey(notes.getChangeId())) { u.setAllowWriteToNewRef(true); } diff --git a/java/com/google/gerrit/server/update/ChangeContext.java b/java/com/google/gerrit/server/update/ChangeContext.java index aeabde4328..feba5414ce 100644 --- a/java/com/google/gerrit/server/update/ChangeContext.java +++ b/java/com/google/gerrit/server/update/ChangeContext.java @@ -20,6 +20,7 @@ import com.google.gerrit.entities.Change; import com.google.gerrit.entities.PatchSet; import com.google.gerrit.server.notedb.ChangeNotes; import com.google.gerrit.server.notedb.ChangeUpdate; +import java.sql.Timestamp; /** * Context for performing the {@link BatchUpdateOp#updateChange} phase. @@ -43,6 +44,15 @@ public interface ChangeContext extends Context { ChangeUpdate getUpdate(PatchSet.Id psId); /** + * Same as {@link ChangeContext#getUpdate}, but allows to override the commit timestamp. + * + * @param psId patch set ID. + * @param whenOverride commit timestamp. + * @return handle for change updates. + */ + ChangeUpdate getUpdate(PatchSet.Id psId, Timestamp whenOverride); + + /** * Gets a new ChangeUpdate for this change at a given patch set. * * <p>To get the current patch set ID, use {@link com.google.gerrit.server.PatchSetUtil#current}. @@ -53,6 +63,15 @@ public interface ChangeContext extends Context { ChangeUpdate getDistinctUpdate(PatchSet.Id psId); /** + * Same as {@link ChangeContext#getDistinctUpdate}, but allows to override the commit timestamp. + * + * @param psId patch set ID. + * @param whenOverride commit timestamp. + * @return handle for change updates. + */ + ChangeUpdate getDistinctUpdate(PatchSet.Id psId, Timestamp whenOverride); + + /** * Get the up-to-date notes for this change. * * <p>The change data is read within the same transaction that {@link |