@matheusbsbs / matheus-bagliano / commits / 701ce87633
Fork 0

Changed the import mechanism to write to git fast-import through a pipe instead of having p4-fast-export write to stdout and let the caller connect it to git fast-import.

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

Simon Hausmann committed Jan 31, 2007 at 21:54 UTC 701ce876331eca10031c104f42cc6fccc425ac94
1 file changed +27 -25
contrib/fast-import/p4-fast-export.py
+27 -25
@@ -14,16 +14,16 @@
14 # - don't hardcode the import to master
15 #
16 import os, string, sys, time
17 -import marshal
17 +import marshal, popen2
18
19 if len(sys.argv) != 2:
20 - sys.stderr.write("usage: %s //depot/path[@revRange]\n" % sys.argv[0]);
21 - sys.stderr.write("\n example:\n");
22 - sys.stderr.write(" %s //depot/my/project/ -- to import everything\n");
23 - sys.stderr.write(" %s //depot/my/project/@1,6 -- to import only from revision 1 to 6\n");
24 - sys.stderr.write("\n");
25 - sys.stderr.write(" (a ... is not needed in the path p4 specification, it's added implicitly)\n");
26 - sys.stderr.write("\n");
20 + print "usage: %s //depot/path[@revRange]" % sys.argv[0]
21 + print "\n example:"
22 + print " %s //depot/my/project/ -- to import everything"
23 + print " %s //depot/my/project/@1,6 -- to import only from revision 1 to 6"
24 + print ""
25 + print " (a ... is not needed in the path p4 specification, it's added implicitly)"
26 + print ""
27 sys.exit(1)
28
29 prefix = sys.argv[1]
@@ -147,23 +147,23 @@ sys.stderr.write("\n")
147
148 tz = - time.timezone / 36
149
150 +gitOutput, gitStream, gitError = popen2.popen3("git-fast-import")
151 +
152 cnt = 1
153 for change in changes:
154 [ author, log, epoch, changedFiles, removedFiles ] = describe(change)
153 - sys.stderr.write("\rimporting revision %s (%s%%)" % (change, cnt * 100 / len(changes)))
155 + sys.stdout.write("\rimporting revision %s (%s%%)" % (change, cnt * 100 / len(changes)))
156 cnt = cnt + 1
157
156 - print "commit refs/heads/master"
158 + gitStream.write("commit refs/heads/master\n")
159 if author in users:
158 - print "committer %s %s %s" % (users[author], epoch, tz)
160 + gitStream.write("committer %s %s %s\n" % (users[author], epoch, tz))
161 else:
160 - print "committer %s <a@b> %s %s" % (author, epoch, tz)
161 - print "data <<EOT"
162 + gitStream.write("committer %s <a@b> %s %s\n" % (author, epoch, tz))
163 + gitStream.write("data <<EOT\n")
164 for l in log:
163 - print l[:len(l) - 1]
164 - print "EOT"
165 -
166 - print ""
165 + gitStream.write(l)
166 + gitStream.write("EOT\n\n")
167
168 for f in changedFiles:
169 if not f.startswith(prefix):
@@ -173,20 +173,22 @@ for change in changes:
173
174 [mode, fileSize] = p4Stat(f)
175
176 - print "M %s inline %s" % (mode, stripRevision(relpath))
177 - print "data %s" % fileSize
178 - sys.stdout.flush();
179 - os.system("p4 print -q \"%s\"" % f)
180 - print ""
176 + gitStream.write("M %s inline %s\n" % (mode, stripRevision(relpath)))
177 + gitStream.write("data %s\n" % fileSize)
178 + gitStream.write(os.popen("p4 print -q \"%s\"" % f).read())
179 + gitStream.write("\n")
180
181 for f in removedFiles:
182 if not f.startswith(prefix):
183 sys.stderr.write("\ndeleted files: ignoring path %s outside of %s in change %s\n" % (f, prefix, change))
184 continue
185 relpath = f[len(prefix):]
187 - print "D %s" % stripRevision(relpath)
186 + gitStream.write("D %s\n" % stripRevision(relpath))
187
189 - print ""
188 + gitStream.write("\n")
189
191 -sys.stderr.write("\n")
190 +gitStream.close()
191 +gitOutput.close()
192 +gitError.close()
193
194 +print ""