@matheusbsbs / matheus-bagliano / commits / cdc7e388da
Fork 0

Make it possible to abort the submission of a change to Perforce

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Simon Hausmann committed Aug 27, 2008 at 09:30 UTC cdc7e388da47b66fe11c92ed7698ec233ce70635
1 file changed +23 -8
contrib/fast-import/git-p4
+23 -8
@@ -708,6 +708,7 @@ class P4Submit(Command):
708 newdiff = newdiff.replace("\n", "\r\n")
709 tmpFile.write(submitTemplate + separatorLine + diff + newdiff)
710 tmpFile.close()
711 + mtime = os.stat(fileName).st_mtime
712 defaultEditor = "vi"
713 if platform.system() == "Windows":
714 defaultEditor = "notepad"
@@ -716,15 +717,29 @@ class P4Submit(Command):
717 else:
718 editor = os.environ.get("EDITOR", defaultEditor);
719 system(editor + " " + fileName)
719 - tmpFile = open(fileName, "rb")
720 - message = tmpFile.read()
721 - tmpFile.close()
722 - os.remove(fileName)
723 - submitTemplate = message[:message.index(separatorLine)]
724 - if self.isWindows:
725 - submitTemplate = submitTemplate.replace("\r\n", "\n")
720
727 - p4_write_pipe("submit -i", submitTemplate)
721 + response = "y"
722 + if os.stat(fileName).st_mtime <= mtime:
723 + response = "x"
724 + while response != "y" and response != "n":
725 + response = raw_input("Submit template unchanged. Submit anyway? [y]es, [n]o (skip this patch) ")
726 +
727 + if response == "y":
728 + tmpFile = open(fileName, "rb")
729 + message = tmpFile.read()
730 + tmpFile.close()
731 + submitTemplate = message[:message.index(separatorLine)]
732 + if self.isWindows:
733 + submitTemplate = submitTemplate.replace("\r\n", "\n")
734 + p4_write_pipe("submit -i", submitTemplate)
735 + else:
736 + for f in editedFiles:
737 + p4_system("revert \"%s\"" % f);
738 + for f in filesToAdd:
739 + p4_system("revert \"%s\"" % f);
740 + system("rm %s" %f)
741 +
742 + os.remove(fileName)
743 else:
744 fileName = "submit.txt"
745 file = open(fileName, "w+")