git-p4: commit time should be most recent p4 change time

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>

Pete Wyckoff committed Jul 31, 2011 at 09:45 UTC 4e2e6ce45047fe2713546127f3d1ded576e1bf7e
2 files changed +33 -1
contrib/fast-import/git-p4
+14 -1
@@ -1649,7 +1649,8 @@ class P4Sync(Command, P4UserMap):
1649 def importHeadRevision(self, revision):
1650 print "Doing initial import of %s from revision %s into %s" % (' '.join(self.depotPaths), revision, self.branch)
1651
1652 - details = { "user" : "git perforce import user", "time" : int(time.time()) }
1652 + details = {}
1653 + details["user"] = "git perforce import user"
1654 details["desc"] = ("Initial import of %s from the state at revision %s\n"
1655 % (' '.join(self.depotPaths), revision))
1656 details["change"] = revision
@@ -1689,6 +1690,18 @@ class P4Sync(Command, P4UserMap):
1690 fileCnt = fileCnt + 1
1691
1692 details["change"] = newestRevision
1693 +
1694 + # Use time from top-most change so that all git-p4 clones of
1695 + # the same p4 repo have the same commit SHA1s.
1696 + res = p4CmdList("describe -s %d" % newestRevision)
1697 + newestTime = None
1698 + for r in res:
1699 + if r.has_key('time'):
1700 + newestTime = int(r['time'])
1701 + if newestTime is None:
1702 + die("\"describe -s\" on newest change %d did not give a time")
1703 + details["time"] = newestTime
1704 +
1705 self.updateOptionDict(details)
1706 try:
1707 self.commit(details, self.extractFilesFromCommit(details), self.branch, self.depotPaths)
t/t9800-git-p4.sh
+19
@@ -249,6 +249,25 @@ test_expect_success 'not preserving user with mixed authorship' '
249 p4_check_commit_author usernamefile3 alice
250 '
251
252 +marshal_dump() {
253 + what=$1
254 + python -c 'import marshal, sys; d = marshal.load(sys.stdin); print d["'$what'"]'
255 +}
256 +
257 +# Sleep a bit so that the top-most p4 change did not happen "now". Then
258 +# import the repo and make sure that the initial import has the same time
259 +# as the top-most change.
260 +test_expect_success 'initial import time from top change time' '
261 + p4change=$(p4 -G changes -m 1 //depot/... | marshal_dump change) &&
262 + p4time=$(p4 -G changes -m 1 //depot/... | marshal_dump time) &&
263 + sleep 3 &&
264 + "$GITP4" clone --dest="$git" //depot &&
265 + test_when_finished cleanup_git &&
266 + cd "$git" &&
267 + gittime=$(git show -s --raw --pretty=format:%at HEAD) &&
268 + echo $p4time $gittime &&
269 + test $p4time = $gittime
270 +'
271
272 test_expect_success 'shutdown' '
273 pid=`pgrep -f p4d` &&