git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] format-patch: don't include --stat with --range-diff output

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Nov 22, 2018, 21:12 UTC
Message-ID
<20181122211248.24546-3-avarab@gmail.com>
In-Reply-To
<CAPig+cSzyT5N5=YeX+VgRq1t0VbWqXLHSB=g=V=O-nLdCWrE9g@mail.gmail.com>

Fix a regression introduced in my a48e12ef7a ("range-diff: make diff option behavior (e.g. --stat) consistent", 2018-11-13). Since the format-patch setup code implicitly sets --stat --summary by default, we started emitting the --stat output in the cover letter's range-diff.

As noted in df569c3f31 ("range-diff doc: add a section about output stability", 2018-11-09) the --stat output is currently rather useless, and just adds noise.

Perhaps we should detect if --stat or --summary were implicitly passed to format-patch, and then pass them along, but I think fixing it this way is fine. If our --stat output ever becomes useful in range-diff we can revisit this.

There's still cases like e.g. --numstat triggering rather useless range-diff output, but I think it's OK to just handle the default case. Users are unlikely to produce a formatted patch with the likes of --numstat, or indeed any other custom diff option except -U<n> or maybe -W. If they need weirder combinations of options they can always manually produce the range-diff.

This whole situation comes about because we're assuming that when the user passes along e.g. -U10 that they want that some 10-line context for the range-diff as for the patches themselves. As noted in [1] I think it's worth re-visiting this and making -U10 just apply to the patches, and e.g. --range-diff-U10 to the range-diff. But that's left as a topic for another series less close to a rc2.

1. https://public-inbox.org/git/87d0ri7gbs.fsf@evledraar.gmail.com/
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/log.c         |  7 ++++++-
 t/t3206-range-diff.sh | 12 ------------
 2 files changed, 6 insertions(+), 13 deletions(-)
diff --git a/builtin/log.c b/builtin/log.c
index 0fe6f9ba1e..7cd2db0be9 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1094,9 +1094,13 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
 	}
 
 	if (rev->rdiff1) {
+		struct diff_options opts;
+		memcpy(&opts, &rev->diffopt, sizeof(opts));
+		opts.output_format &= ~(DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY);
+
 		fprintf_ln(rev->diffopt.file, "%s", rev->rdiff_title);
 		show_range_diff(rev->rdiff1, rev->rdiff2,
-				rev->creation_factor, 1, &rev->diffopt);
+				rev->creation_factor, 1, &opts);
 	}
 }
 
@@ -1697,6 +1701,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	if (!use_patch_format &&
 		(!rev.diffopt.output_format ||
 		 rev.diffopt.output_format == DIFF_FORMAT_PATCH))
+		/* Needs to be mirrored in show_range_diff() invocation */
 		rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY;
 	if (!rev.diffopt.stat_width)
 		rev.diffopt.stat_width = MAIL_DEFAULT_WRAP;
diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh
index 0235c038be..90def330bd 100755
--- a/t/t3206-range-diff.sh
+++ b/t/t3206-range-diff.sh
@@ -252,21 +252,9 @@ do
 			master..unmodified >actual.raw &&
 		sed -e "s|^:||" -e "s|:$||" >expect <<-\EOF &&
 		:1:  4de457d = 1:  35b9b25 s/5/A/
-		:     a => b | 0
-		:     1 file changed, 0 insertions(+), 0 deletions(-)
-		:    :
 		:2:  fccce22 = 2:  de345ab s/4/A/
-		:     a => b | 0
-		:     1 file changed, 0 insertions(+), 0 deletions(-)
-		:    :
 		:3:  147e64e = 3:  9af6654 s/11/B/
-		:     a => b | 0
-		:     1 file changed, 0 insertions(+), 0 deletions(-)
-		:    :
 		:4:  a63e992 = 4:  2901f77 s/12/B/
-		:     a => b | 0
-		:     1 file changed, 0 insertions(+), 0 deletions(-)
-		:    :
 		:-- :
 		EOF
 		sed -ne "/^1:/,/^--/p" <actual.raw >actual &&
