Added a little helper script to debug the output of the p4 python interface.
[gitweb.git] / contrib / fast-import / p4-fast-export.py
index 36381fbecd97d95867ab3e56e966b97404411680..c44292473a82fd349b69176038eafdf8c177f4f6 100755 (executable)
 #       - support p4 submit (hah!)
 #
 import os, string, sys, time
-import marshal, popen2
+import marshal, popen2, getopt
 
 branch = "refs/heads/p4"
 prefix = previousDepotPath = os.popen("git-repo-config --get p4.depotpath").read()
 if len(prefix) != 0:
     prefix = prefix[:-1]
 
-if len(sys.argv) == 1 and len(prefix) != 0:
+try:
+    opts, args = getopt.getopt(sys.argv[1:], "", [ "branch=" ])
+except getopt.GetoptError:
+    print "fixme, syntax error"
+    sys.exit(1)
+
+for o, a in opts:
+    if o == "--branch":
+        branch = "refs/heads/" + a
+
+if len(args) == 0 and len(prefix) != 0:
     print "[using previously specified depot path %s]" % prefix
-elif len(sys.argv) != 2:
+elif len(args) != 1:
     print "usage: %s //depot/path[@revRange]" % sys.argv[0]
     print "\n    example:"
     print "    %s //depot/my/project/ -- to import the current head"
     print ""
     sys.exit(1)
 else:
-    if len(prefix) != 0 and prefix != sys.argv[1]:
-        print "previous import used depot path %s and now %s was specified. this doesn't work!" % (prefix, sys.argv[1])
+    if len(prefix) != 0 and prefix != args[0]:
+        print "previous import used depot path %s and now %s was specified. this doesn't work!" % (prefix, args[0])
         sys.exit(1)
-    prefix = sys.argv[1]
+    prefix = args[0]
 
 changeRange = ""
 revision = ""
@@ -230,7 +240,11 @@ def getUserMap():
         sys.stdout.flush()
         cnt = cnt + 1
 
-        commit(description)
+        try:
+            commit(description)
+        except:
+            print gitError.read()
+            sys.exit(1)
 
     gitStream.close()
     gitOutput.close()
@@ -240,3 +254,4 @@ def getUserMap():
 
 os.popen("git-repo-config p4.depotpath %s" % prefix).read()
 
+sys.exit(0)