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>
This commit is contained in:
Thomas Gummerer 2019-07-11 17:08:51 +01:00 коммит произвёл Junio C Hamano
Родитель 444e0969ba
Коммит 499352c2ad
2 изменённых файлов: 28 добавлений и 22 удалений

Просмотреть файл

@ -139,8 +139,10 @@ static int read_patches(const char *range, struct string_list *list)
strbuf_addstr(&buf, " ##"); strbuf_addstr(&buf, " ##");
} else if (in_header) { } else if (in_header) {
if (starts_with(line, "Author: ")) { if (starts_with(line, "Author: ")) {
strbuf_addstr(&buf, " ## Metadata ##\n");
strbuf_addstr(&buf, line); strbuf_addstr(&buf, line);
strbuf_addstr(&buf, "\n\n"); strbuf_addstr(&buf, "\n\n");
strbuf_addstr(&buf, " ## Commit message ##\n");
} else if (starts_with(line, " ")) { } else if (starts_with(line, " ")) {
p = line + len - 2; p = line + len - 2;
while (isspace(*p) && p >= line) while (isspace(*p) && p >= line)
@ -402,8 +404,9 @@ static void output_pair_header(struct diff_options *diffopt,
fwrite(buf->buf, buf->len, 1, diffopt->file); fwrite(buf->buf, buf->len, 1, diffopt->file);
} }
static struct userdiff_driver no_func_name = { static struct userdiff_driver section_headers = {
.funcname = { "$^", 0 } .funcname = { "^ ## (.*) ##$\n"
"^.?@@ (.*)$", REG_EXTENDED }
}; };
static struct diff_filespec *get_filespec(const char *name, const char *p) 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)
spec->size = strlen(p); spec->size = strlen(p);
spec->should_munmap = 0; spec->should_munmap = 0;
spec->is_stdin = 1; spec->is_stdin = 1;
spec->driver = &no_func_name; spec->driver = &section_headers;
return spec; return spec;
} }

Просмотреть файл

