Fix multi-branch import with --silent.
[gitweb.git] / contrib / fast-import / git-p4
index 152c3c1ca56a0376a765312c87f6f9cfd1259c3f..d8b7080b4bdb403ae48489bbaeeb0d3a03abab57 100755 (executable)
@@ -31,7 +31,11 @@ def p4CmdList(cmd):
             result.append(entry)
     except EOFError:
         pass
-    pipe.close()
+    exitCode = pipe.close()
+    if exitCode != None:
+        entry = {}
+        entry["p4ExitCode"] = exitCode
+        result.append(entry)
 
     return result
 
@@ -136,18 +140,31 @@ class P4RollBack(Command):
     def __init__(self):
         Command.__init__(self)
         self.options = [
-            optparse.make_option("--verbose", dest="verbose", action="store_true")
+            optparse.make_option("--verbose", dest="verbose", action="store_true"),
+            optparse.make_option("--local", dest="rollbackLocalBranches", action="store_true")
         ]
         self.description = "A tool to debug the multi-branch import. Don't use :)"
         self.verbose = False
+        self.rollbackLocalBranches = False
 
     def run(self, args):
         if len(args) != 1:
             return False
         maxChange = int(args[0])
-        for line in mypopen("git rev-parse --symbolic --remotes").readlines():
-            if line.startswith("p4/") and line != "p4/HEAD\n":
-                ref = "refs/remotes/" + line[:-1]
+
+        if "p4ExitCode" in p4Cmd("changes -m 1"):
+            die("Problems executing p4");
+
+        if self.rollbackLocalBranches:
+            refPrefix = "refs/heads/"
+            lines = mypopen("git rev-parse --symbolic --branches").readlines()
+        else:
+            refPrefix = "refs/remotes/"
+            lines = mypopen("git rev-parse --symbolic --remotes").readlines()
+
+        for line in lines:
+            if self.rollbackLocalBranches or (line.startswith("p4/") and line != "p4/HEAD\n"):
+                ref = refPrefix + line[:-1]
                 log = extractLogMessageFromGitCommit(ref)
                 depotPath, change = extractDepotPathAndChangeFromGitLog(log)
                 changed = False
@@ -814,8 +831,9 @@ class P4Sync(Command):
 
         # this needs to be called after the conversion from heads/p4 to remotes/p4/master
         self.listExistingP4GitBranches()
-        if len(self.p4BranchesInGit) > 1 and not self.silent:
-            print "Importing from/into multiple branches"
+        if len(self.p4BranchesInGit) > 1:
+            if not self.silent:
+               print "Importing from/into multiple branches"
             self.detectBranches = True
 
         if len(args) == 0:
@@ -1067,7 +1085,7 @@ class P4Sync(Command):
         self.gitError.close()
 
         if createP4HeadRef:
-            system("git symbolic-ref %s/HEAD %s" % (self.refPrefix, self.branch))
+            system("git symbolic-ref %sHEAD %s" % (self.refPrefix, self.branch))
 
         return True