summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Draebing <thomas.draebing@sap.com>2022-10-05 15:49:31 +0200
committerThomas Dräbing <thomas.draebing@sap.com>2022-10-06 06:12:35 +0000
commit124d6829be8aa49696b42b7c8d88706dfd665621 (patch)
treea1676b5d43fa065fbd37043b726ee326c0f965d4
parente42e1dde802f44151a1938087730e64a6510dd1e (diff)
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
-rw-r--r--java/com/google/gerrit/server/approval/RecursiveApprovalCopier.java2
-rw-r--r--java/com/google/gerrit/server/update/BatchUpdate.java18
-rw-r--r--java/com/google/gerrit/server/update/ChangeContext.java19
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