Fix conversion from old style heads/p4 to remotes/p4/master
[gitweb.git] / contrib / fast-import / git-p4
index 92522417cd27f6baefae00b39e349388efaffc38..7489c91081a3234d086dbb88afeac25509106ca6 100755 (executable)
 # TODO: * implement git-p4 rollback <perforce change number> for debugging
 #         to roll back all p4 remote branches to a commit older or equal to
 #         the specified change.
+#       * for git-p4 submit --direct it would be nice to still create a
+#         git commit without updating HEAD before submitting to perforce.
+#         With the commit sha1 printed (or recoded in a .git/foo file?)
+#         it's possible to recover if anything goes wrong instead of potentially
+#         loosing a change entirely because it was never comitted to git and
+#         the p4 submit failed (or resulted in lots of conflicts, etc.)
+#       * Consider making --with-origin the default, assuming that the git
+#         protocol is always more efficient. (needs manual testing first :)
 #
 
 import optparse, sys, os, marshal, popen2, subprocess, shelve
@@ -722,11 +730,6 @@ class P4Sync(Command):
         self.knownBranches = {}
         self.initialParents = {}
 
-        self.listExistingP4GitBranches()
-        if len(self.p4BranchesInGit) > 1:
-            print "Importing from/into multiple branches"
-            self.detectBranches = True
-
         if self.syncWithOrigin and gitBranchExists("origin") and gitBranchExists("refs/remotes/p4/master") and not self.detectBranches:
             ### needs to be ported to multi branch import
 
@@ -752,6 +755,12 @@ class P4Sync(Command):
             if not gitBranchExists("refs/remotes/p4/HEAD"):
                 system("git symbolic-ref refs/remotes/p4/HEAD %s" % self.branch)
 
+        # 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"
+            self.detectBranches = True
+
         if len(args) == 0:
             if not gitBranchExists(self.branch) and gitBranchExists("origin") and not self.detectBranches:
                 ### needs to be ported to multi branch import
@@ -789,7 +798,7 @@ class P4Sync(Command):
                 self.depotPath = self.previousDepotPath
                 self.changeRange = "@%s,#head" % p4Change
                 self.initialParent = parseRevision(self.branch)
-                if not self.silent:
+                if not self.silent and not self.detectBranches:
                     print "Performing incremental import into %s git branch" % self.branch
 
         if not self.branch.startswith("refs/"):
@@ -914,15 +923,17 @@ class P4Sync(Command):
 
             if len(changes) == 0:
                 if not self.silent:
-                    print "no changes to import!"
+                    print "No changes to import!"
                 return True
 
+            self.updatedBranches = set()
+
             cnt = 1
             for change in changes:
                 description = p4Cmd("describe %s" % change)
 
                 if not self.silent:
-                    sys.stdout.write("\rimporting revision %s (%s%%)" % (change, cnt * 100 / len(changes)))
+                    sys.stdout.write("\rImporting revision %s (%s%%)" % (change, cnt * 100 / len(changes)))
                     sys.stdout.flush()
                 cnt = cnt + 1
 
@@ -939,6 +950,8 @@ class P4Sync(Command):
                             if self.verbose:
                                 print "branch is %s" % branch
 
+                            self.updatedBranches.add(branch)
+
                             if branch not in self.createdBranches:
                                 self.createdBranches.add(branch)
                                 parent = self.knownBranches[branch]
@@ -978,8 +991,13 @@ class P4Sync(Command):
                     print self.gitError.read()
                     sys.exit(1)
 
-        if not self.silent:
-            print ""
+            if not self.silent:
+                print ""
+                if len(self.updatedBranches) > 0:
+                    sys.stdout.write("Updated branches: ")
+                    for b in self.updatedBranches:
+                        sys.stdout.write("%s " % b)
+                    sys.stdout.write("\n")
 
 
         self.gitStream.close()