git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCHv2 4/4] git-p4: commit time should be most recent p4 change time

From
PWPete Wyckoff <pw@padd.com>
Date
Jul 31, 2011, 13:45 UTC
Message-ID
<20110731134555.GF6564@arf.padd.com>
In-Reply-To
<20110731134416.GB6564@arf.padd.com>

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>
---
 contrib/fast-import/git-p4 |   15 ++++++++++++++-
 t/t9800-git-p4.sh          |   19 +++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletions(-)
diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 98d2aee..6b9de9e 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -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)
diff --git a/t/t9800-git-p4.sh b/t/t9800-git-p4.sh
index b304707..97ec975 100755
--- a/t/t9800-git-p4.sh
+++ b/t/t9800-git-p4.sh
@@ -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` &&
-- 
1.7.5.4
Previous: Pete Wyckoff
Message 17 of 17 in “git-p4 test cleanup, commit time change”
  1. 0/4 git-p4 test cleanup, commit time changePete Wyckoff, Jul 31, 2011
  2. 1/4 git-p4: use test_when_finished in testsPete Wyckoff, Jul 31, 2011
  3. Luke DiamandJul 31, 2011
  4. 2/4 git-p4: make tests work on p4d eval serverPete Wyckoff, Jul 31, 2011
  5. 3/4 git-p4: one test missing config git-p4.skipSubmitEditCheckPete Wyckoff, Jul 31, 2011
  6. Luke DiamandJul 31, 2011
  7. 4/4 git-p4: commit time should be most recent p4 change timePete Wyckoff, Jul 31, 2011
  8. Luke DiamandJul 31, 2011
  9. Luke DiamandJul 31, 2011
  10. Pete WyckoffJul 31, 2011
  11. Luke DiamandJul 31, 2011
  12. 0/4 git-p4 test cleanup, commit time changePete Wyckoff, Jul 31, 2011
  13. 1/4 git-p4: use test_when_finished in testsPete Wyckoff, Jul 31, 2011
  14. 2/4 git-p4: add missing && in testPete Wyckoff, Jul 31, 2011
  15. Luke DiamandJul 31, 2011
  16. 3/4 git-p4: one test missing config git-p4.skipSubmitEditCheckPete Wyckoff, Jul 31, 2011
  17. 4/4 git-p4: commit time should be most recent p4 change timePete Wyckoff, Jul 31, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.