# [PATCH] [git-p4] Make it possible to abort the submission of a change to Perforce

2 messages from 2008-08-27 to 2008-08-27. Participants: Simon Hausmann, Junio C Hamano.
Thread: https://gitlist.dev/t/15214

## Simon Hausmann, 2008-08-27 07:30

Subject: [PATCH] [git-p4] Make it possible to abort the submission of a change to Perforce
Message-ID: <200808270937.10577.simon@lst.de>
URL: https://gitlist.dev/e/200808270937.10577.simon%40lst.de

```
Currently it is not possible to skip the submission of a change to Perforce
when running git-p4 submit. This patch compares the modification time before
and after the submit editor invokation and offers a prompt for skipping if
the submit template file was not saved.

Signed-off-by: Simon Hausmann <simon@lst.de>
---
 contrib/fast-import/git-p4 |   31 +++++++++++++++++++++++--------
 1 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4
index 46136d4..c1d24b3 100755
--- a/contrib/fast-import/git-p4
+++ b/contrib/fast-import/git-p4
@@ -708,6 +708,7 @@ class P4Submit(Command):
                 newdiff = newdiff.replace("\n", "\r\n")
             tmpFile.write(submitTemplate + separatorLine + diff + newdiff)
             tmpFile.close()
+            mtime = os.stat(fileName).st_mtime
             defaultEditor = "vi"
             if platform.system() == "Windows":
                 defaultEditor = "notepad"
@@ -716,15 +717,29 @@ class P4Submit(Command):
             else:
                 editor = os.environ.get("EDITOR", defaultEditor);
             system(editor + " " + fileName)
-            tmpFile = open(fileName, "rb")
-            message = tmpFile.read()
-            tmpFile.close()
-            os.remove(fileName)
-            submitTemplate = message[:message.index(separatorLine)]
-            if self.isWindows:
-                submitTemplate = submitTemplate.replace("\r\n", "\n")
 
-            p4_write_pipe("submit -i", submitTemplate)
+            response = "y"
+            if os.stat(fileName).st_mtime <= mtime:
+                response = "x"
+                while response != "y" and response != "n":
+                    response = raw_input("Submit template unchanged. Submit anyway? [y]es, [n]o (skip this patch) ")
+
+            if response == "y":
+                tmpFile = open(fileName, "rb")
+                message = tmpFile.read()
+                tmpFile.close()
+                submitTemplate = message[:message.index(separatorLine)]
+                if self.isWindows:
+                    submitTemplate = submitTemplate.replace("\r\n", "\n")
+                p4_write_pipe("submit -i", submitTemplate)
+            else:
+                for f in editedFiles:
+                    p4_system("revert \"%s\"" % f);
+                for f in filesToAdd:
+                    p4_system("revert \"%s\"" % f);
+                    system("rm %s" %f)
+
+            os.remove(fileName)
         else:
             fileName = "submit.txt"
             file = open(fileName, "w+")
-- 
1.6.0.2.g2ebc0

```

## Junio C Hamano, 2008-08-27 19:20

Subject: Re: [PATCH] [git-p4] Make it possible to abort the submission of a change to Perforce
Message-ID: <7vk5e2p8me.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vk5e2p8me.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <200808270937.10577.simon@lst.de>

```
Simon Hausmann <simon@lst.de> writes:

> Currently it is not possible to skip the submission of a change to Perforce
> when running git-p4 submit. This patch compares the modification time before
> and after the submit editor invokation and offers a prompt for skipping if
> the submit template file was not saved.

Applied, thanks.

It makes one wonder if mtime is a reliable enough indication or you are
better off comparing the contents, though.  The message file the user is
editing is not that big anyway, no?

```
