1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-30 05:47:53 +01:00

Started working on incremental imports from Perforce.

Try to find the last imported p4 change number from the git tags and try to pass the right parent for commits to git fast-import.

Signed-off-by: Simon Hausmann <hausmann@kde.org>
This commit is contained in:
Simon Hausmann 2007-02-01 00:08:51 +01:00
parent 79799d52b2
commit 61b3cf7c47

View file

@ -26,6 +26,8 @@
print ""
sys.exit(1)
master = "refs/heads/p4"
branch = "refs/heads/p4-import"
prefix = sys.argv[1]
changeRange = ""
try:
@ -70,6 +72,25 @@ def getUserMap():
return users
users = getUserMap()
topMerge = ""
incremental = 0
# try incremental import
if len(changeRange) == 0:
try:
sout, sin, serr = popen2.popen3("git-name-rev --tags `git-rev-parse %s`" % master)
output = sout.read()
tagIdx = output.index(" tags/p4/")
caretIdx = output.index("^")
revision = int(output[tagIdx + 9 : caretIdx]) + 1
changeRange = "@%s,#head" % revision
topMerge = os.popen("git-rev-parse %s" % master).read()[:-1]
incremental = 1
except:
pass
if incremental == 0:
branch = master
output = os.popen("p4 changes %s...%s" % (prefix, changeRange)).readlines()
@ -80,6 +101,10 @@ def getUserMap():
changes.reverse()
if len(changes) == 0:
print "no changes to import!"
sys.exit(1)
sys.stderr.write("\n")
tz = - time.timezone / 36
@ -97,7 +122,7 @@ def getUserMap():
epoch = description["time"]
author = description["user"]
gitStream.write("commit refs/heads/master\n")
gitStream.write("commit %s\n" % branch)
committer = ""
if author in users:
committer = "%s %s %s" % (users[author], epoch, tz)
@ -111,6 +136,10 @@ def getUserMap():
gitStream.write("\n[ imported from %s; change %s ]\n" % (prefix, change))
gitStream.write("EOT\n\n")
if len(topMerge) > 0:
gitStream.write("merge %s\n" % topMerge)
topMerge = ""
fnum = 0
while description.has_key("depotFile%s" % fnum):
path = description["depotFile%s" % fnum]
@ -143,7 +172,7 @@ def getUserMap():
gitStream.write("\n")
gitStream.write("tag p4/%s\n" % change)
gitStream.write("from refs/heads/master\n");
gitStream.write("from %s\n" % branch);
gitStream.write("tagger %s\n" % committer);
gitStream.write("data 0\n\n")
@ -152,4 +181,8 @@ def getUserMap():
gitOutput.close()
gitError.close()
if incremental == 1:
os.popen("git rebase p4-import p4")
os.popen("git branch -d p4-import")
print ""