* [PATCH] git-send-email: allow re-editing of message
@ 2018-05-02 14:32 Drew DeVault
2018-05-04 8:19 ` Eric Wong
0 siblings, 1 reply; 2+ messages in thread
From: Drew DeVault @ 2018-05-02 14:32 UTC (permalink / raw)
To: git
Cc: Drew DeVault, Simon Ser, Ævar Arnfjörð Bjarmason,
Junio C Hamano
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>
---
Sent to the ML without comment, sending back around with more people
Cc'd for better visibility.
git-send-email.perl | 35 ++++++++++++++++++++++++++++-------
1 file changed, 28 insertions(+), 7 deletions(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index 2fa7818ca..14f2e8ae4 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1330,9 +1330,14 @@ sub file_name_is_absolute {
return File::Spec::Functions::file_name_is_absolute($path);
}
-# Returns 1 if the message was sent, and 0 otherwise.
-# In actuality, the whole program dies when there
-# is an error sending a message.
+# Prepares the email, then asks the user what to do.
+#
+# If the user chooses to send the email, it's sent and 1 is returned.
+# If the user chooses not to send the email, 0 is returned.
+# If the user decides they want to make further edits, -1 is returned and the
+# caller is expected to call send_message again after the edits are performed.
+#
+# If an error occurs sending the email, this just dies.
sub send_message {
my @recipients = unique_email_list(@to);
@@ -1404,15 +1409,17 @@ Message-Id: $message_id
EOF
}
- # TRANSLATORS: Make sure to include [y] [n] [q] [a] in your
+ # TRANSLATORS: Make sure to include [y] [n] [e] [q] [a] in your
# translation. The program will only accept English input
# at this point.
- $_ = ask(__("Send this email? ([y]es|[n]o|[q]uit|[a]ll): "),
- valid_re => qr/^(?:yes|y|no|n|quit|q|all|a)/i,
+ $_ = ask(__("Send this email? ([y]es|[n]o|[e]dit|[q]uit|[a]ll): "),
+ valid_re => qr/^(?:yes|y|no|n|edit|e|quit|q|all|a)/i,
default => $ask_default);
die __("Send this email reply required") unless defined $_;
if (/^n/i) {
return 0;
+ } elsif (/^e/i) {
+ return -1;
} elsif (/^q/i) {
cleanup_compose_files();
exit(0);
@@ -1552,7 +1559,9 @@ $references = $initial_in_reply_to || '';
$subject = $initial_subject;
$message_num = 0;
-foreach my $t (@files) {
+sub process_file {
+ my ($t) = @_;
+
open my $fh, "<", $t or die sprintf(__("can't open file %s"), $t);
my $author = undef;
@@ -1755,6 +1764,10 @@ foreach my $t (@files) {
}
my $message_was_sent = send_message();
+ if ($message_was_sent == -1) {
+ do_edit($t);
+ return 0;
+ }
# set up for the next message
if ($thread && $message_was_sent &&
@@ -1776,6 +1789,14 @@ foreach my $t (@files) {
undef $auth;
sleep($relogin_delay) if defined $relogin_delay;
}
+
+ return 1;
+}
+
+foreach my $t (@files) {
+ while (!process_file($t)) {
+ # This space deliberately left blank
+ }
}
# Execute a command (e.g. $to_cmd) to get a list of email addresses
--
2.17.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] git-send-email: allow re-editing of message
2018-05-02 14:32 [PATCH] git-send-email: allow re-editing of message Drew DeVault
@ 2018-05-04 8:19 ` Eric Wong
0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2018-05-04 8:19 UTC (permalink / raw)
To: Drew DeVault
Cc: git, Simon Ser, Ævar Arnfjörð Bjarmason, Junio C Hamano
Drew DeVault <sir@cmpwn.com> wrote:
> 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.
Thanks, this seems like a good idea for the cover letter, especially.
I prefer to get the commit messages right in the git history, first,
but I more often screw up the cover letter.
I haven't looked at the code to send-email in a while,
so some thinking out loud below :>
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -1330,9 +1330,14 @@ sub file_name_is_absolute {
> return File::Spec::Functions::file_name_is_absolute($path);
> }
>
> -# Returns 1 if the message was sent, and 0 otherwise.
> -# In actuality, the whole program dies when there
> -# is an error sending a message.
> +# Prepares the email, then asks the user what to do.
> +#
> +# If the user chooses to send the email, it's sent and 1 is returned.
> +# If the user chooses not to send the email, 0 is returned.
> +# If the user decides they want to make further edits, -1 is returned and the
> +# caller is expected to call send_message again after the edits are performed.
OK, -1 is the new return value. Thanks for documenting this.
The rest of the prompt implementation looks fine and I won't quote it.
> @@ -1552,7 +1559,9 @@ $references = $initial_in_reply_to || '';
> $subject = $initial_subject;
> $message_num = 0;
>
> -foreach my $t (@files) {
> +sub process_file {
> + my ($t) = @_;
> +
> open my $fh, "<", $t or die sprintf(__("can't open file %s"), $t);
>
> my $author = undef;
OK, process_file is a new function...
> @@ -1755,6 +1764,10 @@ foreach my $t (@files) {
> }
>
> my $message_was_sent = send_message();
> + if ($message_was_sent == -1) {
> + do_edit($t);
> + return 0;
> + }
And the previously documented -1 return value is used here.
Mental note: process_file returns 0 to indicate an edit was done.
> # set up for the next message
> if ($thread && $message_was_sent &&
> @@ -1776,6 +1789,14 @@ foreach my $t (@files) {
> undef $auth;
> sleep($relogin_delay) if defined $relogin_delay;
> }
> +
> + return 1;
Mental note: process_file normally returns 1
> +}
> +
> +foreach my $t (@files) {
> + while (!process_file($t)) {
> + # This space deliberately left blank
Cute, but that comment could say something useful, instead:
# user is still editing the file
Otherwise, I think the patch is great. Thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-05-04 8:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-02 14:32 [PATCH] git-send-email: allow re-editing of message Drew DeVault
2018-05-04 8:19 ` Eric Wong
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).