Skip to content

Commit 4e2e6ce

Browse files
Pete Wyckoffgitster
authored andcommitted
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 <[email protected]> Acked-by: Luke Diamand <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eab3081 commit 4e2e6ce

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

contrib/fast-import/git-p4

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,8 @@ class P4Sync(Command, P4UserMap):
16491649
def importHeadRevision(self, revision):
16501650
print "Doing initial import of %s from revision %s into %s" % (' '.join(self.depotPaths), revision, self.branch)
16511651

1652-
details = { "user" : "git perforce import user", "time" : int(time.time()) }
1652+
details = {}
1653+
details["user"] = "git perforce import user"
16531654
details["desc"] = ("Initial import of %s from the state at revision %s\n"
16541655
% (' '.join(self.depotPaths), revision))
16551656
details["change"] = revision
@@ -1689,6 +1690,18 @@ class P4Sync(Command, P4UserMap):
16891690
fileCnt = fileCnt + 1
16901691

16911692
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+
16921705
self.updateOptionDict(details)
16931706
try:
16941707
self.commit(details, self.extractFilesFromCommit(details), self.branch, self.depotPaths)

t/t9800-git-p4.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,25 @@ test_expect_success 'not preserving user with mixed authorship' '
249249
p4_check_commit_author usernamefile3 alice
250250
'
251251

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+
'
252271

253272
test_expect_success 'shutdown' '
254273
pid=`pgrep -f p4d` &&

0 commit comments

Comments
 (0)