Use refs/heads/* instead of refs/heads/p4/* for local imports
[gitweb.git] / contrib / fast-import / git-p4
index 969c1fe45bba7aebe71084c68a62af7e7515a6cd..152c3c1ca56a0376a765312c87f6f9cfd1259c3f 100755 (executable)
@@ -499,7 +499,8 @@ class P4Sync(Command):
                 optparse.make_option("--detect-labels", dest="detectLabels", action="store_true"),
                 optparse.make_option("--with-origin", dest="syncWithOrigin", action="store_true"),
                 optparse.make_option("--verbose", dest="verbose", action="store_true"),
-                optparse.make_option("--import-local", dest="importIntoRemotes", action="store_false")
+                optparse.make_option("--import-local", dest="importIntoRemotes", action="store_false"),
+                optparse.make_option("--max-changes", dest="maxChanges")
         ]
         self.description = """Imports from Perforce into a git repository.\n
     example:
@@ -521,6 +522,7 @@ class P4Sync(Command):
         self.syncWithOrigin = False
         self.verbose = False
         self.importIntoRemotes = True
+        self.maxChanges = ""
 
     def p4File(self, depotPath):
         return os.popen("p4 print -q \"%s\"" % depotPath, "rb").read()
@@ -758,10 +760,15 @@ class P4Sync(Command):
             cmdline += " --branches"
 
         for line in mypopen(cmdline).readlines():
-            if line.startswith("p4/") and line != "p4/HEAD\n":
+            if self.importIntoRemotes and ((not line.startswith("p4/")) or line == "p4/HEAD\n"):
+                continue
+            if self.importIntoRemotes:
+                # strip off p4
                 branch = line[3:-1]
-                self.p4BranchesInGit.append(branch)
-                self.initialParents[self.refPrefix + branch] = parseRevision(line[:-1])
+            else:
+                branch = line[:-1]
+            self.p4BranchesInGit.append(branch)
+            self.initialParents[self.refPrefix + branch] = parseRevision(line[:-1])
 
     def run(self, args):
         self.depotPath = ""
@@ -775,11 +782,11 @@ class P4Sync(Command):
         if self.importIntoRemotes:
             self.refPrefix = "refs/remotes/p4/"
         else:
-            self.refPrefix = "refs/heads/p4/"
+            self.refPrefix = "refs/heads/"
 
         createP4HeadRef = False;
 
-        if self.syncWithOrigin and gitBranchExists("origin") and gitBranchExists(self.refPrefix + "master") and not self.detectBranches:
+        if self.syncWithOrigin and gitBranchExists("origin") and gitBranchExists(self.refPrefix + "master") and not self.detectBranches and self.importIntoRemotes:
             ### needs to be ported to multi branch import
 
             print "Syncing with origin first as requested by calling git fetch origin"
@@ -971,6 +978,9 @@ class P4Sync(Command):
 
                 changes.reverse()
 
+                if len(self.maxChanges) > 0:
+                    changes = changes[0:min(int(self.maxChanges), len(changes))]
+
             if len(changes) == 0:
                 if not self.silent:
                     print "No changes to import!"