PushOneCommit: Use simple counter for Change-Id

Using a simple counter makes it clearer that the generated Change-Ids
are guaranteed to be unique.

Change-Id: I0154bb05ea1969a2684b247ce1661d65591526ad
diff --git a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/PushOneCommit.java b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/PushOneCommit.java
index d764914..6ca8384 100644
--- a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/PushOneCommit.java
+++ b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/PushOneCommit.java
@@ -37,6 +37,7 @@
 import com.google.inject.assistedinject.AssistedInject;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
 import org.eclipse.jgit.api.TagCommand;
 import org.eclipse.jgit.junit.TestRepository;
 import org.eclipse.jgit.lib.PersonIdent;
@@ -122,6 +123,18 @@
     }
   }
 
+  private static AtomicInteger CHANGE_ID_COUNTER = new AtomicInteger();
+
+  private static String nextChangeId() {
+    // Tests use a variety of mechanisms for setting temporary timestamps, so we can't guarantee
+    // that the PersonIdent (or any other field used by the Change-Id generator) for any two test
+    // methods in the same acceptance test class are going to be different. But tests generally
+    // assume that Change-Ids are unique unless otherwise specified. So, don't even bother trying to
+    // reuse JGit's Change-Id generator, just do the simplest possible thing and convert a counter
+    // to hex.
+    return String.format("%040x", CHANGE_ID_COUNTER.incrementAndGet());
+  }
+
   private final ChangeNotes.Factory notesFactory;
   private final ApprovalsUtil approvalsUtil;
   private final Provider<InternalChangeQuery> queryProvider;
@@ -267,7 +280,7 @@
     if (changeId != null) {
       commitBuilder = testRepo.amendRef("HEAD").insertChangeId(changeId.substring(1));
     } else {
-      commitBuilder = testRepo.branch("HEAD").commit().insertChangeId();
+      commitBuilder = testRepo.branch("HEAD").commit().insertChangeId(nextChangeId());
     }
     commitBuilder.message(subject).author(i).committer(new PersonIdent(i, testRepo.getDate()));
   }