format-patch: support format.mboxrd with --stdout
mboxrd is a more robust output format when used with --stdout and needs more exposure. Introducing this config knob lets users choose the more robust format for all their --stdout uses. Relying on --pretty=mboxrd and including all of pretty-formats.txt in the `git format-patch' documentation would likely be confusing to users. Furthermore, this setting is useful across multiple invocations. So introduce `format.mboxrd' as a boolean configuration knob that changes the default --pretty=email format to --pretty=mboxrd when (and only when) --stdout is in use. Signed-off-by: Eric Wong <e@80x24.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
7c2ef319c5
commit
4810946f60
@ -139,3 +139,7 @@ For example,
|
|||||||
------------
|
------------
|
||||||
+
|
+
|
||||||
will only show notes from `refs/notes/bar`.
|
will only show notes from `refs/notes/bar`.
|
||||||
|
|
||||||
|
format.mboxrd::
|
||||||
|
A boolean value which enables the robust "mboxrd" format when
|
||||||
|
`--stdout` is in use to escape "^>+From " lines.
|
||||||
|
@ -52,6 +52,7 @@ static int decoration_style;
|
|||||||
static int decoration_given;
|
static int decoration_given;
|
||||||
static int use_mailmap_config = 1;
|
static int use_mailmap_config = 1;
|
||||||
static unsigned int force_in_body_from;
|
static unsigned int force_in_body_from;
|
||||||
|
static int stdout_mboxrd;
|
||||||
static const char *fmt_patch_subject_prefix = "PATCH";
|
static const char *fmt_patch_subject_prefix = "PATCH";
|
||||||
static int fmt_patch_name_max = FORMAT_PATCH_NAME_MAX_DEFAULT;
|
static int fmt_patch_name_max = FORMAT_PATCH_NAME_MAX_DEFAULT;
|
||||||
static const char *fmt_pretty;
|
static const char *fmt_pretty;
|
||||||
@ -1077,6 +1078,10 @@ static int git_format_config(const char *var, const char *value, void *cb)
|
|||||||
cover_from_description_mode = parse_cover_from_description(value);
|
cover_from_description_mode = parse_cover_from_description(value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (!strcmp(var, "format.mboxrd")) {
|
||||||
|
stdout_mboxrd = git_config_bool(var, value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return git_log_config(var, value, cb);
|
return git_log_config(var, value, cb);
|
||||||
}
|
}
|
||||||
@ -2105,6 +2110,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
|
|||||||
rev.diffopt.close_file, "--output",
|
rev.diffopt.close_file, "--output",
|
||||||
!!output_directory, "--output-directory");
|
!!output_directory, "--output-directory");
|
||||||
|
|
||||||
|
if (use_stdout && stdout_mboxrd)
|
||||||
|
rev.commit_format = CMIT_FMT_MBOXRD;
|
||||||
|
|
||||||
if (use_stdout) {
|
if (use_stdout) {
|
||||||
setup_pager();
|
setup_pager();
|
||||||
} else if (!rev.diffopt.close_file) {
|
} else if (!rev.diffopt.close_file) {
|
||||||
|
@ -2281,7 +2281,7 @@ test_expect_success 'format-patch --attach cover-letter only is non-multipart' '
|
|||||||
test_line_count = 1 output
|
test_line_count = 1 output
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'format-patch --pretty=mboxrd' '
|
test_expect_success '-c format.mboxrd format-patch' '
|
||||||
sp=" " &&
|
sp=" " &&
|
||||||
cat >msg <<-INPUT_END &&
|
cat >msg <<-INPUT_END &&
|
||||||
mboxrd should escape the body
|
mboxrd should escape the body
|
||||||
@ -2316,7 +2316,9 @@ test_expect_success 'format-patch --pretty=mboxrd' '
|
|||||||
INPUT_END
|
INPUT_END
|
||||||
|
|
||||||
C=$(git commit-tree HEAD^^{tree} -p HEAD <msg) &&
|
C=$(git commit-tree HEAD^^{tree} -p HEAD <msg) &&
|
||||||
git format-patch --pretty=mboxrd --stdout -1 $C~1..$C >patch &&
|
git -c format.mboxrd format-patch --stdout -1 $C~1..$C >patch &&
|
||||||
|
git format-patch --pretty=mboxrd --stdout -1 $C~1..$C >compat &&
|
||||||
|
test_cmp patch compat &&
|
||||||
git grep -h --no-index -A11 \
|
git grep -h --no-index -A11 \
|
||||||
"^>From could trip up a loose mbox parser" patch >actual &&
|
"^>From could trip up a loose mbox parser" patch >actual &&
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
|
@ -1033,7 +1033,7 @@ test_expect_success 'am --patch-format=mboxrd handles mboxrd' '
|
|||||||
>From extra escape for reversibility
|
>From extra escape for reversibility
|
||||||
INPUT_END
|
INPUT_END
|
||||||
git commit -F msg &&
|
git commit -F msg &&
|
||||||
git format-patch --pretty=mboxrd --stdout -1 >mboxrd1 &&
|
git -c format.mboxrd format-patch --stdout -1 >mboxrd1 &&
|
||||||
grep "^>From could trip up a loose mbox parser" mboxrd1 &&
|
grep "^>From could trip up a loose mbox parser" mboxrd1 &&
|
||||||
git checkout -f first &&
|
git checkout -f first &&
|
||||||
git am --patch-format=mboxrd mboxrd1 &&
|
git am --patch-format=mboxrd mboxrd1 &&
|
||||||
|
Loading…
Reference in New Issue
Block a user