git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Date
Aug 7, 2023, 16:58 UTC
Message-ID
<20230807165850.2335067-1-oswald.buddenhagen@gmx.de>
In-Reply-To
<xmqqttx1l3zp.fsf@gitster.g>

From the perspective of a scripted 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.

For interactive calls from the command line, interactive cancellation is arguably not really an error, but there the exit code will be more or less ignored anyway.

Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
---
v3:
- use a tally instead of flags after all, as my seemingly simple idea
  apparently requires lots of thinking to grasp fully
- correct exit code when zero messages are to be sent. this cannot
  actually happen, as it induces an exit via usage() earlier on.
- unfold nested ternary to save junio's sanity (who proved his point by
  unfolding it slightly incorrectly)
- expand commit message
v2:
- fix do_quit() not resetting $sent_all
Cc: Junio C Hamano <gitster@pobox.com>
Cc: Phillip Wood <phillip.wood123@gmail.com>
---
 git-send-email.perl | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index affbb88509..cd4db84b7f 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -256,6 +256,26 @@ sub system_or_die {
 	die $msg if $msg;
 }
 
+my $sent_files = 0;
+
+sub do_exit {
+	if ($sent_files == @files) {
+		# All specified messages were sent
+		exit(0);
+	} elsif ($sent_files) {
+		# At least some messages were sent
+		exit(10);
+	} else {
+		# User cancelled on first message already
+		exit(11);
+	}
+}
+
+sub do_quit {
+	cleanup_compose_files();
+	do_exit();
+}
+
 sub do_edit {
 	if (!defined($editor)) {
 		$editor = Git::command_oneline('var', 'GIT_EDITOR');
@@ -1195,8 +1215,7 @@ sub validate_address {
 		if (/^d/i) {
 			return undef;
 		} elsif (/^q/i) {
-			cleanup_compose_files();
-			exit(0);
+			do_quit();
 		}
 		$address = ask("$to_whom ",
 			default => "",
@@ -1619,8 +1638,7 @@ sub send_message {
 		} elsif (/^e/i) {
 			return -1;
 		} elsif (/^q/i) {
-			cleanup_compose_files();
-			exit(0);
+			do_quit();
 		} elsif (/^a/i) {
 			$confirm = 'never';
 		}
@@ -2001,6 +2019,10 @@ sub process_file {
 		return 0;
 	}
 
+	if ($message_was_sent) {
+		$sent_files++;
+	}
+
 	# set up for the next message
 	if ($thread) {
 		if ($message_was_sent &&
@@ -2278,3 +2300,5 @@ sub body_or_subject_has_nonascii {
 	}
 	return 0;
 }
+
+do_exit();
-- 
2.40.0.152.g15d061e6df
Previous: Felipe ContrerasNext: Junio C Hamano
Message 4 of 18 in “send-email: prompt-dependent exit codes”
  1. send-email: prompt-dependent exit codesOswald Buddenhagen, Apr 26, 2023
  2. Junio C HamanoApr 27, 2023
  3. Felipe ContrerasMay 2, 2023
  4. send-email: prompt-dependent exit codesOswald Buddenhagen, Aug 7, 2023
  5. Junio C HamanoAug 7, 2023
  6. Oswald BuddenhagenAug 8, 2023
  7. Junio C HamanoAug 8, 2023
  8. Oswald BuddenhagenAug 8, 2023
  9. send-email: prompt-dependent exit codesOswald Buddenhagen, Aug 9, 2023
  10. Junio C HamanoAug 9, 2023
  11. Oswald BuddenhagenAug 10, 2023
  12. Junio C HamanoAug 10, 2023
  13. Oswald BuddenhagenAug 11, 2023
  14. send-email: prompt-dependent exit codesOswald Buddenhagen, Aug 21, 2023
  15. Junio C HamanoAug 21, 2023
  16. Oswald BuddenhagenAug 21, 2023
  17. Junio C HamanoAug 30, 2023
  18. Oswald BuddenhagenAug 30, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.