Mention remotes/p4/master also in the documentation.
[gitweb.git] / contrib / fast-import / git-p4
index 36fe69a79540029a83f4e31a5b980523e49b96d1..6c199296d39869aae435e95590b776c6ded705a1 100755 (executable)
@@ -718,6 +718,11 @@ class P4Sync(Command):
                 text += filedata[j]['data']
                 j += 1
 
+
+            if not stat.has_key('depotFile'):
+                sys.stderr.write("p4 print fails with: %s\n" % repr(stat))
+                continue
+
             contents[stat['depotFile']] = text
 
         for f in files:
@@ -760,12 +765,11 @@ class P4Sync(Command):
 
         self.gitStream.write("data <<EOT\n")
         self.gitStream.write(details["desc"])
-        self.gitStream.write("\n[git-p4: depot-paths = \"%s\": change = %s: "
-                             "options = %s]\n"
-                             % (','.join (branchPrefixes), details["change"],
-                                details['options']
-                                ))
-        self.gitStream.write("EOT\n\n")
+        self.gitStream.write("\n[git-p4: depot-paths = \"%s\": change = %s"
+                             % (','.join (branchPrefixes), details["change"]))
+        if len(details['options']) > 0:
+            self.gitStream.write(": options = %s" % details['options'])
+        self.gitStream.write("]\nEOT\n\n")
 
         if len(parent) > 0:
             if self.verbose:
@@ -904,7 +908,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"):
@@ -943,9 +952,9 @@ class P4Sync(Command):
             if not line.startswith('p4/') or line == "p4/HEAD":
                 continue
             branch = line
-            if self.importIntoRemotes:
-                # strip off p4
-                branch = re.sub ("^p4/", "", line)
+
+            # strip off p4
+            branch = re.sub ("^p4/", "", line)
 
             self.p4BranchesInGit.append(branch)
             self.initialParents[self.refPrefix + branch] = parseRevision(line)
@@ -955,14 +964,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\n"):
+            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')
@@ -1015,7 +1026,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/"
@@ -1162,7 +1175,7 @@ class P4Sync(Command):
         self.gitError = importProcess.stderr
 
         if self.revision:
-            print "Doing initial import of %s from revision %s" % (' '.join(self.depotPaths), self.revision)
+            print "Doing initial import of %s from revision %s into %s" % (' '.join(self.depotPaths), self.revision, self.branch)
 
             details = { "user" : "git perforce import user", "time" : int(time.time()) }
             details["desc"] = ("Initial import of %s from the state at revision %s"
@@ -1239,6 +1252,9 @@ class P4Sync(Command):
                     print "No changes to import!"
                 return True
 
+            if not self.silent and not self.detectBranches:
+                print "Import destination: %s" % self.branch
+
             self.updatedBranches = set()
 
             cnt = 1
@@ -1300,7 +1316,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,
@@ -1387,7 +1403,8 @@ class P4Clone(P4Sync):
             self.cloneDestination = self.defaultDestination(args)
 
         print "Importing from %s into %s" % (', '.join(depotPaths), self.cloneDestination)
-        os.makedirs(self.cloneDestination)
+        if not os.path.exists(self.cloneDestination):
+            os.makedirs(self.cloneDestination)
         os.chdir(self.cloneDestination)
         system("git init")
         self.gitdir = os.getcwd() + "/.git"