Avoid calling fstat for every imported file (slow!) and instead read the file data first into the python process and use the length of the bytes read for the size field of git fast-import.
Signed-off-by: Simon Hausmann <hausmann@kde.org>
Simon Hausmann committed
Jan 31, 2007 at 22:38 UTC
2385536282d809e923af3895624d8c66b01ec433
1 file changed
+4
-6
contrib/fast-import/p4-fast-export.py
+4
-6
@@ -57,9 +57,6 @@ def p4Cmd(cmd):
57
result.update(entry)
58
return result;
59
60
-def p4FileSize(path):
61
- return int(p4Cmd("fstat -Ol \"%s\"" % path)["fileSize"])
62
-
60
def getUserMap():
61
users = {}
62
@@ -121,14 +118,15 @@ for change in changes:
118
if action == "delete":
119
gitStream.write("D %s\n" % relPath)
120
else:
124
- fileSize = p4FileSize(depotPath)
121
mode = 644
122
if description["type%s" % fnum].startswith("x"):
123
mode = 755
124
125
+ data = os.popen("p4 print -q \"%s\"" % depotPath, "rb").read()
126
+
127
gitStream.write("M %s inline %s\n" % (mode, relPath))
130
- gitStream.write("data %s\n" % fileSize)
131
- gitStream.write(os.popen("p4 print -q \"%s\"" % depotPath).read())
128
+ gitStream.write("data %s\n" % len(data))
129
+ gitStream.write(data)
130
gitStream.write("\n")
131
132
fnum = fnum + 1