From 8da2a12a9cb4ebaf66607543e9a2379706e59d3d Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Mon, 24 Jun 2019 11:02:08 +0200 Subject: Set commit date to cherry-pick time When we stage commits, we expect them to have the commit date of the staging time. Move the timestamp variable down, since it's only used later and this makes things less confusing for future readers I hope. Fixes: QTQAINFRA-2994 Fixes: QTQAINFRA-3019 Change-Id: If22cdda9b05d1d453981ada8459031eea95ea844 Reviewed-by: Jukka Jokiniva Reviewed-by: Kari Oikarinen --- .../gerrit/plugins/qtcodereview/QtCherryPickPatch.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/googlesource/gerrit/plugins/qtcodereview/QtCherryPickPatch.java b/src/main/java/com/googlesource/gerrit/plugins/qtcodereview/QtCherryPickPatch.java index 0169885..061d341 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/qtcodereview/QtCherryPickPatch.java +++ b/src/main/java/com/googlesource/gerrit/plugins/qtcodereview/QtCherryPickPatch.java @@ -39,6 +39,7 @@ import com.google.inject.Singleton; import java.io.IOException; import java.sql.Timestamp; import java.util.Arrays; +import java.util.Date; import java.util.List; import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.lib.ObjectId; @@ -110,8 +111,8 @@ public class QtCherryPickPatch { return commitToCherryPick; } - Timestamp now = TimeUtil.nowTs(); - PersonIdent committerIdent = commitToCherryPick.getCommitterIdent(); + // Copy the committer, but change the date to now. + PersonIdent committerIdent = new PersonIdent(commitToCherryPick.getCommitterIdent(), new Date()); commitToCherryPick.setPatchsetId(changeData.currentPatchSet().getId()); commitToCherryPick.setNotes(changeData.notes()); @@ -136,7 +137,6 @@ public class QtCherryPickPatch { cherryPickCommit = revWalk.parseCommit(commit); } else { String commitMessage = mergeUtil.createCommitMessageOnSubmit(commitToCherryPick, baseCommit); - commitMessage += " "; // This ensures unique SHA1 is generated, otherwise old is reused cherryPickCommit = mergeUtil.createCherryPickFromCommit(oi, git.getConfig(), baseCommit, @@ -154,7 +154,8 @@ public class QtCherryPickPatch { logger.atInfo().log("qtcodereview: new patch %s -> %s", commitToCherryPick, cherryPickCommit); oi.flush(); } - BatchUpdate bu = batchUpdateFactory.create(dbProvider.get(), project, identifiedUser, now); + Timestamp commitTimestamp = new Timestamp(committerIdent.getWhen().getTime()); + BatchUpdate bu = batchUpdateFactory.create(dbProvider.get(), project, identifiedUser, commitTimestamp); bu.setRepository(git, revWalk, oi); if (!patchSetNotChanged && !mergeCommit) { Change.Id changeId = insertPatchSet(bu, git, changeData.notes(), cherryPickCommit); -- cgit v1.2.3