git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-p4: Handle p4 submit failure
@ 2015-10-28 13:12 Etienne Girard
  2015-10-30 16:44 ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Etienne Girard @ 2015-10-28 13:12 UTC (permalink / raw)
  To: Git Users

Clean the workspace if p4_write_pipe raised SystemExit,
so that the user don't have to do it themselves.

Signed-off-by: GIRARD Etienne <egirard@murex.com>
---
 git-p4.py | 71 +++++++++++++++++++++++++++++++++------------------------------
 1 file changed, 37 insertions(+), 34 deletions(-)

The p4 submit command may fail, for example if the changelist contains
a job that does not exist in the Jobs section. If this is the case,
p4_write_pipe will exit the script. This change makes it so that the
workspace is reverted before letting the script die.

diff --git a/git-p4.py b/git-p4.py
index 0093fa3..d535904 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1538,44 +1538,47 @@ class P4Submit(Command, P4UserMap):
         #
         # Let the user edit the change description, then submit it.
         #
-        if self.edit_template(fileName):
-            # read the edited message and submit
-            ret = True
-            tmpFile = open(fileName, "rb")
-            message = tmpFile.read()
-            tmpFile.close()
-            if self.isWindows:
-                message = message.replace("\r\n", "\n")
-            submitTemplate = message[:message.index(separatorLine)]
-            p4_write_pipe(['submit', '-i'], submitTemplate)
-
-            if self.preserveUser:
-                if p4User:
-                    # Get last changelist number. Cannot easily get it from
-                    # the submit command output as the output is
-                    # unmarshalled.
-                    changelist = self.lastP4Changelist()
-                    self.modifyChangelistUser(changelist, p4User)
-
-            # The rename/copy happened by applying a patch that created a
-            # new file.  This leaves it writable, which confuses p4.
-            for f in pureRenameCopy:
-                p4_sync(f, "-f")
+        submitted = False

-        else:
+        try:
+            if self.edit_template(fileName):
+                # read the edited message and submit
+                tmpFile = open(fileName, "rb")
+                message = tmpFile.read()
+                tmpFile.close()
+                if self.isWindows:
+                    message = message.replace("\r\n", "\n")
+                submitTemplate = message[:message.index(separatorLine)]
+                p4_write_pipe(['submit', '-i'], submitTemplate)
+
+                if self.preserveUser:
+                    if p4User:
+                        # Get last changelist number. Cannot easily get it from
+                        # the submit command output as the output is
+                        # unmarshalled.
+                        changelist = self.lastP4Changelist()
+                        self.modifyChangelistUser(changelist, p4User)
+
+                # The rename/copy happened by applying a patch that created a
+                # new file.  This leaves it writable, which confuses p4.
+                for f in pureRenameCopy:
+                    p4_sync(f, "-f")
+                submitted = True
+
+        finally:
             # skip this patch
-            ret = False
-            print "Submission cancelled, undoing p4 changes."
-            for f in editedFiles:
-                p4_revert(f)
-            for f in filesToAdd:
-                p4_revert(f)
-                os.remove(f)
-            for f in filesToDelete:
-                p4_revert(f)
+            if not submitted:
+                print "Submission cancelled, undoing p4 changes."
+                for f in editedFiles:
+                    p4_revert(f)
+                for f in filesToAdd:
+                    p4_revert(f)
+                    os.remove(f)
+                for f in filesToDelete:
+                    p4_revert(f)

         os.remove(fileName)
-        return ret
+        return submitted

     # Export git tags as p4 labels. Create a p4 label and then tag
     # with that.
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] git-p4: Handle p4 submit failure
  2015-10-28 13:12 [PATCH] git-p4: Handle p4 submit failure Etienne Girard
@ 2015-10-30 16:44 ` Junio C Hamano
  2015-10-30 17:33   ` Etienne Girard
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2015-10-30 16:44 UTC (permalink / raw)
  To: Etienne Girard; +Cc: Git Users, Luke Diamand, Pete Wyckoff, Lars Schneider

Etienne Girard <etienne.g.girard@gmail.com> writes:

> Clean the workspace if p4_write_pipe raised SystemExit,
> so that the user don't have to do it themselves.
>
> Signed-off-by: GIRARD Etienne <egirard@murex.com>
> ---

Thanks.  As I do not really do "p4", I am CC'ing this response to
the area experts.

First, one "procedural" comment.

You sent the patch from your gmail.com address, but signed it off
with another address (with name spelled differently).  If applied
as-is, the result will have your gmail.com address listed as the
author and that will be the name you would see in "git shortlog".