-- 
2.20.0.rc0.387.gc7a69e6b6c
Previous: Ævar Arnfjörð BjarmasonNext: Junio C Hamano
Message 8 of 53 in “[ANNOUNCE] Git v2.20.0-rc1”
  1. Junio C HamanoNov 21, 2018
  2. Ævar Arnfjörð BjarmasonNov 22, 2018
  3. Eric SunshineNov 22, 2018
  4. 0/2 format-patch: pre-2.20 range-diff regression fixÆvar Arnfjörð Bjarmason, Nov 22, 2018
  5. 1/2 format-patch: add a more exhaustive --range-diff testÆvar Arnfjörð Bjarmason, Nov 22, 2018
  6. Junio C HamanoNov 24, 2018
  7. Ævar Arnfjörð BjarmasonNov 24, 2018
  8. 2/2 format-patch: don't include --stat with --range-diff outputÆvar Arnfjörð Bjarmason, Nov 22, 2018
  9. Junio C HamanoNov 24, 2018
  10. Junio C HamanoNov 24, 2018
  11. 2/2 format-patch: allow for independent diff & range-diff optionsÆvar Arnfjörð Bjarmason, Nov 28, 2018
  12. Junio C HamanoNov 29, 2018
  13. Johannes SchindelinNov 29, 2018
  14. Ævar Arnfjörð BjarmasonNov 29, 2018
  15. Johannes SchindelinNov 29, 2018
  16. Ævar Arnfjörð BjarmasonNov 29, 2018
  17. Johannes SchindelinNov 29, 2018
  18. Ævar Arnfjörð BjarmasonNov 29, 2018
  19. Johannes SchindelinNov 29, 2018
  20. Junio C HamanoNov 30, 2018
  21. format-patch: do not let its diff-options affect --range-diff (was Re: [PATCH 2/2] format-patch: allow for independent diff & range-diff options)Junio C Hamano, Nov 30, 2018
  22. Junio C HamanoNov 30, 2018
  23. Ævar Arnfjörð BjarmasonNov 30, 2018
  24. Johannes SchindelinNov 30, 2018
  25. Eric SunshineNov 30, 2018
  26. Martin ÅgrenDec 3, 2018
  27. range-diff: always pass at least minimal diff optionsMartin Ågren, Dec 3, 2018
  28. range-diff: always pass at least minimal diff optionsEric Sunshine, Dec 3, 2018
  29. Junio C HamanoDec 4, 2018
  30. Martin ÅgrenDec 4, 2018
  31. Eric SunshineNov 30, 2018
  32. 0/2 format-patch: fix root cause of recent regressionÆvar Arnfjörð Bjarmason, Nov 28, 2018
  33. 1/2 format-patch: add test for --range-diff diff outputÆvar Arnfjörð Bjarmason, Nov 28, 2018
  34. Ævar Arnfjörð BjarmasonNov 24, 2018
  35. Junio C HamanoNov 25, 2018
  36. rebase: mark the C reimplementation as an experimental opt-in feature (was Re: [ANNOUNCE] Git v2.20.0-rc1)Junio C Hamano, Nov 26, 2018
  37. Jonathan NiederNov 28, 2018
  38. Johannes SchindelinNov 28, 2018
  39. Ævar Arnfjörð BjarmasonNov 28, 2018
  40. Junio C HamanoNov 29, 2018
  41. Johannes SchindelinNov 29, 2018
  42. Ian JacksonNov 29, 2018
  43. Johannes SchindelinNov 29, 2018
  44. Ian JacksonNov 29, 2018
  45. Johannes SchindelinNov 29, 2018
  46. Ian JacksonNov 29, 2018
  47. Johannes SchindelinNov 26, 2018
  48. Johannes SchindelinNov 26, 2018
  49. Junio C HamanoNov 28, 2018
  50. Johannes SchindelinNov 28, 2018
  51. Junio C HamanoNov 26, 2018
  52. Elijah NewrenNov 26, 2018
  53. Junio C HamanoNov 27, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.