Skip to content

Commit 499352c

Browse files
tgummerergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 444e096 commit 499352c

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

range-diff.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@ static int read_patches(const char *range, struct string_list *list)
139139
strbuf_addstr(&buf, " ##");
140140
} else if (in_header) {
141141
if (starts_with(line, "Author: ")) {
142+
strbuf_addstr(&buf, " ## Metadata ##\n");
142143
strbuf_addstr(&buf, line);
143144
strbuf_addstr(&buf, "\n\n");
145+
strbuf_addstr(&buf, " ## Commit message ##\n");
144146
} else if (starts_with(line, " ")) {
145147
p = line + len - 2;
146148
while (isspace(*p) && p >= line)
@@ -402,8 +404,9 @@ static void output_pair_header(struct diff_options *diffopt,
402404
fwrite(buf->buf, buf->len, 1, diffopt->file);
403405
}
404406

405-
static struct userdiff_driver no_func_name = {
406-
.funcname = { "$^", 0 }
407+
static struct userdiff_driver section_headers = {
408+
.funcname = { "^ ## (.*) ##$\n"
409+
"^.?@@ (.*)$", REG_EXTENDED }
407410
};
408411

409412
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)
415418
spec->size = strlen(p);
416419
spec->should_munmap = 0;
417420
spec->is_stdin = 1;
418-
spec->driver = &no_func_name;
421+
spec->driver = &section_headers;
419422

420423
return spec;
421424
}

t/t3206-range-diff.sh

Lines changed: 22 additions & 19 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-
@@
102+
@@ file: A
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-
@@
112+
@@ file
113113
@@ file: 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-
@@
161+
@@ file: A
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-
@@
171+
@@ file
172172
@@ file: A
173173
9
174174
10
@@ -186,9 +186,10 @@ test_expect_success 'renamed file' '
186186
sed s/Z/\ /g >expected <<-EOF &&
187187
1: 4de457d = 1: f258d75 s/5/A/
188188
2: fccce22 ! 2: 017b62d s/4/A/
189-
@@
189+
@@ Metadata
190190
ZAuthor: Thomas Rast <[email protected]>
191191
Z
192+
Z ## Commit message ##
192193
- s/4/A/
193194
+ s/4/A/ + rename file
194195
Z
@@ -198,8 +199,8 @@ test_expect_success 'renamed file' '
198199
Z 1
199200
Z 2
200201
3: 147e64e ! 3: 3ce7af6 s/11/B/
201-
@@
202-
Z
202+
@@ Metadata
203+
Z ## Commit message ##
203204
Z s/11/B/
204205
Z
205206
- ## file ##
@@ -210,8 +211,8 @@ test_expect_success 'renamed file' '
210211
Z 9
211212
Z 10
212213
4: a63e992 ! 4: 1e6226b s/12/B/
213-
@@
214-
Z
214+
@@ Metadata
215+
Z ## Commit message ##
215216
Z s/12/B/
216217
Z
217218
- ## file ##
@@ -230,30 +231,32 @@ test_expect_success 'file added and later removed' '
230231
sed s/Z/\ /g >expected <<-EOF &&
231232
1: 4de457d = 1: 096b1ba s/5/A/
232233
2: fccce22 ! 2: d92e698 s/4/A/
233-
@@
234+
@@ Metadata
234235
ZAuthor: Thomas Rast <[email protected]>
235236
Z
237+
Z ## Commit message ##
236238
- s/4/A/
237239
+ s/4/A/ + new-file
238240
Z
239241
Z ## file ##
240242
Z@@
241-
@@
243+
@@ file
242244
Z A
243245
Z 6
244246
Z 7
245247
+
246248
+ ## new-file (new) ##
247249
3: 147e64e ! 3: 9a1db4d s/11/B/
248-
@@
250+
@@ Metadata
249251
ZAuthor: Thomas Rast <[email protected]>
250252
Z
253+
Z ## Commit message ##
251254
- s/11/B/
252255
+ s/11/B/ + remove file
253256
Z
254257
Z ## file ##
255258
Z@@ file: A
256-
@@
259+
@@ file: A
257260
Z 12
258261
Z 13
259262
Z 14
@@ -274,8 +277,8 @@ test_expect_success 'changed message' '
274277
sed s/Z/\ /g >expected <<-EOF &&
275278
1: 4de457d = 1: f686024 s/5/A/
276279
2: fccce22 ! 2: 4ab067d s/4/A/
277-
@@
278-
Z
280+
@@ Metadata
281+
Z ## Commit message ##
279282
Z s/4/A/
280283
Z
281284
+ Also a silly comment here!
@@ -293,8 +296,8 @@ test_expect_success 'dual-coloring' '
293296
sed -e "s|^:||" >expect <<-\EOF &&
294297
:<YELLOW>1: a4b3333 = 1: f686024 s/5/A/<RESET>
295298
:<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>
298301
: s/4/A/<RESET>
299302
: <RESET>
300303
: <REVERSE><GREEN>+<RESET><BOLD> Also a silly comment here!<RESET>
@@ -303,7 +306,7 @@ test_expect_success 'dual-coloring' '
303306
: <CYAN> @@<RESET>
304307
: 1<RESET>
305308
:<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>
307310
: 9<RESET>
308311
: 10<RESET>
309312
: <RED> -11<RESET>
@@ -313,7 +316,7 @@ test_expect_success 'dual-coloring' '
313316
: 13<RESET>
314317
: 14<RESET>
315318
:<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>
317320
: <CYAN> @@ file: A<RESET>
318321
: 9<RESET>
319322
: 10<RESET>

0 commit comments

Comments
 (0)