Skip to content

Commit 430be36

Browse files
tgummerergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e1db263 commit 430be36

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

diff.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,10 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
16731673
if (ecbdata->opt->flags.dual_color_diffed_diffs)
16741674
strbuf_addstr(&msgbuf, reverse);
16751675
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);
16771680
strbuf_addstr(&msgbuf, reset);
16781681

16791682
/*

diff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ struct diff_flags {
9898
unsigned stat_with_summary;
9999
unsigned suppress_diff_headers;
100100
unsigned dual_color_diffed_diffs;
101+
unsigned suppress_hunk_header_line_count;
101102
};
102103

103104
static inline void diff_flags_or(struct diff_flags *a,

range-diff.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ int show_range_diff(const char *range1, const char *range2,
486486
opts.output_format = DIFF_FORMAT_PATCH;
487487
opts.flags.suppress_diff_headers = 1;
488488
opts.flags.dual_color_diffed_diffs = dual_color;
489+
opts.flags.suppress_hunk_header_line_count = 1;
489490
opts.output_prefix = output_prefix_cb;
490491
strbuf_addstr(&indent, " ");
491492
opts.output_prefix_data = &indent;

t/t3206-range-diff.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ test_expect_success 'changed commit' '
9999
1: 4de457d = 1: a4b3333 s/5/A/
100100
2: fccce22 = 2: f51d370 s/4/A/
101101
3: 147e64e ! 3: 0559556 s/11/B/
102-
@@ -10,7 +10,7 @@
102+
@@
103103
9
104104
10
105105
-11
@@ -109,7 +109,7 @@ test_expect_success 'changed commit' '
109109
13
110110
14
111111
4: a63e992 ! 4: d966c5c s/12/B/
112-
@@ -8,7 +8,7 @@
112+
@@
113113
@@ A
114114
9
115115
10
@@ -158,7 +158,7 @@ test_expect_success 'changed commit with sm config' '
158158
1: 4de457d = 1: a4b3333 s/5/A/
159159
2: fccce22 = 2: f51d370 s/4/A/
160160
3: 147e64e ! 3: 0559556 s/11/B/
161-
@@ -10,7 +10,7 @@
161+
@@
162162
9
163163
10
164164
-11
@@ -168,7 +168,7 @@ test_expect_success 'changed commit with sm config' '
168168
13
169169
14
170170
4: a63e992 ! 4: d966c5c s/12/B/
171-
@@ -8,7 +8,7 @@
171+
@@
172172
@@ A
173173
9
174174
10
@@ -191,7 +191,7 @@ test_expect_success 'changed message' '
191191
sed s/Z/\ /g >expected <<-EOF &&
192192
1: 4de457d = 1: f686024 s/5/A/
193193
2: fccce22 ! 2: 4ab067d s/4/A/
194-
@@ -2,6 +2,8 @@
194+
@@
195195
Z
196196
Z s/4/A/
197197
Z
@@ -210,7 +210,7 @@ test_expect_success 'dual-coloring' '
210210
sed -e "s|^:||" >expect <<-\EOF &&
211211
:<YELLOW>1: a4b3333 = 1: f686024 s/5/A/<RESET>
212212
:<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>
214214
: <RESET>
215215
: s/4/A/<RESET>
216216
: <RESET>
@@ -220,7 +220,7 @@ test_expect_success 'dual-coloring' '
220220
: --- a/file<RESET>
221221
: +++ b/file<RESET>
222222
:<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>
224224
: 9<RESET>
225225
: 10<RESET>
226226
: <RED> -11<RESET>
@@ -230,7 +230,7 @@ test_expect_success 'dual-coloring' '
230230
: 13<RESET>
231231
: 14<RESET>
232232
:<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>
234234
: <CYAN> @@ A<RESET>
235235
: 9<RESET>
236236
: 10<RESET>

0 commit comments

Comments
 (0)