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 <sdrake@xnet.co.nz>
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Steven Drake 2010-02-17 12:39:34 +13:00 committed by Junio C Hamano
parent e923eaeb90
commit ae6c098f15
3 changed files with 38 additions and 3 deletions

View File

@ -18,7 +18,7 @@ SYNOPSIS
[--in-reply-to=Message-Id] [--suffix=.<sfx>] [--in-reply-to=Message-Id] [--suffix=.<sfx>]
[--ignore-if-in-upstream] [--ignore-if-in-upstream]
[--subject-prefix=Subject-Prefix] [--subject-prefix=Subject-Prefix]
[--cc=<email>] [--to=<email>] [--cc=<email>]
[--cover-letter] [--cover-letter]
[<common diff options>] [<common diff options>]
[ <since> | <revision range> ] [ <since> | <revision range> ]
@ -162,6 +162,10 @@ will want to ensure that threading is disabled for `git send-email`.
allows for useful naming of a patch series, and can be allows for useful naming of a patch series, and can be
combined with the `--numbered` option. combined with the `--numbered` option.
--to=<email>::
Add a `To:` header to the email headers. This is in addition
to any configured headers, and may be used multiple times.
--cc=<email>:: --cc=<email>::
Add a `Cc:` header to the email headers. This is in addition Add a `Cc:` header to the email headers. This is in addition
to any configured headers, and may be used multiple times. to any configured headers, and may be used multiple times.
@ -202,8 +206,8 @@ CONFIGURATION
------------- -------------
You can specify extra mail header lines to be added to each message, You can specify extra mail header lines to be added to each message,
defaults for the subject prefix and file suffix, number patches when defaults for the subject prefix and file suffix, number patches when
outputting more than one patch, add "Cc:" headers, configure attachments, outputting more than one patch, add "To" or "Cc:" headers, configure
and sign off patches with configuration variables. attachments, and sign off patches with configuration variables.
------------ ------------
[format] [format]
@ -211,6 +215,7 @@ and sign off patches with configuration variables.
subjectprefix = CHANGE subjectprefix = CHANGE
suffix = .txt suffix = .txt
numbered = auto numbered = auto
to = <email>
cc = <email> cc = <email>
attach [ = mime-boundary-string ] attach [ = mime-boundary-string ]
signoff = true signoff = true

View File

@ -504,6 +504,13 @@ static int git_format_config(const char *var, const char *value, void *cb)
} }
if (!strcmp(var, "format.suffix")) if (!strcmp(var, "format.suffix"))
return git_config_string(&fmt_patch_suffix, var, value); return git_config_string(&fmt_patch_suffix, var, value);
if (!strcmp(var, "format.to")) {
if (!value)
return config_error_nonbool(var);
ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc);
extra_to[extra_to_nr++] = xstrdup(value);
return 0;
}
if (!strcmp(var, "format.cc")) { if (!strcmp(var, "format.cc")) {
if (!value) if (!value)
return config_error_nonbool(var); return config_error_nonbool(var);
@ -875,6 +882,13 @@ static int header_callback(const struct option *opt, const char *arg, int unset)
return 0; return 0;
} }
static int to_callback(const struct option *opt, const char *arg, int unset)
{
ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc);
extra_to[extra_to_nr++] = xstrdup(arg);
return 0;
}
static int cc_callback(const struct option *opt, const char *arg, int unset) static int cc_callback(const struct option *opt, const char *arg, int unset)
{ {
ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc); 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)
{ OPTION_CALLBACK, 0, "add-header", NULL, "header", { OPTION_CALLBACK, 0, "add-header", NULL, "header",
"add email header", PARSE_OPT_NONEG, "add email header", PARSE_OPT_NONEG,
header_callback }, header_callback },
{ OPTION_CALLBACK, 0, "to", NULL, "email", "add To: header",
PARSE_OPT_NONEG, to_callback },
{ OPTION_CALLBACK, 0, "cc", NULL, "email", "add Cc: header", { OPTION_CALLBACK, 0, "cc", NULL, "email", "add Cc: header",
PARSE_OPT_NONEG, cc_callback }, PARSE_OPT_NONEG, cc_callback },
OPT_STRING(0, "in-reply-to", &in_reply_to, "message-id", OPT_STRING(0, "in-reply-to", &in_reply_to, "message-id",

View File

@ -143,6 +143,20 @@ test_expect_success 'configuration headers and command line headers' '
grep "^ *S. E. Cipient <scipient@example.com>\$" patch7 grep "^ *S. E. Cipient <scipient@example.com>\$" patch7
' '
test_expect_success 'command line To: header' '
git config --unset-all format.headers &&
git format-patch --to="R. E. Cipient <rcipient@example.com>" --stdout master..side | sed -e "/^\$/q" >patch8 &&
grep "^To: R. E. Cipient <rcipient@example.com>\$" patch8
'
test_expect_success 'configuration To: header' '
git config format.to "R. E. Cipient <rcipient@example.com>" &&
git format-patch --stdout master..side | sed -e "/^\$/q" >patch9 &&
grep "^To: R. E. Cipient <rcipient@example.com>\$" patch9
'
test_expect_success 'multiple files' ' test_expect_success 'multiple files' '
rm -rf patches/ && rm -rf patches/ &&