{"thread":{"id":"9435","subject":"[PATCH] git-p4: Fix git-p4 submit to include only changed files in the perforce submit template.","startedAt":"2007-08-08T15:06:55Z","lastAt":"2007-08-08T15:06:55Z","messageCount":1,"participants":["Simon Hausmann"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"50194","messageId":"200708081706.58088.simon@lst.de","threadId":"9435","inReplyTo":null,"subject":"[PATCH] git-p4: Fix git-p4 submit to include only changed files in the perforce submit template.","fromName":"Simon Hausmann","fromEmail":"simon@lst.de","sentAt":"2007-08-08T15:06:55Z","receivedAt":"2007-08-08T15:06:55Z","isPatch":true,"sender":{"key":"hausmann@kde.org","avatar":"https://gravatar.com/avatar/bc9aad4fb31dce17eb66e690e7b51fe980c62da3c225c785da35dd806b8da778?d=mp&s=160"},"body":"Parse the files section in the \"p4 change -o\" output and remove lines with file changes in unrelated depot paths.\n\nSigned-off-by: Simon Hausmann <simon@lst.de>\nSigned-off-by: Marius Storm-Olsen <marius@trolltech.com>\n---\n\n contrib/fast-import/git-p4 |   36 ++++++++++++++++++++++++++++++------\n 1 files changed, 30 insertions(+), 6 deletions(-)\n\ndiff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4\nindex 3cbb2da..805d632 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -390,6 +390,30 @@ class P4Submit(Command):\n \n         return result\n \n+    def prepareSubmitTemplate(self):\n+        # remove lines in the Files section that show changes to files outside the depot path we're committing into\n+        template = \"\"\n+        inFilesSection = False\n+        for line in read_pipe_lines(\"p4 change -o\"):\n+            if inFilesSection:\n+                if line.startswith(\"\\t\"):\n+                    # path starts and ends with a tab\n+                    path = line[1:]\n+                    lastTab = path.rfind(\"\\t\")\n+                    if lastTab != -1:\n+                        path = path[:lastTab]\n+                        if not path.startswith(self.depotPath):\n+                            continue\n+                else:\n+                    inFilesSection = False\n+            else:\n+                if line.startswith(\"Files:\"):\n+                    inFilesSection = True\n+\n+            template += line\n+\n+        return template\n+\n     def applyCommit(self, id):\n         if self.directSubmit:\n             print \"Applying local change in working directory/index\"\n@@ -467,7 +491,7 @@ class P4Submit(Command):\n                 logMessage = logMessage.replace(\"\\n\", \"\\r\\n\")\n             logMessage = logMessage.strip()\n \n-        template = read_pipe(\"p4 change -o\")\n+        template = self.prepareSubmitTemplate()\n \n         if self.interactive:\n             submitTemplate = self.prepareLogMessage(template, logMessage)\n@@ -558,24 +582,24 @@ class P4Submit(Command):\n             return False\n \n         [upstream, settings] = findUpstreamBranchPoint()\n-        depotPath = settings['depot-paths'][0]\n+        self.depotPath = settings['depot-paths'][0]\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(depotPath) == 0:\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(depotPath)\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\" % depotPath\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\" % (depotPath, self.clientPath)\n+        print \"Perforce checkout for depot path %s located at %s\" % (self.depotPath, self.clientPath)\n         self.oldWorkingDirectory = os.getcwd()\n \n         if self.directSubmit:\n-- \n1.5.3.rc3.91.g5c75\n"}]}