git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] send-email: prompt-dependent exit codes
@ 2023-03-23 16:22 Oswald Buddenhagen
  2023-03-24 14:56 ` Phillip Wood
  0 siblings, 1 reply; 2+ messages in thread
From: Oswald Buddenhagen @ 2023-03-23 16:22 UTC (permalink / raw)
  To: git

From the perspective of the caller, failure to send (some) mails is an
error even if it was interactively requested, so it should be indicated
by the exit code.

To make it somewhat specific, the exit code is 10 when only some mails
were skipped, and 11 if the user quit on the first prompt.

Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
---
 git-send-email.perl | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index 07f2a0cbea..2ab6766583 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -254,6 +254,18 @@ sub system_or_die {
 	die $msg if $msg;
 }
 
+my $sent_any = 0;
+my $sent_all = 1;
+
+sub do_exit {
+	exit($sent_any ? $sent_all ? 0 : 10 : 11);
+}
+
+sub do_quit {
+	cleanup_compose_files();
+	do_exit();
+}
+
 sub do_edit {
 	if (!defined($editor)) {
 		$editor = Git::command_oneline('var', 'GIT_EDITOR');
@@ -1172,8 +1184,7 @@ sub validate_address {
 		if (/^d/i) {
 			return undef;
 		} elsif (/^q/i) {
-			cleanup_compose_files();
-			exit(0);
+			do_quit();
 		}
 		$address = ask("$to_whom ",
 			default => "",
@@ -1593,8 +1604,7 @@ sub send_message {
 		} elsif (/^e/i) {
 			return -1;
 		} elsif (/^q/i) {
-			cleanup_compose_files();
-			exit(0);
+			do_quit();
 		} elsif (/^a/i) {
 			$confirm = 'never';
 		}
@@ -1968,6 +1978,12 @@ sub process_file {
 		return 0;
 	}
 
+	if ($message_was_sent) {
+		$sent_any = 1;
+	} else {
+		$sent_all = 0;
+	}
+
 	# set up for the next message
 	if ($thread) {
 		if ($message_was_sent &&
@@ -2187,3 +2203,5 @@ sub body_or_subject_has_nonascii {
 	}
 	return 0;
 }
+
+do_exit();
-- 
2.40.0.152.g15d061e6df


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

* Re: [PATCH] send-email: prompt-dependent exit codes
  2023-03-23 16:22 [PATCH] send-email: prompt-dependent exit codes Oswald Buddenhagen
@ 2023-03-24 14:56 ` Phillip Wood
  0 siblings, 0 replies; 2+ messages in thread
From: Phillip Wood @ 2023-03-24 14:56 UTC (permalink / raw)
  To: Oswald Buddenhagen, git

Hi Oswald

On 23/03/2023 16:22, Oswald Buddenhagen wrote:
>  From the perspective of the caller, failure to send (some) mails is an
> error even if it was interactively requested, so it should be indicated
> by the exit code.

I think this is a useful change as I was caught out by the existing 
behavior recently when I quit send-email without sending any patches and 
the shell thought it exited successfully.

I'm not sure about this implementation though. If I send one patch and 
then quit it looks like it will still exit(0) as both $sent_any and 
$sent_all will be true. I think it would be better to count the number 
of patches sent and compare that to the total number of patches when 
calculating the exit code to use.

Best Wishes

Phillip

> To make it somewhat specific, the exit code is 10 when only some mails
> were skipped, and 11 if the user quit on the first prompt.
> 
> Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
> ---
>   git-send-email.perl | 26 ++++++++++++++++++++++----
>   1 file changed, 22 insertions(+), 4 deletions(-)
> 
> diff --git a/git-send-email.perl b/git-send-email.perl
> index 07f2a0cbea..2ab6766583 100755
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -254,6 +254,18 @@ sub system_or_die {
>   	die $msg if $msg;
>   }
>   
> +my $sent_any = 0;
> +my $sent_all = 1;
> +
> +sub do_exit {
> +	exit($sent_any ? $sent_all ? 0 : 10 : 11);
> +}
> +
> +sub do_quit {
> +	cleanup_compose_files();
> +	do_exit();
> +}
> +
>   sub do_edit {
>   	if (!defined($editor)) {
>   		$editor = Git::command_oneline('var', 'GIT_EDITOR');
> @@ -1172,8 +1184,7 @@ sub validate_address {
>   		if (/^d/i) {
>   			return undef;
>   		} elsif (/^q/i) {
> -			cleanup_compose_files();
> -			exit(0);
> +			do_quit();
>   		}
>   		$address = ask("$to_whom ",
>   			default => "",
> @@ -1593,8 +1604,7 @@ sub send_message {
>   		} elsif (/^e/i) {
>   			return -1;
>   		} elsif (/^q/i) {
> -			cleanup_compose_files();
> -			exit(0);
> +			do_quit();
>   		} elsif (/^a/i) {
>   			$confirm = 'never';
>   		}
> @@ -1968,6 +1978,12 @@ sub process_file {
>   		return 0;
>   	}
>   
> +	if ($message_was_sent) {
> +		$sent_any = 1;
> +	} else {
> +		$sent_all = 0;
> +	}
> +
>   	# set up for the next message
>   	if ($thread) {
>   		if ($message_was_sent &&
> @@ -2187,3 +2203,5 @@ sub body_or_subject_has_nonascii {
>   	}
>   	return 0;
>   }
> +
> +do_exit();

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

end of thread, other threads:[~2023-03-24 14:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-23 16:22 [PATCH] send-email: prompt-dependent exit codes Oswald Buddenhagen
2023-03-24 14:56 ` Phillip Wood

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).