git-p4: commit time should be most recent p4 change time
authorPete Wyckoff <pw@padd.com>
Sun, 31 Jul 2011 13:45:55 +0000 (09:45 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 1 Aug 2011 17:24:20 +0000 (10:24 -0700)
When importing a repo, the time on the initial commit had been
just "now". But this causes problems when trying to share among
git-p4 repos that were created identically, although at different
times. Instead, use the time in the top-most p4 change as the
time for the git import commit.

Signed-off-by: Pete Wyckoff <pw@padd.com>
Acked-by: Luke Diamand <luke@diamand.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/fast-import/git-p4
t/t9800-git-p4.sh
index 98d2aee67fc1f6bfdfc960527b6f0bf6acf5122a..6b9de9e7e0e3304d42048ff3680eac9270330ee4 100755 (executable)
@@ -1649,7 +1649,8 @@ class P4Sync(Command, P4UserMap):
     def importHeadRevision(self, revision):
         print "Doing initial import of %s from revision %s into %s" % (' '.join(self.depotPaths), revision, self.branch)
 
-        details = { "user" : "git perforce import user", "time" : int(time.time()) }
+        details = {}
+        details["user"] = "git perforce import user"
         details["desc"] = ("Initial import of %s from the state at revision %s\n"
                            % (' '.join(self.depotPaths), revision))
         details["change"] = revision
@@ -1689,6 +1690,18 @@ class P4Sync(Command, P4UserMap):
             fileCnt = fileCnt + 1
 
         details["change"] = newestRevision
+
+        # Use time from top-most change so that all git-p4 clones of
+        # the same p4 repo have the same commit SHA1s.
+        res = p4CmdList("describe -s %d" % newestRevision)
+        newestTime = None
+        for r in res:
+            if r.has_key('time'):
+                newestTime = int(r['time'])
+        if newestTime is None:
+            die("\"describe -s\" on newest change %d did not give a time")
+        details["time"] = newestTime
+
         self.updateOptionDict(details)
         try:
             self.commit(details, self.extractFilesFromCommit(details), self.branch, self.depotPaths)
index b3047077e9e9d5ea3bd0593c98f6ab24cc33248b..97ec9753b45b4f2786e247e2897b3185b7b66df8 100755 (executable)
@@ -249,6 +249,25 @@ test_expect_success 'not preserving user with mixed authorship' '
        p4_check_commit_author usernamefile3 alice
 '
 
+marshal_dump() {
+       what=$1
+       python -c 'import marshal, sys; d = marshal.load(sys.stdin); print d["'$what'"]'
+}
+
+# Sleep a bit so that the top-most p4 change did not happen "now".  Then
+# import the repo and make sure that the initial import has the same time
+# as the top-most change.
+test_expect_success 'initial import time from top change time' '
+       p4change=$(p4 -G changes -m 1 //depot/... | marshal_dump change) &&
+       p4time=$(p4 -G changes -m 1 //depot/... | marshal_dump time) &&
+       sleep 3 &&
+       "$GITP4" clone --dest="$git" //depot &&
+       test_when_finished cleanup_git &&
+       cd "$git" &&
+       gittime=$(git show -s --raw --pretty=format:%at HEAD) &&
+       echo $p4time $gittime &&
+       test $p4time = $gittime
+'
 
 test_expect_success 'shutdown' '
        pid=`pgrep -f p4d` &&