{"thread":{"id":"23040","subject":"[PATCH] Improve git-p4 to be able to submit patches back to perforce when the git repository is made up of multiple perforce directories.","startedAt":"2010-03-16T19:23:43Z","lastAt":"2010-03-16T19:23:43Z","messageCount":1,"participants":["Benjamin C Meyer"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"136969","messageId":"1268767423-7431-1-git-send-email-bmeyer@rim.com","threadId":"23040","inReplyTo":null,"subject":"[PATCH] Improve git-p4 to be able to submit patches back to perforce when the git repository is made up of multiple perforce directories.","fromName":"Benjamin C Meyer","fromEmail":"bmeyer@rim.com","sentAt":"2010-03-16T19:23:43Z","receivedAt":"2010-03-16T19:23:43Z","isPatch":true,"sender":{"key":"bmeyer@rim.com","avatar":null},"body":"git-p4 lets you sync several perforce directories into the one git repository,\nbut when you would do a git perforce submit it was hardcoded to apply\nthe patches to whatever was the first directory in the list that\nthe repository was synced from which would usually fail.  When\nmultiple perforce directories are now present git-p4 will apply them\nto the common root directory where the patches can successfully be applied.\n\nFor example if you synced these two directories from perforce in git\n\n//depot/foo/bar,//depot/test\n\ngit-p4 will now lookup that the client paths are:\n\n~/p4/foo/bar,~/p4/test\n\nand then set self.clientPath to the root of all of the client paths\n(~/p4) permitting the patches from git to be cleanly applied for all\nof the directories.\n\nSigned-off-by: Benjamin C Meyer <bmeyer@rim.com>\n---\n contrib/fast-import/git-p4 |   40 +++++++++++++++++++++++++++++-----------\n 1 files changed, 29 insertions(+), 11 deletions(-)\n\ndiff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4\nindex c1ea643..b4b509c 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -766,6 +766,21 @@ class P4Submit(Command):\n                    + \"Please review/edit and then use p4 submit -i < %s to submit directly!\"\n                    % (fileName, fileName))\n \n+    def findCommonPath(self, settings):\n+        dirs = []\n+        for path in settings:\n+            localDir = p4Where(path)\n+            if len(localDir) > 0:\n+                dirs.append(localDir)\n+        localDir = dirs[0];\n+        maxMatch = len(localDir) - 1\n+        for dir in dirs:\n+            if maxMatch > len(dir) - 1:\n+                maxMatch = len(dir) - 1\n+            while dir[maxMatch] != localDir[maxMatch]:\n+                maxMatch = maxMatch - 1;\n+        return localDir[0:maxMatch]\n+\n     def run(self, args):\n         if len(args) == 0:\n             self.master = currentGitBranch()\n@@ -781,23 +796,26 @@ class P4Submit(Command):\n             die(\"%s is not in git-p4.allowSubmit\" % self.master)\n \n         [upstream, settings] = findUpstreamBranchPoint()\n-        self.depotPath = settings['depot-paths'][0]\n+        if (len(settings['depot-paths']) > 0):\n+            self.depotPath = \"\"\n+            self.clientPath = self.findCommonPath(settings['depot-paths'])\n+        else:\n+            self.depotPath = settings['depot-paths'][0]\n+            if len(self.depotPath) == 0:\n+                print \"Internal error: cannot locate perforce depot path from existing branches\"\n+                sys.exit(128)\n+            self.clientPath = p4Where(self.depotPath)\n+\n+        if len(self.clientPath) == 0:\n+            print \"Error: Cannot locate perforce checkout of %s in client view\" % self.depotPath\n+            sys.exit(128)\n+\n         if len(self.origin) == 0:\n             self.origin = upstream\n \n         if self.verbose:\n             print \"Origin branch is \" + self.origin\n \n-        if len(self.depotPath) == 0:\n-            print \"Internal error: cannot locate perforce depot path from existing branches\"\n-            sys.exit(128)\n-\n-        self.clientPath = p4Where(self.depotPath)\n-\n-        if len(self.clientPath) == 0:\n-            print \"Error: Cannot locate perforce checkout of %s in client view\" % self.depotPath\n-            sys.exit(128)\n-\n         print \"Perforce checkout for depot path %s located at %s\" % (self.depotPath, self.clientPath)\n         self.oldWorkingDirectory = os.getcwd()\n \n-- \n1.6.3.3\n"}]}