{"thread":{"id":"15214","subject":"[PATCH] [git-p4] Make it possible to abort the submission of a change to Perforce","startedAt":"2008-08-27T07:30:29Z","lastAt":"2008-08-27T19:20:57Z","messageCount":2,"participants":["Simon Hausmann","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"88696","messageId":"200808270937.10577.simon@lst.de","threadId":"15214","inReplyTo":null,"subject":"[PATCH] [git-p4] Make it possible to abort the submission of a change to Perforce","fromName":"Simon Hausmann","fromEmail":"simon@lst.de","sentAt":"2008-08-27T07:30:29Z","receivedAt":"2008-08-27T07:30:29Z","isPatch":true,"sender":{"key":"hausmann@kde.org","avatar":"https://gravatar.com/avatar/bc9aad4fb31dce17eb66e690e7b51fe980c62da3c225c785da35dd806b8da778?d=mp&s=160"},"body":"Currently it is not possible to skip the submission of a change to Perforce\nwhen running git-p4 submit. This patch compares the modification time before\nand after the submit editor invokation and offers a prompt for skipping if\nthe submit template file was not saved.\n\nSigned-off-by: Simon Hausmann <simon@lst.de>\n---\n contrib/fast-import/git-p4 |   31 +++++++++++++++++++++++--------\n 1 files changed, 23 insertions(+), 8 deletions(-)\n\ndiff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4\nindex 46136d4..c1d24b3 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -708,6 +708,7 @@ 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             defaultEditor = \"vi\"\n             if platform.system() == \"Windows\":\n                 defaultEditor = \"notepad\"\n@@ -716,15 +717,29 @@ class P4Submit(Command):\n             else:\n                 editor = os.environ.get(\"EDITOR\", defaultEditor);\n             system(editor + \" \" + fileName)\n-            tmpFile = open(fileName, \"rb\")\n-            message = tmpFile.read()\n-            tmpFile.close()\n-            os.remove(fileName)\n-            submitTemplate = message[:message.index(separatorLine)]\n-            if self.isWindows:\n-                submitTemplate = submitTemplate.replace(\"\\r\\n\", \"\\n\")\n \n-            p4_write_pipe(\"submit -i\", submitTemplate)\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         else:\n             fileName = \"submit.txt\"\n             file = open(fileName, \"w+\")\n-- \n1.6.0.2.g2ebc0\n"},{"id":"88760","messageId":"7vk5e2p8me.fsf@gitster.siamese.dyndns.org","threadId":"15214","inReplyTo":"200808270937.10577.simon@lst.de","subject":"Re: [PATCH] [git-p4] Make it possible to abort the submission of a change to Perforce","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-27T19:20:57Z","receivedAt":"2008-08-27T19:20:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Simon Hausmann <simon@lst.de> writes:\n\n> Currently it is not possible to skip the submission of a change to Perforce\n> when running git-p4 submit. This patch compares the modification time before\n> and after the submit editor invokation and offers a prompt for skipping if\n> the submit template file was not saved.\n\nApplied, thanks.\n\nIt makes one wonder if mtime is a reliable enough indication or you are\nbetter off comparing the contents, though.  The message file the user is\nediting is not that big anyway, no?\n"}]}