{"thread":{"id":"10881","subject":"[PATCH] git-p4: Fix direct import from perforce after fetching changes through git from origin","startedAt":"2007-11-15T09:38:45Z","lastAt":"2007-11-15T09:38:45Z","messageCount":1,"participants":["Simon Hausmann"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"59963","messageId":"200711151038.45668.simon@lst.de","threadId":"10881","inReplyTo":null,"subject":"[PATCH] git-p4: Fix direct import from perforce after fetching changes through git from origin","fromName":"Simon Hausmann","fromEmail":"simon@lst.de","sentAt":"2007-11-15T09:38:45Z","receivedAt":"2007-11-15T09:38:45Z","isPatch":true,"sender":{"key":"hausmann@kde.org","avatar":"https://gravatar.com/avatar/bc9aad4fb31dce17eb66e690e7b51fe980c62da3c225c785da35dd806b8da778?d=mp&s=160"},"body":"When using an existing git repository to cache the perforce import we don't fetch the\nbranch mapping from perforce as that is a slow operation. However the origin repository\nmay not be fully up-to-date and therefore it may be necessary to import more changes\ndirectly from Perforce. Such a direct import needs self.knownBranches to be set up though,\nso initialize it from the existing p4/* git branches.\n\nSigned-off-by: Simon Hausmann <simon@lst.de>\n---\n contrib/fast-import/git-p4 |   15 +++++++++++++--\n 1 files changed, 13 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4\nindex c148b5a..c869bb8 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -1207,6 +1207,15 @@ class P4Sync(Command):\n         for branch in lostAndFoundBranches:\n             self.knownBranches[branch] = branch\n \n+    def getBranchMappingFromGitBranches(self):\n+        branches = p4BranchesInGit(self.importIntoRemotes)\n+        for branch in branches.keys():\n+            if branch == \"master\":\n+                branch = \"main\"\n+            else:\n+                branch = branch[len(self.projectName):]\n+            self.knownBranches[branch] = branch\n+\n     def listExistingP4GitBranches(self):\n         # branches holds mapping from name to commit\n         branches = p4BranchesInGit(self.importIntoRemotes)\n@@ -1541,8 +1550,10 @@ class P4Sync(Command):\n             ## FIXME - what's a P4 projectName ?\n             self.projectName = self.guessProjectName()\n \n-            if not self.hasOrigin:\n-                self.getBranchMapping();\n+            if self.hasOrigin:\n+                self.getBranchMappingFromGitBranches()\n+            else:\n+                self.getBranchMapping()\n             if self.verbose:\n                 print \"p4-git branches: %s\" % self.p4BranchesInGit\n                 print \"initial parents: %s\" % self.initialParents\n-- \n1.5.3.5.576.gfe6193\n\n"}]}