If you rather prefer to be known as the name and address you placed
on your sign-off, while sending the patch from another address, you
can do so by staring the _body_ of the message with what is called
an "in-body header", like this:

        From: GIRARD Etienne <egirard@murex.com>

        Clean the workspace if p4_write_pipe raised SystemExit,
        so that the user don't have to do it themselves.

        Signed-off-by: GIRARD Etienne <egirard@murex.com>
        ---
	  ... here you have the usual patch ...

That "From:" line would sit on the first line of the body of your
message, separated by a blank line from the body of the log message.

This is not even a problem from the project's point of view, but I
thought you would want to be aware of it, and may want a chance to
change it.

	Note: this time, you do not need to resend the patch; just
	please let me know if you want me to do the equivalent of
	the above while applying to make your murex address and name
	appear as the author in "git log" and "git shortlog" output.

FYI, you could override the "Subject:" of your e-mail header with an
in-body header (this is often useful when replying to an existing
discussion thread with a patch that shows a solution), e.g.

        From: GIRARD Etienne <egirard@murex.com>
	Subject: git-p4: clean up after p4 submit failure

        Clean the workspace if p4_write_pipe raised SystemExit,
        so that the user don't have to do it themselves.

        Signed-off-by: GIRARD Etienne <egirard@murex.com>
        ---
	  ... here you have the usual patch ...

>  git-p4.py | 71 +++++++++++++++++++++++++++++++++------------------------------
>  1 file changed, 37 insertions(+), 34 deletions(-)
>
> The p4 submit command may fail, for example if the changelist contains
> a job that does not exist in the Jobs section. If this is the case,
> p4_write_pipe will exit the script. This change makes it so that the
> workspace is reverted before letting the script die.

Some of the information contained in this paragraph deserves to be
in the log message proper.  How about

        From: GIRARD Etienne <egirard@murex.com>
	Subject: git-p4: clean up after p4 submit failure

	When "p4 submit" command fails in P4Submit.applyCommit, the
	workspace is left with the changes.  We already have a code
        to revert the changes to the workspace when the user decides
	to cancel submission by aborting the editor that edits the
	change description, and we should treat the "p4 submit"
	failure the same way.

        Clean the workspace if p4_write_pipe raised SystemExit,
        so that the user don't have to do it themselves.

        Signed-off-by: GIRARD Etienne <egirard@murex.com>

or something like that?

While trying to come up with the above description, I started
wondering if the error message wants to differentiate the two cases.

When self.edit_template() returns false, we know that the user
actively said "no I do not want to submit", and "Submission
cancelled" is perfectly fine, but when "p4 submit" fails because it
did not like the change description or if it found some other
issues, it is not necessarily that the user said "I want to cancel";
it is more like "Submission failed".

Hmm?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] git-p4: Handle p4 submit failure
  2015-10-30 16:44 ` Junio C Hamano
@ 2015-10-30 17:33   ` Etienne Girard
  2015-10-30 17:57     ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Etienne Girard @ 2015-10-30 17:33 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Users, Luke Diamand, Pete Wyckoff, Lars Schneider

Hello,

>         Note: this time, you do not need to resend the patch; just
>         please let me know if you want me to do the equivalent of
>         the above while applying to make your murex address and name
>         appear as the author in "git log" and "git shortlog" output.

I'd like my murex address to appear on the log please, if it is not
too much trouble. Thank you for all these tips on the submitting
process.

>> The p4 submit command may fail, for example if the changelist contains
>> a job that does not exist in the Jobs section. If this is the case,
>> p4_write_pipe will exit the script. This change makes it so that the
>> workspace is reverted before letting the script die.
>
> Some of the information contained in this paragraph deserves to be
> in the log message proper.  How about
>
>         From: GIRARD Etienne <egirard@murex.com>
>         Subject: git-p4: clean up after p4 submit failure
>
>         When "p4 submit" command fails in P4Submit.applyCommit, the
>         workspace is left with the changes.  We already have a code
>         to revert the changes to the workspace when the user decides
>         to cancel submission by aborting the editor that edits the
>         change description, and we should treat the "p4 submit"
>         failure the same way.
>
>         Clean the workspace if p4_write_pipe raised SystemExit,
>         so that the user don't have to do it themselves.
>
>         Signed-off-by: GIRARD Etienne <egirard@murex.com>
>
> or something like that?

It seems like a good description. Please let me know if I should
submit another patch with the proper log message

>
> While trying to come up with the above description, I started
> wondering if the error message wants to differentiate the two cases.
>
> When self.edit_template() returns false, we know that the user
> actively said "no I do not want to submit", and "Submission
> cancelled" is perfectly fine, but when "p4 submit" fails because it
> did not like the change description or if it found some other
> issues, it is not necessarily that the user said "I want to cancel";
> it is more like "Submission failed".

