[PATCH v2] send-email: prompt-dependent exit codes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>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@xxxxxx>

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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux