git-send-email: allow re-editing of message

When shown the email summary, an opportunity is presented for the user to edit the email as if they had specified --annotate. This also permits them to edit it multiple times. Signed-off-by: Drew DeVault <sir@cmpwn.com> Reviewed-by: Simon Ser <contact@emersion.fr> Helped-by: Eric Wong <e@80x24.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Drew DeVault committed May 4, 2018 at 09:08 UTC 04c4a4e865c1735edec553408aa7b4db6eb17263
1 file changed +31 -7
git-send-email.perl
+31 -7
@@ -1330,9 +1330,14 @@ sub file_name_is_absolute {
1330 return File::Spec::Functions::file_name_is_absolute($path);
1331 }
1332
1333 -# Returns 1 if the message was sent, and 0 otherwise.
1334 -# In actuality, the whole program dies when there
1335 -# is an error sending a message.
1333 +# Prepares the email, then asks the user what to do.
1334 +#
1335 +# If the user chooses to send the email, it's sent and 1 is returned.
1336 +# If the user chooses not to send the email, 0 is returned.
1337 +# If the user decides they want to make further edits, -1 is returned and the
1338 +# caller is expected to call send_message again after the edits are performed.
1339 +#
1340 +# If an error occurs sending the email, this just dies.
1341
1342 sub send_message {
1343 my @recipients = unique_email_list(@to);
@@ -1404,15 +1409,17 @@ Message-Id: $message_id
1409
1410 EOF
1411 }
1407 - # TRANSLATORS: Make sure to include [y] [n] [q] [a] in your
1412 + # TRANSLATORS: Make sure to include [y] [n] [e] [q] [a] in your
1413 # translation. The program will only accept English input
1414 # at this point.
1410 - $_ = ask(__("Send this email? ([y]es|[n]o|[q]uit|[a]ll): "),
1411 - valid_re => qr/^(?:yes|y|no|n|quit|q|all|a)/i,
1415 + $_ = ask(__("Send this email? ([y]es|[n]o|[e]dit|[q]uit|[a]ll): "),
1416 + valid_re => qr/^(?:yes|y|no|n|edit|e|quit|q|all|a)/i,
1417 default => $ask_default);
1418 die __("Send this email reply required") unless defined $_;
1419 if (/^n/i) {
1420 return 0;
1421 + } elsif (/^e/i) {
1422 + return -1;
1423 } elsif (/^q/i) {
1424 cleanup_compose_files();
1425 exit(0);
@@ -1552,7 +1559,12 @@ $references = $initial_in_reply_to || '';
1559 $subject = $initial_subject;
1560 $message_num = 0;
1561
1555 -foreach my $t (@files) {
1562 +# Prepares the email, prompts the user, sends it out
1563 +# Returns 0 if an edit was done and the function should be called again, or 1
1564 +# otherwise.
1565 +sub process_file {
1566 + my ($t) = @_;
1567 +
1568 open my $fh, "<", $t or die sprintf(__("can't open file %s"), $t);
1569
1570 my $author = undef;
@@ -1755,6 +1767,10 @@ foreach my $t (@files) {
1767 }
1768
1769 my $message_was_sent = send_message();
1770 + if ($message_was_sent == -1) {
1771 + do_edit($t);
1772 + return 0;
1773 + }
1774
1775 # set up for the next message
1776 if ($thread && $message_was_sent &&
@@ -1776,6 +1792,14 @@ foreach my $t (@files) {
1792 undef $auth;
1793 sleep($relogin_delay) if defined $relogin_delay;
1794 }
1795 +
1796 + return 1;
1797 +}
1798 +
1799 +foreach my $t (@files) {
1800 + while (!process_file($t)) {
1801 + # user edited the file
1802 + }
1803 }
1804
1805 # Execute a command (e.g. $to_cmd) to get a list of email addresses