Skip to content

Commit 8fd5bb7

Browse files
MadCodergitster
authored andcommitted
git send-email: add --annotate option
This allows to review every patch (and fix various aspects of them, or comment them) in an editor just before being sent. Combined to the fact that git send-email can now process revision lists, this makes git send-email and efficient way to review and send patches interactively. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5df9fcf commit 8fd5bb7

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

Documentation/git-send-email.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ The --bcc option must be repeated for each user you want on the bcc list.
3737
+
3838
The --cc option must be repeated for each user you want on the cc list.
3939

40+
--annotate::
41+
Review each patch you're about to send in an editor. The setting
42+
'sendemail.multiedit' defines if this will spawn one editor per patch
43+
or one for all of them at once.
44+
4045
--compose::
4146
Use $GIT_EDITOR, core.editor, $VISUAL, or $EDITOR to edit an
4247
introductory message for the patch series.
@@ -210,6 +215,12 @@ sendemail.aliasfiletype::
210215
Format of the file(s) specified in sendemail.aliasesfile. Must be
211216
one of 'mutt', 'mailrc', 'pine', or 'gnus'.
212217

218+
sendemail.multiedit::
219+
If true (default), a single editor instance will be spawned to edit
220+
files you have to edit (patches when '--annotate' is used, and the
221+
summary when '--compose' is used). If false, files will be edited one
222+
after the other, spawning a new editor each time.
223+
213224

214225
Author
215226
------

git-send-email.perl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ sub usage {
5151
--bcc <str> * Email Bcc:
5252
--subject <str> * Email "Subject:"
5353
--in-reply-to <str> * Email "In-Reply-To:"
54+
--annotate * Review each patch that will be sent in an editor.
5455
--compose * Open an editor for introduction.
5556
5657
Sending:
@@ -132,7 +133,8 @@ sub format_2822_time {
132133

133134
# Variables we fill in automatically, or via prompting:
134135
my (@to,@cc,@initial_cc,@bcclist,@xh,
135-
$initial_reply_to,$initial_subject,@files,$author,$sender,$smtp_authpass,$compose,$time);
136+
$initial_reply_to,$initial_subject,@files,
137+
$author,$sender,$smtp_authpass,$annotate,$compose,$time);
136138

137139
my $envelope_sender;
138140

@@ -155,6 +157,17 @@ sub format_2822_time {
155157
my $format_patch;
156158
my $compose_filename = $repo->repo_path() . "/.gitsendemail.msg.$$";
157159

160+
# Handle interactive edition of files.
161+
my $multiedit;
162+
my $editor = $ENV{GIT_EDITOR} || Git::config(@repo, "core.editor") || $ENV{VISUAL} || $ENV{EDITOR} || "vi";
163+
sub do_edit {
164+
if (defined($multiedit) && !$multiedit) {
165+
map { system('sh', '-c', $editor.' "$@"', $editor, $_); } @_;
166+
} else {
167+
system('sh', '-c', $editor.' "$@"', $editor, @_);
168+
}
169+
}
170+
158171
# Variables with corresponding config settings
159172
my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc, $cc_cmd);
160173
my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_encryption);
@@ -184,6 +197,7 @@ sub format_2822_time {
184197
"aliasesfile" => \@alias_files,
185198
"suppresscc" => \@suppress_cc,
186199
"envelopesender" => \$envelope_sender,
200+
"multiedit" => \$multiedit,
187201
);
188202

189203
# Handle Uncouth Termination
@@ -226,6 +240,7 @@ sub signal_handler {
226240
"smtp-ssl" => sub { $smtp_encryption = 'ssl' },
227241
"smtp-encryption=s" => \$smtp_encryption,
228242
"identity=s" => \$identity,
243+
"annotate" => \$annotate,
229244
"compose" => \$compose,
230245
"quiet" => \$quiet,
231246
"cc-cmd=s" => \$cc_cmd,
@@ -532,7 +547,12 @@ sub expand_aliases {
532547
close(C);
533548

534549
my $editor = $ENV{GIT_EDITOR} || Git::config(@repo, "core.editor") || $ENV{VISUAL} || $ENV{EDITOR} || "vi";
535-
system('sh', '-c', $editor.' "$@"', $editor, $compose_filename);
550+
551+
if ($annotate) {
552+
do_edit($compose_filename, @files);
553+
} else {
554+
do_edit($compose_filename);
555+
}
536556

537557
open(C2,">",$compose_filename . ".final")
538558
or die "Failed to open $compose_filename.final : " . $!;
@@ -581,6 +601,8 @@ sub expand_aliases {
581601
}
582602

583603
@files = ($compose_filename . ".final", @files);
604+
} elsif ($annotate) {
605+
do_edit(@files);
584606
}
585607

586608
# Variables we set as part of the loop over files

0 commit comments

Comments
 (0)