range-diff: suppress line count in outer diff

The line count in the outer diff's hunk headers of a range diff is not all that interesting. It merely shows how far along the inner diff are on both sides. That number is of no use for human readers, and range-diffs are not meant to be machine readable. In a subsequent commit we're going to add some more contextual information such as the filename corresponding to the diff to the hunk headers. Remove the unnecessary information, and just keep the "@@" to indicate that a new hunk of the outer diff is starting. Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Gummerer committed Jul 11, 2019 at 17:08 UTC 430be36eb53b042c447201c778b5398df887022f
4 files changed +14 -9
diff.c
+4 -1
@@ -1673,7 +1673,10 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
1673 if (ecbdata->opt->flags.dual_color_diffed_diffs)
1674 strbuf_addstr(&msgbuf, reverse);
1675 strbuf_addstr(&msgbuf, frag);
1676 - strbuf_add(&msgbuf, line, ep - line);
1676 + if (ecbdata->opt->flags.suppress_hunk_header_line_count)
1677 + strbuf_add(&msgbuf, atat, sizeof(atat));
1678 + else
1679 + strbuf_add(&msgbuf, line, ep - line);
1680 strbuf_addstr(&msgbuf, reset);
1681
1682 /*
diff.h
+1
@@ -98,6 +98,7 @@ struct diff_flags {
98 unsigned stat_with_summary;
99 unsigned suppress_diff_headers;
100 unsigned dual_color_diffed_diffs;
101 + unsigned suppress_hunk_header_line_count;
102 };
103
104 static inline void diff_flags_or(struct diff_flags *a,
range-diff.c
+1
@@ -486,6 +486,7 @@ int show_range_diff(const char *range1, const char *range2,
486 opts.output_format = DIFF_FORMAT_PATCH;
487 opts.flags.suppress_diff_headers = 1;
488 opts.flags.dual_color_diffed_diffs = dual_color;
489 + opts.flags.suppress_hunk_header_line_count = 1;
490 opts.output_prefix = output_prefix_cb;
491 strbuf_addstr(&indent, " ");
492 opts.output_prefix_data = &indent;
t/t3206-range-diff.sh
+8 -8
@@ -99,7 +99,7 @@ test_expect_success 'changed commit' '
99 1: 4de457d = 1: a4b3333 s/5/A/
100 2: fccce22 = 2: f51d370 s/4/A/
101 3: 147e64e ! 3: 0559556 s/11/B/
102 - @@ -10,7 +10,7 @@
102 + @@
103 9
104 10
105 -11
@@ -109,7 +109,7 @@ test_expect_success 'changed commit' '
109 13
110 14
111 4: a63e992 ! 4: d966c5c s/12/B/
112 - @@ -8,7 +8,7 @@
112 + @@
113 @@ A
114 9
115 10
@@ -158,7 +158,7 @@ test_expect_success 'changed commit with sm config' '
158 1: 4de457d = 1: a4b3333 s/5/A/
159 2: fccce22 = 2: f51d370 s/4/A/
160 3: 147e64e ! 3: 0559556 s/11/B/
161 - @@ -10,7 +10,7 @@
161 + @@
162 9
163 10
164 -11
@@ -168,7 +168,7 @@ test_expect_success 'changed commit with sm config' '
168 13
169 14
170 4: a63e992 ! 4: d966c5c s/12/B/
171 - @@ -8,7 +8,7 @@
171 + @@
172 @@ A
173 9
174 10
@@ -191,7 +191,7 @@ test_expect_success 'changed message' '
191 sed s/Z/\ /g >expected <<-EOF &&
192 1: 4de457d = 1: f686024 s/5/A/
193 2: fccce22 ! 2: 4ab067d s/4/A/
194 - @@ -2,6 +2,8 @@
194 + @@
195 Z
196 Z s/4/A/
197 Z
@@ -210,7 +210,7 @@ test_expect_success 'dual-coloring' '
210 sed -e "s|^:||" >expect <<-\EOF &&
211 :<YELLOW>1: a4b3333 = 1: f686024 s/5/A/<RESET>
212 :<RED>2: f51d370 <RESET><YELLOW>!<RESET><GREEN> 2: 4ab067d<RESET><YELLOW> s/4/A/<RESET>
213 - : <REVERSE><CYAN>@@ -2,6 +2,8 @@<RESET>
213 + : <REVERSE><CYAN>@@<RESET>
214 : <RESET>
215 : s/4/A/<RESET>
216 : <RESET>
@@ -220,7 +220,7 @@ test_expect_success 'dual-coloring' '
220 : --- a/file<RESET>
221 : +++ b/file<RESET>
222 :<RED>3: 0559556 <RESET><YELLOW>!<RESET><GREEN> 3: b9cb956<RESET><YELLOW> s/11/B/<RESET>
223 - : <REVERSE><CYAN>@@ -10,7 +10,7 @@<RESET>
223 + : <REVERSE><CYAN>@@<RESET>
224 : 9<RESET>
225 : 10<RESET>
226 : <RED> -11<RESET>
@@ -230,7 +230,7 @@ test_expect_success 'dual-coloring' '
230 : 13<RESET>
231 : 14<RESET>
232 :<RED>4: d966c5c <RESET><YELLOW>!<RESET><GREEN> 4: 8add5f1<RESET><YELLOW> s/12/B/<RESET>
233 - : <REVERSE><CYAN>@@ -8,7 +8,7 @@<RESET>
233 + : <REVERSE><CYAN>@@<RESET>
234 : <CYAN> @@ A<RESET>
235 : 9<RESET>
236 : 10<RESET>