{"thread":{"id":"59450","subject":"[PATCH] send-email: prompt-dependent exit codes","startedAt":"2023-03-23T16:47:27Z","lastAt":"2023-03-24T14:56:51Z","messageCount":2,"participants":["Oswald Buddenhagen","Phillip Wood"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"474002","messageId":"20230323162234.995435-1-oswald.buddenhagen@gmx.de","threadId":"59450","inReplyTo":null,"subject":"[PATCH] send-email: prompt-dependent exit codes","fromName":"Oswald Buddenhagen","fromEmail":"oswald.buddenhagen@gmx.de","sentAt":"2023-03-23T16:22:34Z","receivedAt":"2023-03-23T16:47:27Z","isPatch":true,"sender":{"key":"oswald.buddenhagen@gmx.de","avatar":"https://avatars.githubusercontent.com/u/812380?v=4"},"body":"From the perspective of the caller, failure to send (some) mails is an\nerror even if it was interactively requested, so it should be indicated\nby the exit code.\n\nTo make it somewhat specific, the exit code is 10 when only some mails\nwere skipped, and 11 if the user quit on the first prompt.\n\nSigned-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>\n---\n git-send-email.perl | 26 ++++++++++++++++++++++----\n 1 file changed, 22 insertions(+), 4 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 07f2a0cbea..2ab6766583 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -254,6 +254,18 @@ sub system_or_die {\n \tdie $msg if $msg;\n }\n \n+my $sent_any = 0;\n+my $sent_all = 1;\n+\n+sub do_exit {\n+\texit($sent_any ? $sent_all ? 0 : 10 : 11);\n+}\n+\n+sub do_quit {\n+\tcleanup_compose_files();\n+\tdo_exit();\n+}\n+\n sub do_edit {\n \tif (!defined($editor)) {\n \t\t$editor = Git::command_oneline('var', 'GIT_EDITOR');\n@@ -1172,8 +1184,7 @@ sub validate_address {\n \t\tif (/^d/i) {\n \t\t\treturn undef;\n \t\t} elsif (/^q/i) {\n-\t\t\tcleanup_compose_files();\n-\t\t\texit(0);\n+\t\t\tdo_quit();\n \t\t}\n \t\t$address = ask(\"$to_whom \",\n \t\t\tdefault => \"\",\n@@ -1593,8 +1604,7 @@ sub send_message {\n \t\t} elsif (/^e/i) {\n \t\t\treturn -1;\n \t\t} elsif (/^q/i) {\n-\t\t\tcleanup_compose_files();\n-\t\t\texit(0);\n+\t\t\tdo_quit();\n \t\t} elsif (/^a/i) {\n \t\t\t$confirm = 'never';\n \t\t}\n@@ -1968,6 +1978,12 @@ sub process_file {\n \t\treturn 0;\n \t}\n \n+\tif ($message_was_sent) {\n+\t\t$sent_any = 1;\n+\t} else {\n+\t\t$sent_all = 0;\n+\t}\n+\n \t# set up for the next message\n \tif ($thread) {\n \t\tif ($message_was_sent &&\n@@ -2187,3 +2203,5 @@ sub body_or_subject_has_nonascii {\n \t}\n \treturn 0;\n }\n+\n+do_exit();\n-- \n2.40.0.152.g15d061e6df\n\n"},{"id":"474092","messageId":"d6c0bb22-94d4-5186-136d-4127b1eaf883@dunelm.org.uk","threadId":"59450","inReplyTo":"20230323162234.995435-1-oswald.buddenhagen@gmx.de","subject":"Re: [PATCH] send-email: prompt-dependent exit codes","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2023-03-24T14:56:37Z","receivedAt":"2023-03-24T14:56:51Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Oswald\n\nOn 23/03/2023 16:22, Oswald Buddenhagen wrote:\n>  From the perspective of the caller, failure to send (some) mails is an\n> error even if it was interactively requested, so it should be indicated\n> by the exit code.\n\nI think this is a useful change as I was caught out by the existing \nbehavior recently when I quit send-email without sending any patches and \nthe shell thought it exited successfully.\n\nI'm not sure about this implementation though. If I send one patch and \nthen quit it looks like it will still exit(0) as both $sent_any and \n$sent_all will be true. I think it would be better to count the number \nof patches sent and compare that to the total number of patches when \ncalculating the exit code to use.\n\nBest Wishes\n\nPhillip\n\n> To make it somewhat specific, the exit code is 10 when only some mails\n> were skipped, and 11 if the user quit on the first prompt.\n> \n> Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>\n> ---\n>   git-send-email.perl | 26 ++++++++++++++++++++++----\n>   1 file changed, 22 insertions(+), 4 deletions(-)\n> \n> diff --git a/git-send-email.perl b/git-send-email.perl\n> index 07f2a0cbea..2ab6766583 100755\n> --- a/git-send-email.perl\n> +++ b/git-send-email.perl\n> @@ -254,6 +254,18 @@ sub system_or_die {\n>   \tdie $msg if $msg;\n>   }\n>   \n> +my $sent_any = 0;\n> +my $sent_all = 1;\n> +\n> +sub do_exit {\n> +\texit($sent_any ? $sent_all ? 0 : 10 : 11);\n> +}\n> +\n> +sub do_quit {\n> +\tcleanup_compose_files();\n> +\tdo_exit();\n> +}\n> +\n>   sub do_edit {\n>   \tif (!defined($editor)) {\n>   \t\t$editor = Git::command_oneline('var', 'GIT_EDITOR');\n> @@ -1172,8 +1184,7 @@ sub validate_address {\n>   \t\tif (/^d/i) {\n>   \t\t\treturn undef;\n>   \t\t} elsif (/^q/i) {\n> -\t\t\tcleanup_compose_files();\n> -\t\t\texit(0);\n> +\t\t\tdo_quit();\n>   \t\t}\n>   \t\t$address = ask(\"$to_whom \",\n>   \t\t\tdefault => \"\",\n> @@ -1593,8 +1604,7 @@ sub send_message {\n>   \t\t} elsif (/^e/i) {\n>   \t\t\treturn -1;\n>   \t\t} elsif (/^q/i) {\n> -\t\t\tcleanup_compose_files();\n> -\t\t\texit(0);\n> +\t\t\tdo_quit();\n>   \t\t} elsif (/^a/i) {\n>   \t\t\t$confirm = 'never';\n>   \t\t}\n> @@ -1968,6 +1978,12 @@ sub process_file {\n>   \t\treturn 0;\n>   \t}\n>   \n> +\tif ($message_was_sent) {\n> +\t\t$sent_any = 1;\n> +\t} else {\n> +\t\t$sent_all = 0;\n> +\t}\n> +\n>   \t# set up for the next message\n>   \tif ($thread) {\n>   \t\tif ($message_was_sent &&\n> @@ -2187,3 +2203,5 @@ sub body_or_subject_has_nonascii {\n>   \t}\n>   \treturn 0;\n>   }\n> +\n> +do_exit();\n"}]}