git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] send-email: prompt-dependent exit codes
@ 2023-04-26  6:16 Oswald Buddenhagen
  2023-04-27 15:49 ` Junio C Hamano
  0 siblings, 1 reply; 18+ messages in thread
From: Oswald Buddenhagen @ 2023-04-26  6:16 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>

---
v2:
- fix do_quit() not resetting $sent_all
---
 git-send-email.perl | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index 07f2a0cbea..7587cd2d20 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -254,6 +254,19 @@ 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();
+	$sent_all = 0;
+	do_exit();
+}
+
 sub do_edit {
 	if (!defined($editor)) {
 		$editor = Git::command_oneline('var', 'GIT_EDITOR');
@@ -1172,8 +1185,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 +1605,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 +1979,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 +2204,5 @@ sub body_or_subject_has_nonascii {
 	}
 	return 0;
 }
+
+do_exit();
-- 
2.40.0.152.g15d061e6df


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

end of thread, other threads:[~2023-08-30 18:29 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-26  6:16 [PATCH v2] send-email: prompt-dependent exit codes Oswald Buddenhagen
2023-04-27 15:49 ` Junio C Hamano
2023-05-02 19:04   ` Felipe Contreras
2023-08-07 16:58   ` [PATCH v3] " Oswald Buddenhagen
2023-08-07 18:55     ` Junio C Hamano
2023-08-08 10:55       ` Oswald Buddenhagen
2023-08-08 16:08         ` Junio C Hamano
2023-08-08 19:11           ` Oswald Buddenhagen
2023-08-09 17:15           ` [PATCH v4] " Oswald Buddenhagen
2023-08-09 19:15             ` Junio C Hamano
2023-08-10 10:00               ` Oswald Buddenhagen
2023-08-10 19:56                 ` Junio C Hamano
2023-08-11 12:11                   ` Oswald Buddenhagen
2023-08-21 17:07                   ` [PATCH v5] " Oswald Buddenhagen
2023-08-21 17:57                     ` Junio C Hamano
2023-08-21 18:57                       ` Oswald Buddenhagen
2023-08-30  0:46                     ` Junio C Hamano
2023-08-30 10:06                       ` Oswald Buddenhagen

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).