From 124d6829be8aa49696b42b7c8d88706dfd665621 Mon Sep 17 00:00:00 2001 From: Thomas Draebing Date: Wed, 5 Oct 2022 15:49:31 +0200 Subject: Don't update the last updated timestamp when running copy-approvals The copy-approvals pgm tool is creating new commits in the meta ref branches of changes. The commit timestamp of the latest commit in a meta ref will be taken as the last updated timestamp. This would confuse users, since very old changes could be shown as recently updated. Now the new commit timestamp will be overwritten with the timestamp of the last commit in the meta ref branch, thereby preserving the previous update timestamp. Bug: Issue 15998 Release-Notes: Preserve last updated timestamp during copying approvals Change-Id: Ib56133b39b4b980d84a1b8c6b1786ef0902bd926 --- .../server/approval/RecursiveApprovalCopier.java | 2 +- java/com/google/gerrit/server/update/BatchUpdate.java | 18 ++++++++++++++---- .../google/gerrit/server/update/ChangeContext.java | 19 +++++++++++++++++++ 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. @@ -42,6 +43,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. * @@ -52,6 +62,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. * -- cgit v1.2.3