From fc43b7e9eb895bcef00c7a79820c1c2fca8f8ad9 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Wed, 15 Oct 2014 06:09:01 +0000 Subject: [PATCH] Use current time for cherry picked commits Cherry picking with the submitter time could cause massive clock skew in the Git commit graph if the server is shutdown before the submit can finish, and restarted hours later. In such a case Gerrit will write out new cherry picks using hour-old committer times. This can confuse a Git revision walker if there are many such badly dated commits, more than the "slop bucket" the revision walker can tolerate (5-10). Updating the commit time on each attempt also allows this strategy to work around bugs elsewhere in Gerrit that does not handle patch sets with the same commit SHA-1 well. Each new retry will get a new SHA-1, as the timestamp is updated. Change-Id: Ia0be365054cdc4692a8f5aa2afc2fb87f2e7888a --- .../com/google/gerrit/server/git/strategy/CherryPick.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/strategy/CherryPick.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/strategy/CherryPick.java index 6913f77138..d34d1e330d 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/strategy/CherryPick.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/strategy/CherryPick.java @@ -142,15 +142,16 @@ public class CherryPick extends SubmitStrategy { final PatchSetApproval submitAudit = args.mergeUtil.getSubmitter(n); IdentifiedUser cherryPickUser; + PersonIdent serverNow = args.serverIdent.get(); PersonIdent cherryPickCommitterIdent; if (submitAudit != null) { cherryPickUser = args.identifiedUserFactory.create(submitAudit.getAccountId()); cherryPickCommitterIdent = cherryPickUser.newCommitterIdent( - submitAudit.getGranted(), args.serverIdent.get().getTimeZone()); + serverNow.getWhen(), serverNow.getTimeZone()); } else { cherryPickUser = args.identifiedUserFactory.create(n.change().getOwner()); - cherryPickCommitterIdent = args.serverIdent.get(); + cherryPickCommitterIdent = serverNow; } final String cherryPickCmtMsg = args.mergeUtil.createCherryPickCommitMessage(n); @@ -234,4 +235,4 @@ public class CherryPick extends SubmitStrategy { return args.mergeUtil.canCherryPick(args.mergeSorter, args.repo, mergeTip, args.rw, toMerge); } -} +} \ No newline at end of file