Skip to content

Commit 1f9d282

Browse files
committed
Merge branch 'jk/maint-format-patch-p-suppress-stat' into maint
* jk/maint-format-patch-p-suppress-stat: format-patch: make "-p" suppress diffstat
2 parents 3ad1243 + 1d46f2e commit 1f9d282

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

builtin-log.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
891891
struct patch_ids ids;
892892
char *add_signoff = NULL;
893893
struct strbuf buf = STRBUF_INIT;
894+
int use_patch_format = 0;
894895
const struct option builtin_format_patch_options[] = {
895896
{ OPTION_CALLBACK, 'n', "numbered", &numbered, NULL,
896897
"use [PATCH n/m] even with a single patch",
@@ -920,6 +921,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
920921
PARSE_OPT_NOARG | PARSE_OPT_NONEG, keep_callback },
921922
OPT_BOOLEAN(0, "no-binary", &no_binary_diff,
922923
"don't output binary diffs"),
924+
OPT_BOOLEAN('p', NULL, &use_patch_format,
925+
"show patch format instead of default (patch + stat)"),
923926
OPT_BOOLEAN(0, "ignore-if-in-upstream", &ignore_if_in_upstream,
924927
"don't include a patch matching a commit upstream"),
925928
OPT_GROUP("Messaging"),
@@ -1027,8 +1030,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
10271030
if (argc > 1)
10281031
die ("unrecognized argument: %s", argv[1]);
10291032

1030-
if (!rev.diffopt.output_format
1031-
|| rev.diffopt.output_format == DIFF_FORMAT_PATCH)
1033+
if (use_patch_format)
1034+
rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
1035+
else if (!rev.diffopt.output_format ||
1036+
rev.diffopt.output_format == DIFF_FORMAT_PATCH)
10321037
rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_PATCH;
10331038

10341039
if (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff)

t/t4014-format-patch.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,27 @@ test_expect_success 'format-patch respects -U' '
455455
456456
'
457457

458+
cat > expect << EOF
459+
460+
diff --git a/file b/file
461+
index 40f36c6..2dc5c23 100644
462+
--- a/file
463+
+++ b/file
464+
@@ -14,3 +14,19 @@ C
465+
D
466+
E
467+
F
468+
+5
469+
EOF
470+
471+
test_expect_success 'format-patch -p suppresses stat' '
472+
473+
git format-patch -p -2 &&
474+
sed -e "1,/^$/d" -e "/^+5/q" < 0001-This-is-an-excessively-long-subject-line-for-a-messa.patch > output &&
475+
test_cmp expect output
476+
477+
'
478+
458479
test_expect_success 'format-patch from a subdirectory (1)' '
459480
filename=$(
460481
rm -rf sub &&

0 commit comments

Comments
 (0)