Fix support for explicit disabling of syncing with the origin
[gitweb.git] / contrib / fast-import / git-p4
index d03ba0b6ad4c570e33d45538ee9e3ec84d18c4ef..ff56181310988de13f5eef0232c255bdcc4d1910 100755 (executable)
@@ -909,7 +909,12 @@ class P4Sync(Command):
 
     def guessProjectName(self):
         for p in self.depotPaths:
-            return p [p.strip().rfind("/") + 1:]
+            if p.endswith("/"):
+                p = p[:-1]
+            p = p[p.strip().rfind("/") + 1:]
+            if not p.endswith("/"):
+               p += "/"
+            return p
 
     def getBranchMapping(self):
         for info in p4CmdList("branches"):
@@ -960,14 +965,16 @@ class P4Sync(Command):
             print ("Creating/updating branch(es) in %s based on origin branch(es)"
                    % self.refPrefix)
 
+        originPrefix = "origin/p4/"
+
         for line in read_pipe_lines("git rev-parse --symbolic --remotes"):
             line = line.strip()
-            if (not line.startswith("origin/")) or line.endswith("HEAD"):
+            if (not line.startswith(originPrefix)) or line.endswith("HEAD"):
                 continue
 
-            headName = line[len("origin/"):]
+            headName = line[len(originPrefix):]
             remoteHead = self.refPrefix + headName
-            originHead = "origin/" + headName
+            originHead = line
 
             original = extractSettingsGitLog(extractLogMessageFromGitCommit(originHead))
             if (not original.has_key('depot-paths')
@@ -1020,7 +1027,9 @@ class P4Sync(Command):
         # map from branch depot path to parent branch
         self.knownBranches = {}
         self.initialParents = {}
-        self.hasOrigin = gitBranchExists("origin")
+        self.hasOrigin = gitBranchExists("origin") or gitBranchExists("origin/p4") or gitBranchExists("origin/p4/master")
+        if not self.syncWithOrigin:
+            self.hasOrigin = False
 
         if self.importIntoRemotes:
             self.refPrefix = "refs/remotes/p4/"
@@ -1305,7 +1314,7 @@ class P4Sync(Command):
                                 parent = self.initialParents[branch]
                                 del self.initialParents[branch]
 
-                            self.commit(description, filesForCommit, branch, branchPrefix, parent)
+                            self.commit(description, filesForCommit, branch, [branchPrefix], parent)
                     else:
                         files = self.extractFilesFromCommit(description)
                         self.commit(description, files, self.branch, self.depotPaths,