range-diff: add headers to the outer hunk header

Add the section headers/hunk headers we introduced in the previous commits to the outer diff's hunk headers. This makes it easier to understand which change we are actually looking at. For example an outer hunk header might now look like: @@ Documentation/config/interactive.txt while previously it would have only been @@ which doesn't give a lot of context for the change that follows. For completeness also add section headers for the commit metadata and the commit message, although they are arguably less important. 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 499352c2adf9c038ec3469d73590b1c55b6a343b
2 files changed +28 -22
range-diff.c
+6 -3
@@ -139,8 +139,10 @@ static int read_patches(const char *range, struct string_list *list)
139 strbuf_addstr(&buf, " ##");
140 } else if (in_header) {
141 if (starts_with(line, "Author: ")) {
142 + strbuf_addstr(&buf, " ## Metadata ##\n");
143 strbuf_addstr(&buf, line);
144 strbuf_addstr(&buf, "\n\n");
145 + strbuf_addstr(&buf, " ## Commit message ##\n");
146 } else if (starts_with(line, " ")) {
147 p = line + len - 2;
148 while (isspace(*p) && p >= line)
@@ -402,8 +404,9 @@ static void output_pair_header(struct diff_options *diffopt,
404 fwrite(buf->buf, buf->len, 1, diffopt->file);
405 }
406
405 -static struct userdiff_driver no_func_name = {
406 - .funcname = { "$^", 0 }
407 +static struct userdiff_driver section_headers = {
408 + .funcname = { "^ ## (.*) ##$\n"
409 + "^.?@@ (.*)$", REG_EXTENDED }
410 };
411
412 static struct diff_filespec *get_filespec(const char *name, const char *p)
@@ -415,7 +418,7 @@ static struct diff_filespec *get_filespec(const char *name, const char *p)
418 spec->size = strlen(p);
419 spec->should_munmap = 0;
420 spec->is_stdin = 1;
418 - spec->driver = &no_func_name;
421 + spec->driver = &section_headers;
422
423 return spec;
424 }
t/t3206-range-diff.sh
+22 -19
@@ -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 - @@
102 + @@ file: A
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 - @@
112 + @@ file
113 @@ file: 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 - @@
161 + @@ file: A
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 - @@
171 + @@ file
172 @@ file: A
173 9
174 10
@@ -186,9 +186,10 @@ test_expect_success 'renamed file' '
186 sed s/Z/\ /g >expected <<-EOF &&
187 1: 4de457d = 1: f258d75 s/5/A/
188 2: fccce22 ! 2: 017b62d s/4/A/
189 - @@
189 + @@ Metadata
190 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
191 Z
192 + Z ## Commit message ##
193 - s/4/A/
194 + s/4/A/ + rename file
195 Z
@@ -198,8 +199,8 @@ test_expect_success 'renamed file' '
199 Z 1
200 Z 2
201 3: 147e64e ! 3: 3ce7af6 s/11/B/
201 - @@
202 - Z
202 + @@ Metadata
203 + Z ## Commit message ##
204 Z s/11/B/
205 Z
206 - ## file ##
@@ -210,8 +211,8 @@ test_expect_success 'renamed file' '
211 Z 9
212 Z 10
213 4: a63e992 ! 4: 1e6226b s/12/B/
213 - @@
214 - Z
214 + @@ Metadata
215 + Z ## Commit message ##
216 Z s/12/B/
217 Z
218 - ## file ##
@@ -230,30 +231,32 @@ test_expect_success 'file added and later removed' '
231 sed s/Z/\ /g >expected <<-EOF &&
232 1: 4de457d = 1: 096b1ba s/5/A/
233 2: fccce22 ! 2: d92e698 s/4/A/
233 - @@
234 + @@ Metadata
235 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
236 Z
237 + Z ## Commit message ##
238 - s/4/A/
239 + s/4/A/ + new-file
240 Z
241 Z ## file ##
242 Z@@
241 - @@
243 + @@ file
244 Z A
245 Z 6
246 Z 7
247 +
248 + ## new-file (new) ##
249 3: 147e64e ! 3: 9a1db4d s/11/B/
248 - @@
250 + @@ Metadata
251 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
252 Z
253 + Z ## Commit message ##
254 - s/11/B/
255 + s/11/B/ + remove file
256 Z
257 Z ## file ##
258 Z@@ file: A
256 - @@
259 + @@ file: A
260 Z 12
261 Z 13
262 Z 14
@@ -274,8 +277,8 @@ test_expect_success 'changed message' '
277 sed s/Z/\ /g >expected <<-EOF &&
278 1: 4de457d = 1: f686024 s/5/A/
279 2: fccce22 ! 2: 4ab067d s/4/A/
277 - @@
278 - Z
280 + @@ Metadata
281 + Z ## Commit message ##
282 Z s/4/A/
283 Z
284 + Also a silly comment here!
@@ -293,8 +296,8 @@ test_expect_success 'dual-coloring' '
296 sed -e "s|^:||" >expect <<-\EOF &&
297 :<YELLOW>1: a4b3333 = 1: f686024 s/5/A/<RESET>
298 :<RED>2: f51d370 <RESET><YELLOW>!<RESET><GREEN> 2: 4ab067d<RESET><YELLOW> s/4/A/<RESET>
296 - : <REVERSE><CYAN>@@<RESET>
297 - : <RESET>
299 + : <REVERSE><CYAN>@@<RESET> <RESET>Metadata<RESET>
300 + : ## Commit message ##<RESET>
301 : s/4/A/<RESET>
302 : <RESET>
303 : <REVERSE><GREEN>+<RESET><BOLD> Also a silly comment here!<RESET>
@@ -303,7 +306,7 @@ test_expect_success 'dual-coloring' '
306 : <CYAN> @@<RESET>
307 : 1<RESET>
308 :<RED>3: 0559556 <RESET><YELLOW>!<RESET><GREEN> 3: b9cb956<RESET><YELLOW> s/11/B/<RESET>
306 - : <REVERSE><CYAN>@@<RESET>
309 + : <REVERSE><CYAN>@@<RESET> <RESET>file: A<RESET>
310 : 9<RESET>
311 : 10<RESET>
312 : <RED> -11<RESET>
@@ -313,7 +316,7 @@ test_expect_success 'dual-coloring' '
316 : 13<RESET>
317 : 14<RESET>
318 :<RED>4: d966c5c <RESET><YELLOW>!<RESET><GREEN> 4: 8add5f1<RESET><YELLOW> s/12/B/<RESET>
316 - : <REVERSE><CYAN>@@<RESET>
319 + : <REVERSE><CYAN>@@<RESET> <RESET>file<RESET>
320 : <CYAN> @@ file: A<RESET>
321 : 9<RESET>
322 : 10<RESET>