Yes, however if `p4 submit` fails the corresponding "Command failed"
error message is displayed, and the p4 error message itself is
displayed if any.
Tthe script will also terminate successfully if self.edit_template
returns false but it will exit with error code 1 if p4 submit fails.

So the user will get "Command failed: [...]" followed by "Submission
cancelled, undoing p4 changes", to let him know that the script failed
because of p4 and that nothing was submitted.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] git-p4: Handle p4 submit failure
  2015-10-30 17:33   ` Etienne Girard
@ 2015-10-30 17:57     ` Junio C Hamano
  2015-10-30 19:53       ` Luke Diamand
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2015-10-30 17:57 UTC (permalink / raw)
  To: Etienne Girard; +Cc: Git Users, Luke Diamand, Pete Wyckoff, Lars Schneider

Etienne Girard <etienne.g.girard@gmail.com> writes:

> Yes, however if `p4 submit` fails the corresponding "Command failed"
> error message is displayed, and the p4 error message itself is
> displayed if any.
> Tthe script will also terminate successfully if self.edit_template
> returns false but it will exit with error code 1 if p4 submit fails.
>
> So the user will get "Command failed: [...]" followed by "Submission
> cancelled, undoing p4 changes", to let him know that the script failed
> because of p4 and that nothing was submitted.

OK, then it sounds like all I have to do is to update the log
message with the "How about this" version and correct the authorship
to use your murex address, and then wait for reviews from real "git
p4" reviewers.

Thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] git-p4: Handle p4 submit failure
  2015-10-30 17:57     ` Junio C Hamano
@ 2015-10-30 19:53       ` Luke Diamand
  2015-10-30 20:23         ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Luke Diamand @ 2015-10-30 19:53 UTC (permalink / raw)
  To: Junio C Hamano, Etienne Girard; +Cc: Git Users, Pete Wyckoff, Lars Schneider

On 30/10/15 17:57, Junio C Hamano wrote:
> Etienne Girard <etienne.g.girard@gmail.com> writes:
>
>> Yes, however if `p4 submit` fails the corresponding "Command failed"
>> error message is displayed, and the p4 error message itself is
>> displayed if any.
>> Tthe script will also terminate successfully if self.edit_template
>> returns false but it will exit with error code 1 if p4 submit fails.
>>
>> So the user will get "Command failed: [...]" followed by "Submission
>> cancelled, undoing p4 changes", to let him know that the script failed
>> because of p4 and that nothing was submitted.
>
> OK, then it sounds like all I have to do is to update the log
> message with the "How about this" version and correct the authorship
> to use your murex address, and then wait for reviews from real "git
> p4" reviewers.
>

Looks good to me. Nice use of try...finally.

One very small thing - test t9807-git-p4-submit.sh is now failing with 
this change.

That's because it tries to delete one of the files it created, but you 
are now deleting it already! Could you just update that please?

Thanks!
Luke

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] git-p4: Handle p4 submit failure
  2015-10-30 19:53       ` Luke Diamand
@ 2015-10-30 20:23         ` Junio C Hamano
  0 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2015-10-30 20:23 UTC (permalink / raw)
  To: Luke Diamand; +Cc: Etienne Girard, Git Users, Pete Wyckoff, Lars Schneider

Luke Diamand <luke@diamand.org> writes:

> On 30/10/15 17:57, Junio C Hamano wrote:
>> Etienne Girard <etienne.g.girard@gmail.com> writes:
>>
>>> Yes, however if `p4 submit` fails the corresponding "Command failed"
>>> error message is displayed, and the p4 error message itself is
>>> displayed if any.
>>> Tthe script will also terminate successfully if self.edit_template
>>> returns false but it will exit with error code 1 if p4 submit fails.
>>>
>>> So the user will get "Command failed: [...]" followed by "Submission
>>> cancelled, undoing p4 changes", to let him know that the script failed
>>> because of p4 and that nothing was submitted.
>>
>> OK, then it sounds like all I have to do is to update the log
>> message with the "How about this" version and correct the authorship
>> to use your murex address, and then wait for reviews from real "git
>> p4" reviewers.
>>
>
> Looks good to me. Nice use of try...finally.
>
> One very small thing - test t9807-git-p4-submit.sh is now failing with
> this change.
>
> That's because it tries to delete one of the files it created, but you
> are now deleting it already! Could you just update that please?

I'll ask Etienne include that change in a reroll, as my environment
is not equipped to run any p4 tests.

Thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-10-30 20:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-28 13:12 [PATCH] git-p4: Handle p4 submit failure Etienne Girard
2015-10-30 16:44 ` Junio C Hamano
2015-10-30 17:33   ` Etienne Girard
2015-10-30 17:57     ` Junio C Hamano
2015-10-30 19:53       ` Luke Diamand
2015-10-30 20:23         ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).