@ -99,7 +99,7 @@ test_expect_success 'changed commit' '
1: 4de457d = 1: a4b3333 s/5/A/ 1: 4de457d = 1: a4b3333 s/5/A/
2: fccce22 = 2: f51d370 s/4/A/ 2: fccce22 = 2: f51d370 s/4/A/
3: 147e64e ! 3: 0559556 s/11/B/ 3: 147e64e ! 3: 0559556 s/11/B/
@@ @@ file: A
9 9
10 10
-11 -11
@ -109,7 +109,7 @@ test_expect_success 'changed commit' '
13 13
14 14
4: a63e992 ! 4: d966c5c s/12/B/ 4: a63e992 ! 4: d966c5c s/12/B/
@@ @@ file
@@ file: A @@ file: A
9 9
10 10
@ -158,7 +158,7 @@ test_expect_success 'changed commit with sm config' '
1: 4de457d = 1: a4b3333 s/5/A/ 1: 4de457d = 1: a4b3333 s/5/A/
2: fccce22 = 2: f51d370 s/4/A/ 2: fccce22 = 2: f51d370 s/4/A/
3: 147e64e ! 3: 0559556 s/11/B/ 3: 147e64e ! 3: 0559556 s/11/B/
@@ @@ file: A
9 9
10 10
-11 -11
@ -168,7 +168,7 @@ test_expect_success 'changed commit with sm config' '
13 13
14 14
4: a63e992 ! 4: d966c5c s/12/B/ 4: a63e992 ! 4: d966c5c s/12/B/
@@ @@ file
@@ file: A @@ file: A
9 9
10 10
@ -186,9 +186,10 @@ test_expect_success 'renamed file' '
sed s/Z/\ /g >expected <<-EOF && sed s/Z/\ /g >expected <<-EOF &&
1: 4de457d = 1: f258d75 s/5/A/ 1: 4de457d = 1: f258d75 s/5/A/
2: fccce22 ! 2: 017b62d s/4/A/ 2: fccce22 ! 2: 017b62d s/4/A/
@@ @@ Metadata
ZAuthor: Thomas Rast <trast@inf.ethz.ch> ZAuthor: Thomas Rast <trast@inf.ethz.ch>
Z Z
Z ## Commit message ##
- s/4/A/ - s/4/A/
+ s/4/A/ + rename file + s/4/A/ + rename file
Z Z
@ -198,8 +199,8 @@ test_expect_success 'renamed file' '
Z 1 Z 1
Z 2 Z 2
3: 147e64e ! 3: 3ce7af6 s/11/B/ 3: 147e64e ! 3: 3ce7af6 s/11/B/
@@ @@ Metadata
Z Z ## Commit message ##
Z s/11/B/ Z s/11/B/
Z Z
- ## file ## - ## file ##
@ -210,8 +211,8 @@ test_expect_success 'renamed file' '
Z 9 Z 9
Z 10 Z 10
4: a63e992 ! 4: 1e6226b s/12/B/ 4: a63e992 ! 4: 1e6226b s/12/B/
@@ @@ Metadata
Z Z ## Commit message ##
Z s/12/B/ Z s/12/B/
Z Z
- ## file ## - ## file ##
@ -230,30 +231,32 @@ test_expect_success 'file added and later removed' '
sed s/Z/\ /g >expected <<-EOF && sed s/Z/\ /g >expected <<-EOF &&
1: 4de457d = 1: 096b1ba s/5/A/ 1: 4de457d = 1: 096b1ba s/5/A/
2: fccce22 ! 2: d92e698 s/4/A/ 2: fccce22 ! 2: d92e698 s/4/A/
@@ @@ Metadata
ZAuthor: Thomas Rast <trast@inf.ethz.ch> ZAuthor: Thomas Rast <trast@inf.ethz.ch>
Z Z
Z ## Commit message ##
- s/4/A/ - s/4/A/
+ s/4/A/ + new-file + s/4/A/ + new-file
Z Z
Z ## file ## Z ## file ##
Z@@ Z@@
@@ @@ file
Z A Z A
Z 6 Z 6
Z 7 Z 7
+ +
+ ## new-file (new) ## + ## new-file (new) ##
3: 147e64e ! 3: 9a1db4d s/11/B/ 3: 147e64e ! 3: 9a1db4d s/11/B/
@@ @@ Metadata
ZAuthor: Thomas Rast <trast@inf.ethz.ch> ZAuthor: Thomas Rast <trast@inf.ethz.ch>
Z Z
Z ## Commit message ##
- s/11/B/ - s/11/B/
+ s/11/B/ + remove file + s/11/B/ + remove file
Z Z
Z ## file ## Z ## file ##
Z@@ file: A Z@@ file: A
@@ @@ file: A
Z 12 Z 12
Z 13 Z 13
Z 14 Z 14
@ -274,8 +277,8 @@ test_expect_success 'changed message' '
sed s/Z/\ /g >expected <<-EOF && sed s/Z/\ /g >expected <<-EOF &&
1: 4de457d = 1: f686024 s/5/A/ 1: 4de457d = 1: f686024 s/5/A/
2: fccce22 ! 2: 4ab067d s/4/A/ 2: fccce22 ! 2: 4ab067d s/4/A/
@@ @@ Metadata
Z Z ## Commit message ##
Z s/4/A/ Z s/4/A/
Z Z
+ Also a silly comment here! + Also a silly comment here!
@ -293,8 +296,8 @@ test_expect_success 'dual-coloring' '
sed -e "s|^:||" >expect <<-\EOF && sed -e "s|^:||" >expect <<-\EOF &&
:<YELLOW>1: a4b3333 = 1: f686024 s/5/A/<RESET> :<YELLOW>1: a4b3333 = 1: f686024 s/5/A/<RESET>
:<RED>2: f51d370 <RESET><YELLOW>!<RESET><GREEN> 2: 4ab067d<RESET><YELLOW> s/4/A/<RESET> :<RED>2: f51d370 <RESET><YELLOW>!<RESET><GREEN> 2: 4ab067d<RESET><YELLOW> s/4/A/<RESET>
: <REVERSE><CYAN>@@<RESET> : <REVERSE><CYAN>@@<RESET> <RESET>Metadata<RESET>
: <RESET> : ## Commit message ##<RESET>
: s/4/A/<RESET> : s/4/A/<RESET>
: <RESET> : <RESET>
: <REVERSE><GREEN>+<RESET><BOLD> Also a silly comment here!<RESET> : <REVERSE><GREEN>+<RESET><BOLD> Also a silly comment here!<RESET>
@ -303,7 +306,7 @@ test_expect_success 'dual-coloring' '
: <CYAN> @@<RESET> : <CYAN> @@<RESET>
: 1<RESET> : 1<RESET>
:<RED>3: 0559556 <RESET><YELLOW>!<RESET><GREEN> 3: b9cb956<RESET><YELLOW> s/11/B/<RESET> :<RED>3: 0559556 <RESET><YELLOW>!<RESET><GREEN> 3: b9cb956<RESET><YELLOW> s/11/B/<RESET>
: <REVERSE><CYAN>@@<RESET> : <REVERSE><CYAN>@@<RESET> <RESET>file: A<RESET>
: 9<RESET> : 9<RESET>
: 10<RESET> : 10<RESET>
: <RED> -11<RESET> : <RED> -11<RESET>
@ -313,7 +316,7 @@ test_expect_success 'dual-coloring' '
: 13<RESET> : 13<RESET>
: 14<RESET> : 14<RESET>
:<RED>4: d966c5c <RESET><YELLOW>!<RESET><GREEN> 4: 8add5f1<RESET><YELLOW> s/12/B/<RESET> :<RED>4: d966c5c <RESET><YELLOW>!<RESET><GREEN> 4: 8add5f1<RESET><YELLOW> s/12/B/<RESET>
: <REVERSE><CYAN>@@<RESET> : <REVERSE><CYAN>@@<RESET> <RESET>file<RESET>
: <CYAN> @@ file: A<RESET> : <CYAN> @@ file: A<RESET>
: 9<RESET> : 9<RESET>
: 10<RESET> : 10<RESET>