@matheusbsbs / matheus-bagliano / commits / 9466d479e2
Fork 0

Speed up the import of individual files from Perforce into git by passing the output of "p4 print" directly to git fast-import. Also try to set the mode of the file in git correctly based on file type heuristics.

Signed-off-by: Simon Hausmann <hausmann@kde.org>

Simon Hausmann committed Jan 31, 2007 at 20:16 UTC 9466d479e27afe864d42e3d501489b033b8da83f
1 file changed +20 -11
contrib/fast-import/p4-fast-export.py
+20 -11
@@ -5,12 +5,11 @@
5 # Author: Simon Hausmann <hausmann@kde.org>
6 # License: MIT <http://www.opensource.org/licenses/mit-license.php>
7 #
8 -# TODO: - support integrations (at least p4i)
8 +# TODO:
9 +# - support integrations (at least p4i)
10 # - support incremental imports
11 # - create tags
12 # - instead of reading all files into a variable try to pipe from
12 -# - p4 print directly to stdout. need to figure out file size somehow
13 -# though.
13 # - support p4 submit (hah!)
14 # - don't hardcode the import to master
15 #
@@ -92,6 +91,17 @@ def describe(change):
91 def p4cat(path):
92 return os.popen("p4 print -q \"%s\"" % path).read()
93
94 +def p4Stat(path):
95 + output = os.popen("p4 fstat -Ol \"%s\"" % path).readlines()
96 + fileSize = 0
97 + mode = 644
98 + for line in output:
99 + if line.startswith("... headType x"):
100 + mode = 755
101 + elif line.startswith("... fileSize "):
102 + fileSize = long(line[12:])
103 + return mode, fileSize
104 +
105 def stripRevision(path):
106 hashPos = path.rindex("#")
107 return path[:hashPos]
@@ -112,7 +122,6 @@ def getUserMap():
122
123 return users
124
115 -
125 users = getUserMap()
126
127 output = os.popen("p4 changes %s...%s" % (prefix, changeRange)).readlines()
@@ -133,9 +142,6 @@ for change in changes:
142 [ author, log, epoch, changedFiles, removedFiles ] = describe(change)
143 sys.stderr.write("\rimporting revision %s (%s%%)" % (change, cnt * 100 / len(changes)))
144 cnt = cnt + 1
136 -# sys.stderr.write("%s\n" % log)
137 -# sys.stderr.write("%s\n" % changedFiles)
138 -# sys.stderr.write("%s\n" % removedFiles)
145
146 print "commit refs/heads/master"
147 if author in users:
@@ -154,10 +160,13 @@ for change in changes:
160 sys.stderr.write("\nchanged files: ignoring path %s outside of %s in change %s\n" % (f, prefix, change))
161 continue
162 relpath = f[len(prefix):]
157 - print "M 644 inline %s" % stripRevision(relpath)
158 - data = p4cat(f)
159 - print "data %s" % len(data)
160 - sys.stdout.write(data)
163 +
164 + [mode, fileSize] = p4Stat(f)
165 +
166 + print "M %s inline %s" % (mode, stripRevision(relpath))
167 + print "data %s" % fileSize
168 + sys.stdout.flush();
169 + os.system("p4 print -q \"%s\"" % f)
170 print ""
171
172 for f in removedFiles: