@matheusbsbs / matheus-bagliano / commits / 1d46f2ea14
Fork 0

format-patch: make "-p" suppress diffstat

Once upon a time, format-patch would use its default stat plus patch format only when no diff format was given on the command line. This meant that "format-patch -p" would suppress the stat and show just the patch. Commit 68daa64 changed this to keep the stat format when we had an "implicit" patch format, like "-U5". As a side effect, this meant that an explicit patch format was now ignored (because cmd_format_patch didn't know the reason that the format was set way down in diff_opt_parse). This patch unbreaks what 68daa64 did (while still preserving what 68daa64 was trying to do), reinstating "-p" to suppress the default behavior. We do this by parsing "-p" ourselves in format-patch, and noting whether it was used explicitly. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Nov 4, 2009 at 02:19 UTC 1d46f2ea143534e46e6bfee3f34cd90b734bfe80
2 files changed +28 -2
builtin-log.c
+7 -2
@@ -891,6 +891,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
891 struct patch_ids ids;
892 char *add_signoff = NULL;
893 struct strbuf buf = STRBUF_INIT;
894 + int use_patch_format = 0;
895 const struct option builtin_format_patch_options[] = {
896 { OPTION_CALLBACK, 'n', "numbered", &numbered, NULL,
897 "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)
921 PARSE_OPT_NOARG | PARSE_OPT_NONEG, keep_callback },
922 OPT_BOOLEAN(0, "no-binary", &no_binary_diff,
923 "don't output binary diffs"),
924 + OPT_BOOLEAN('p', NULL, &use_patch_format,
925 + "show patch format instead of default (patch + stat)"),
926 OPT_BOOLEAN(0, "ignore-if-in-upstream", &ignore_if_in_upstream,
927 "don't include a patch matching a commit upstream"),
928 OPT_GROUP("Messaging"),
@@ -1027,8 +1030,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1030 if (argc > 1)
1031 die ("unrecognized argument: %s", argv[1]);
1032
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)
1037 rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_PATCH;
1038
1039 if (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff)
t/t4014-format-patch.sh
+21
@@ -455,6 +455,27 @@ test_expect_success 'format-patch respects -U' '
455
456 '
457
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 +
479 test_expect_success 'format-patch from a subdirectory (1)' '
480 filename=$(
481 rm -rf sub &&