range-diff: don't remove funcname from inner diff

When postprocessing the inner diff in range-diff, we currently replace the whole hunk header line with just "@@". This matches how 'git tbdiff' used to handle hunk headers as well. Most likely this is being done because line numbers in the hunk header are not relevant without other changes. They can for example easily change if a range is rebased, and lines are added/removed before a change that we actually care about in our ranges. However it can still be useful to have the function name that 'git diff' extracts as additional context for the change. Note that it is not guaranteed that the hunk header actually shows up in the range-diff, and this change only aims to improve the case where a hunk header would already be included in the final output. 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 e1db26308413f5da2cef2c9c3869257d1ed6336b
2 files changed +7 -6
range-diff.c
+4 -3
@@ -119,9 +119,10 @@ static int read_patches(const char *range, struct string_list *list)
119 strbuf_addch(&buf, '\n');
120 }
121 continue;
122 - } else if (starts_with(line, "@@ "))
123 - strbuf_addstr(&buf, "@@");
124 - else if (!line[0] || starts_with(line, "index "))
122 + } else if (skip_prefix(line, "@@ ", &p)) {
123 + p = strstr(p, "@@");
124 + strbuf_addstr(&buf, p ? p : "@@");
125 + } else if (!line[0] || starts_with(line, "index "))
126 /*
127 * A completely blank (not ' \n', which is context)
128 * line is not valid in a diff. We skip it
t/t3206-range-diff.sh
+3 -3
@@ -110,7 +110,7 @@ test_expect_success 'changed commit' '
110 14
111 4: a63e992 ! 4: d966c5c s/12/B/
112 @@ -8,7 +8,7 @@
113 - @@
113 + @@ A
114 9
115 10
116 - B
@@ -169,7 +169,7 @@ test_expect_success 'changed commit with sm config' '
169 14
170 4: a63e992 ! 4: d966c5c s/12/B/
171 @@ -8,7 +8,7 @@
172 - @@
172 + @@ A
173 9
174 10
175 - B
@@ -231,7 +231,7 @@ test_expect_success 'dual-coloring' '
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>
234 - : <CYAN> @@<RESET>
234 + : <CYAN> @@ A<RESET>
235 : 9<RESET>
236 : 10<RESET>
237 : <REVERSE><RED>-<RESET><FAINT> BB<RESET>