@matheusbsbs / matheus-bagliano / commits / 61b3cf7c47
Fork 0

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>

Simon Hausmann committed Feb 1, 2007 at 00:08 UTC 61b3cf7c471d2f94eefcf6616c1204f32e641542
1 file changed +35 -2
contrib/fast-import/p4-fast-export.py
+35 -2
@@ -26,6 +26,8 @@ if len(sys.argv) != 2:
26 print ""
27 sys.exit(1)
28
29 +master = "refs/heads/p4"
30 +branch = "refs/heads/p4-import"
31 prefix = sys.argv[1]
32 changeRange = ""
33 try:
@@ -70,6 +72,25 @@ def getUserMap():
72 return users
73
74 users = getUserMap()
75 +topMerge = ""
76 +
77 +incremental = 0
78 +# try incremental import
79 +if len(changeRange) == 0:
80 + try:
81 + sout, sin, serr = popen2.popen3("git-name-rev --tags `git-rev-parse %s`" % master)
82 + output = sout.read()
83 + tagIdx = output.index(" tags/p4/")
84 + caretIdx = output.index("^")
85 + revision = int(output[tagIdx + 9 : caretIdx]) + 1
86 + changeRange = "@%s,#head" % revision
87 + topMerge = os.popen("git-rev-parse %s" % master).read()[:-1]
88 + incremental = 1
89 + except:
90 + pass
91 +
92 +if incremental == 0:
93 + branch = master
94
95 output = os.popen("p4 changes %s...%s" % (prefix, changeRange)).readlines()
96
@@ -80,6 +101,10 @@ for line in output:
101
102 changes.reverse()
103
104 +if len(changes) == 0:
105 + print "no changes to import!"
106 + sys.exit(1)
107 +
108 sys.stderr.write("\n")
109
110 tz = - time.timezone / 36
@@ -97,7 +122,7 @@ for change in changes:
122 epoch = description["time"]
123 author = description["user"]
124
100 - gitStream.write("commit refs/heads/master\n")
125 + gitStream.write("commit %s\n" % branch)
126 committer = ""
127 if author in users:
128 committer = "%s %s %s" % (users[author], epoch, tz)
@@ -111,6 +136,10 @@ for change in changes:
136 gitStream.write("\n[ imported from %s; change %s ]\n" % (prefix, change))
137 gitStream.write("EOT\n\n")
138
139 + if len(topMerge) > 0:
140 + gitStream.write("merge %s\n" % topMerge)
141 + topMerge = ""
142 +
143 fnum = 0
144 while description.has_key("depotFile%s" % fnum):
145 path = description["depotFile%s" % fnum]
@@ -143,7 +172,7 @@ for change in changes:
172 gitStream.write("\n")
173
174 gitStream.write("tag p4/%s\n" % change)
146 - gitStream.write("from refs/heads/master\n");
175 + gitStream.write("from %s\n" % branch);
176 gitStream.write("tagger %s\n" % committer);
177 gitStream.write("data 0\n\n")
178
@@ -152,4 +181,8 @@ gitStream.close()
181 gitOutput.close()
182 gitError.close()
183
184 +if incremental == 1:
185 + os.popen("git rebase p4-import p4")
186 + os.popen("git branch -d p4-import")
187 +
188 print ""