Skip to content

Commit ae6c098

Browse files
Steven Drakegitster
authored andcommitted
Add 'git format-patch --to=' option and 'format.to' configuration variable.
Has the same functionality as the '--cc' option and 'format.cc' configuration variable but for the "To:" email header. Half of the code to support this was already there. With email the To: header usually more important than the Cc: header. [jc: tests are by Stephen Boyd] Signed-off-by: Steven Drake <[email protected]> Signed-off-by: Stephen Boyd <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e923eae commit ae6c098

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

Documentation/git-format-patch.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ SYNOPSIS
1818
[--in-reply-to=Message-Id] [--suffix=.<sfx>]
1919
[--ignore-if-in-upstream]
2020
[--subject-prefix=Subject-Prefix]
21-
[--cc=<email>]
21+
[--to=<email>] [--cc=<email>]
2222
[--cover-letter]
2323
[<common diff options>]
2424
[ <since> | <revision range> ]
@@ -162,6 +162,10 @@ will want to ensure that threading is disabled for `git send-email`.
162162
allows for useful naming of a patch series, and can be
163163
combined with the `--numbered` option.
164164

165+
--to=<email>::
166+
Add a `To:` header to the email headers. This is in addition
167+
to any configured headers, and may be used multiple times.
168+
165169
--cc=<email>::
166170
Add a `Cc:` header to the email headers. This is in addition
167171
to any configured headers, and may be used multiple times.
@@ -202,15 +206,16 @@ CONFIGURATION
202206
-------------
203207
You can specify extra mail header lines to be added to each message,
204208
defaults for the subject prefix and file suffix, number patches when
205-
outputting more than one patch, add "Cc:" headers, configure attachments,
206-
and sign off patches with configuration variables.
209+
outputting more than one patch, add "To" or "Cc:" headers, configure
210+
attachments, and sign off patches with configuration variables.
207211

208212
------------
209213
[format]
210214
headers = "Organization: git-foo\n"
211215
subjectprefix = CHANGE
212216
suffix = .txt
213217
numbered = auto
218+
to = <email>
214219
cc = <email>
215220
attach [ = mime-boundary-string ]
216221
signoff = true

builtin-log.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,13 @@ static int git_format_config(const char *var, const char *value, void *cb)
504504
}
505505
if (!strcmp(var, "format.suffix"))
506506
return git_config_string(&fmt_patch_suffix, var, value);
507+
if (!strcmp(var, "format.to")) {
508+
if (!value)
509+
return config_error_nonbool(var);
510+
ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc);
511+
extra_to[extra_to_nr++] = xstrdup(value);
512+
return 0;
513+
}
507514
if (!strcmp(var, "format.cc")) {
508515
if (!value)
509516
return config_error_nonbool(var);
@@ -875,6 +882,13 @@ static int header_callback(const struct option *opt, const char *arg, int unset)
875882
return 0;
876883
}
877884

885+
static int to_callback(const struct option *opt, const char *arg, int unset)
886+
{
887+
ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc);
888+
extra_to[extra_to_nr++] = xstrdup(arg);
889+
return 0;
890+
}
891+
878892
static int cc_callback(const struct option *opt, const char *arg, int unset)
879893
{
880894
ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc);
@@ -939,6 +953,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
939953
{ OPTION_CALLBACK, 0, "add-header", NULL, "header",
940954
"add email header", PARSE_OPT_NONEG,
941955
header_callback },
956+
{ OPTION_CALLBACK, 0, "to", NULL, "email", "add To: header",
957+
PARSE_OPT_NONEG, to_callback },
942958
{ OPTION_CALLBACK, 0, "cc", NULL, "email", "add Cc: header",
943959
PARSE_OPT_NONEG, cc_callback },
944960
OPT_STRING(0, "in-reply-to", &in_reply_to, "message-id",

t/t4014-format-patch.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@ test_expect_success 'configuration headers and command line headers' '
143143
grep "^ *S. E. Cipient <[email protected]>\$" patch7
144144
'
145145

146+
test_expect_success 'command line To: header' '
147+
148+
git config --unset-all format.headers &&
149+
git format-patch --to="R. E. Cipient <[email protected]>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
150+
grep "^To: R. E. Cipient <[email protected]>\$" patch8
151+
'
152+
153+
test_expect_success 'configuration To: header' '
154+
155+
git config format.to "R. E. Cipient <[email protected]>" &&
156+
git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
157+
grep "^To: R. E. Cipient <[email protected]>\$" patch9
158+
'
159+
146160
test_expect_success 'multiple files' '
147161
148162
rm -rf patches/ &&

0 commit comments

Comments
 (0)