Skip to content

Commit 34bc1b1

Browse files
committed
format-patch: allow forcing the use of in-body From: header
Users may be authoring and committing their commits under the same e-mail address they use to send their patches from, in which case they shouldn't need to use the in-body From: line in their outgoing e-mails. At the receiving end, "git am" will use the address on the "From:" header of the incoming e-mail and all should be well. Some mailing lists, however, mangle the From: address from what the original sender had; in such a situation, the user may want to add the in-body "From:" header even for their own patches. "git format-patch --[no-]force-in-body-from" was invented for such users. Signed-off-by: Junio C Hamano <[email protected]>
1 parent b84d013 commit 34bc1b1

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

Documentation/git-format-patch.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ header). Note also that `git send-email` already handles this
275275
transformation for you, and this option should not be used if you are
276276
feeding the result to `git send-email`.
277277

278+
--[no-]force-in-body-from::
279+
With the e-mail sender specified via the `--from` option, by
280+
default, an in-body "From:" to identify the real author of
281+
the commit is added at the top of the commit log message if
282+
the sender is different from the author. With this option,
283+
the in-body "From:" is added even when the sender and the
284+
author have the same name and address, which may help if the
285+
mailing list software mangles the sender's identity.
286+
278287
--add-header=<header>::
279288
Add an arbitrary header to the email headers. This is in addition
280289
to any configured headers, and may be used multiple times.

builtin/log.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static int default_encode_email_headers = 1;
5252
static int decoration_style;
5353
static int decoration_given;
5454
static int use_mailmap_config = 1;
55+
static unsigned int force_in_body_from;
5556
static const char *fmt_patch_subject_prefix = "PATCH";
5657
static int fmt_patch_name_max = FORMAT_PATCH_NAME_MAX_DEFAULT;
5758
static const char *fmt_pretty;
@@ -1897,6 +1898,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
18971898
N_("show changes against <refspec> in cover letter or single patch")),
18981899
OPT_INTEGER(0, "creation-factor", &creation_factor,
18991900
N_("percentage by which creation is weighted")),
1901+
OPT_BOOL(0, "force-in-body-from", &force_in_body_from,
1902+
N_("show in-body From: even if identical to the e-mail header")),
19001903
OPT_END()
19011904
};
19021905

@@ -1940,6 +1943,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
19401943
PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN |
19411944
PARSE_OPT_KEEP_DASHDASH);
19421945

1946+
rev.force_in_body_from = force_in_body_from;
1947+
19431948
/* Make sure "0000-$sub.patch" gives non-negative length for $sub */
19441949
if (fmt_patch_name_max <= strlen("0000-") + strlen(fmt_patch_suffix))
19451950
fmt_patch_name_max = strlen("0000-") + strlen(fmt_patch_suffix);

pretty.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ static void append_line_with_color(struct strbuf *sb, struct grep_opt *opt,
480480
static int use_in_body_from(const struct pretty_print_context *pp,
481481
const struct ident_split *ident)
482482
{
483+
if (pp->rev && pp->rev->force_in_body_from)
484+
return 1;
483485
if (ident_cmp(pp->from_ident, ident))
484486
return 1;
485487
return 0;

revision.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ struct rev_info {
221221
missing_newline:1,
222222
date_mode_explicit:1,
223223
preserve_subject:1,
224+
force_in_body_from:1,
224225
encode_email_headers:1,
225226
include_header:1;
226227
unsigned int disable_stdin:1;

t/t4014-format-patch.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,19 @@ test_expect_success '--from omits redundant in-body header' '
14001400
test_cmp expect patch.head
14011401
'
14021402

1403+
test_expect_success 'with --force-in-body-from, redundant in-body from is kept' '
1404+
git format-patch --force-in-body-from \
1405+
-1 --stdout --from="A U Thor <[email protected]>" >patch &&
1406+
cat >expect <<-\EOF &&
1407+
From: A U Thor <[email protected]>
1408+
1409+
From: A U Thor <[email protected]>
1410+
1411+
EOF
1412+
sed -ne "/^From:/p; /^$/p; /^---$/q" patch >patch.head &&
1413+
test_cmp expect patch.head
1414+
'
1415+
14031416
test_expect_success 'in-body headers trigger content encoding' '
14041417
test_env GIT_AUTHOR_NAME="éxötìc" test_commit exotic &&
14051418
test_when_finished "git reset --hard HEAD^" &&

0 commit comments

Comments
 (0)