{"thread":{"id":"22332","subject":"[PATCH 2/3] git-p4: improve submit dialogs","startedAt":"2010-01-22T02:05:04Z","lastAt":"2010-01-22T02:05:04Z","messageCount":1,"participants":["Pal-Kristian Engstad"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"132358","messageId":"4B5907D0.9070608@naughtydog.com","threadId":"22332","inReplyTo":null,"subject":"[PATCH 2/3] git-p4: improve submit dialogs","fromName":"Pal-Kristian Engstad","fromEmail":"pal_engstad@naughtydog.com","sentAt":"2010-01-22T02:05:04Z","receivedAt":"2010-01-22T02:05:04Z","isPatch":true,"sender":{"key":"pal_engstad@naughtydog.com","avatar":null},"body":"Improve the git-p4 submit process by adding additional submit options.\n\n* The regular commit sequence now gives the options of:\n  + [y] to submit the patch as is,\n  + [c] to display the Perforce commit through \"less\",\n  + [d] to display the output of \"p4 diff -du\" through \"less\",\n  + [e] to edit the message before submitting,\n  + [n] to skip the patch.\n\n* Add a --no-prompt option to submit multiple check-ins without any\n  prompts. This feature is useful for when many changes needs to be\n  checked in. The git commit message is assumed as the Perforce\n  submit message.\n\n* Add an --edit option to preserve the previous submission process.\n\nSigned-off-by: Pal-Kristian Engstad <pal_engstad@naughtydog.com>\n---\n contrib/fast-import/git-p4 |   75 +++++++++++++++++++++++++++++++++++--------\n 1 files changed, 61 insertions(+), 14 deletions(-)\n\ndiff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4\nindex c65ef8a..ab538b3 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -545,6 +545,10 @@ class P4Submit(Command):\n                 optparse.make_option(\"--origin\", dest=\"origin\"),\n                 optparse.make_option(\"--no-detect\", dest=\"detectRename\", action=\"store_false\",\n                                      help=\"Disable git's rename detection, forcing \\\"p4 delete\\\" and \\\"p4 add\\\" instead of \\\"p4 integrate\\\" and \\\"p4 edit\\\"\"),\n+                optparse.make_option(\"--no-prompt\", dest=\"prompt\", action=\"store_false\",\n+                                     help=\"Check in every git change into the perforce database without any prompts\"),\n+                optparse.make_option(\"--edit\", dest=\"editCommit\", action=\"store_true\",\n+                                     help=\"Edit every commit before submitting (old procedure)\")\n         ]\n         self.description = \"Submit changes from git to the perforce depot.\"\n         self.usage += \" [name of git branch to submit into perforce depot]\"\n@@ -552,6 +556,8 @@ class P4Submit(Command):\n         self.origin = \"\"\n         self.detectRename = True\n         self.verbose = False\n+        self.editCommit = False\n+        self.prompt = True\n         self.isWindows = (platform.system() == \"Windows\")\n \n     def check(self):\n@@ -657,19 +663,21 @@ class P4Submit(Command):\n \n         if os.system(tryPatchCmd) != 0:\n             print \"Unfortunately applying the change failed!\"\n+            print \"This may be because you need to rebase your commits to the latest P4 changes.\"\n             print \"What do you want to do?\"\n             response = \"x\"\n-            while response != \"s\" and response != \"a\" and response != \"w\":\n-                response = raw_input(\"[s]kip this patch / [a]pply the patch forcibly \"\n+            while response != \"s\" and response != \"f\" and response != \"a\" and response != \"w\":\n+                response = raw_input(\"[a]bort / [s]kip this patch / apply the patch [f]orcibly \"\n                                      \"and with .rej files / [w]rite the patch to a file (patch.txt) \")\n-            if response == \"s\":\n-                print \"Skipping! Good luck with the next patches...\"\n+            if response == \"s\" or response == \"a\":\n+                if response == \"s\":\n+                    print \"Skipping! Next set of patches might fail...\"\n                 for f in editedFiles:\n                     p4_system(\"revert \\\"%s\\\"\" % f);\n                 for f in filesToAdd:\n                     system(\"rm %s\" %f)\n-                return\n-            elif response == \"a\":\n+                return response == \"a\"\n+            elif response == \"f\":\n                 os.system(applyPatchCmd)\n                 if len(filesToAdd) > 0:\n                     print \"You may also want to call p4 add on the following files:\"\n@@ -729,18 +737,28 @@ class P4Submit(Command):\n                 newdiff = newdiff.replace(\"\\n\", \"\\r\\n\")\n             tmpFile.write(submitTemplate + separatorLine + diff + newdiff)\n             tmpFile.close()\n-            mtime = os.stat(fileName).st_mtime\n+\n             if os.environ.has_key(\"P4EDITOR\"):\n                 editor = os.environ.get(\"P4EDITOR\")\n             else:\n                 editor = read_pipe(\"git var GIT_EDITOR\")\n-            system(editor + \" \" + fileName)\n \n-            response = \"y\"\n-            if os.stat(fileName).st_mtime <= mtime:\n+            if self.editCommit:\n+                response = \"e\"\n+            elif not self.prompt:\n+                response = \"y\"\n+            else:\n                 response = \"x\"\n-                while response != \"y\" and response != \"n\":\n-                    response = raw_input(\"Submit template unchanged. Submit anyway? [y]es, [n]o (skip this patch) \")\n+                print \"--- Description --------------------------------------------------------------------\"\n+                print logMessage\n+                print \"------------------------------------------------------------------------------------\"\n+\n+                while response != \"y\" and response != \"n\" and response != \"e\":\n+                    response = raw_input(\"Submit: [y]es, see P4 [c]ommit, see [d]iff, [e]dit message first, or [n]o (skip this patch) \")\n+                    if response == \"d\":\n+                        system(\"less \" + fileName)\n+                    elif response == \"c\":\n+                        print submitTemplate\n \n             if response == \"y\":\n                 tmpFile = open(fileName, \"rb\")\n@@ -750,14 +768,39 @@ class P4Submit(Command):\n                 if self.isWindows:\n                     submitTemplate = submitTemplate.replace(\"\\r\\n\", \"\\n\")\n                 p4_write_pipe(\"submit -i\", submitTemplate)\n-            else:\n+            elif response == \"n\":\n                 for f in editedFiles:\n                     p4_system(\"revert \\\"%s\\\"\" % f);\n                 for f in filesToAdd:\n                     p4_system(\"revert \\\"%s\\\"\" % f);\n                     system(\"rm %s\" %f)\n+            elif self.editCommit or response == \"e\":\n+                mtime = os.stat(fileName).st_mtime\n+                system(editor + \" \" + fileName)\n+\n+                response = \"y\"\n+                if os.stat(fileName).st_mtime <= mtime:\n+                    response = \"x\"\n+                    while response != \"y\" and response != \"n\":\n+                        response = raw_input(\"Submit template unchanged. Submit anyway? [y]es, [n]o (skip this patch) \")\n+\n+                if response == \"y\":\n+                    tmpFile = open(fileName, \"rb\")\n+                    message = tmpFile.read()\n+                    tmpFile.close()\n+                    submitTemplate = message[:message.index(separatorLine)]\n+                    if self.isWindows:\n+                        submitTemplate = submitTemplate.replace(\"\\r\\n\", \"\\n\")\n+                    p4_write_pipe(\"submit -i\", submitTemplate)\n+                else:\n+                    for f in editedFiles:\n+                        p4_system(\"revert \\\"%s\\\"\" % f);\n+                    for f in filesToAdd:\n+                        p4_system(\"revert \\\"%s\\\"\" % f);\n+                        system(\"rm %s\" %f)\n \n             os.remove(fileName)\n+            return True\n         else:\n             fileName = \"submit.txt\"\n             file = open(fileName, \"w+\")\n@@ -766,6 +809,7 @@ class P4Submit(Command):\n             print (\"Perforce submit template written as %s. \"\n                    + \"Please review/edit and then use p4 submit -i < %s to submit directly!\"\n                    % (fileName, fileName))\n+            return False\n \n     def run(self, args):\n         if len(args) == 0:\n@@ -813,10 +857,13 @@ class P4Submit(Command):\n             commits.append(line.strip())\n         commits.reverse()\n \n+        startCommits = len(commits)\n+\n         while len(commits) > 0:\n             commit = commits[0]\n             commits = commits[1:]\n-            self.applyCommit(commit)\n+            if not self.applyCommit(commit):\n+                break\n             if not self.interactive:\n                 break\n \n-- \n1.6.5.2.6.gc3c1e.dirty\n"}]}