range-diff: suppress line count in outer diff
authorThomas Gummerer <t.gummerer@gmail.com>
Thu, 11 Jul 2019 16:08:48 +0000 (17:08 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 11 Jul 2019 21:29:27 +0000 (14:29 -0700)
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 <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff.c
diff.h
range-diff.c
t/t3206-range-diff.sh
diff --git a/diff.c b/diff.c
index 1ee04e321b1b5cc4e3f6bde37f49b7d3c0694aa6..41469930102ff3f807576384a77be59bc26a8613 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1673,7 +1673,10 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
        if (ecbdata->opt->flags.dual_color_diffed_diffs)
                strbuf_addstr(&msgbuf, reverse);
        strbuf_addstr(&msgbuf, frag);
-       strbuf_add(&msgbuf, line, ep - line);
+       if (ecbdata->opt->flags.suppress_hunk_header_line_count)
+               strbuf_add(&msgbuf, atat, sizeof(atat));
+       else
+               strbuf_add(&msgbuf, line, ep - line);
        strbuf_addstr(&msgbuf, reset);
 
        /*
diff --git a/diff.h b/diff.h
index b680b377b2f5871ecb3a27856f8d15fe2b1c8621..c2c30568101d4733d421a8e1742568bde38c7167 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -98,6 +98,7 @@ struct diff_flags {
        unsigned stat_with_summary;
        unsigned suppress_diff_headers;
        unsigned dual_color_diffed_diffs;
+       unsigned suppress_hunk_header_line_count;
 };
 
 static inline void diff_flags_or(struct diff_flags *a,
index a5202d8b6c7eb0b776e68e33525c3f77348a5712..f4a90b33b84bee5681d45f9300c87f5f5841bbe6 100644 (file)
@@ -486,6 +486,7 @@ int show_range_diff(const char *range1, const char *range2,
                        opts.output_format = DIFF_FORMAT_PATCH;
                opts.flags.suppress_diff_headers = 1;
                opts.flags.dual_color_diffed_diffs = dual_color;
+               opts.flags.suppress_hunk_header_line_count = 1;
                opts.output_prefix = output_prefix_cb;
                strbuf_addstr(&indent, "    ");
                opts.output_prefix_data = &indent;
index aebd4e3693a08f46b767830dd72113ae3037c6ad..9f89af71789f515dadbd16c7aa4578dbc4781dcf 100755 (executable)
@@ -99,7 +99,7 @@ test_expect_success 'changed commit' '
        1:  4de457d = 1:  a4b3333 s/5/A/
        2:  fccce22 = 2:  f51d370 s/4/A/
        3:  147e64e ! 3:  0559556 s/11/B/
-           @@ -10,7 +10,7 @@
+           @@
              9
              10
             -11
@@ -109,7 +109,7 @@ test_expect_success 'changed commit' '
              13
              14
        4:  a63e992 ! 4:  d966c5c s/12/B/
-           @@ -8,7 +8,7 @@
+           @@
             @@ A
              9
              10
@@ -158,7 +158,7 @@ test_expect_success 'changed commit with sm config' '
        1:  4de457d = 1:  a4b3333 s/5/A/
        2:  fccce22 = 2:  f51d370 s/4/A/
        3:  147e64e ! 3:  0559556 s/11/B/
-           @@ -10,7 +10,7 @@
+           @@
              9
              10
             -11
@@ -168,7 +168,7 @@ test_expect_success 'changed commit with sm config' '
              13
              14
        4:  a63e992 ! 4:  d966c5c s/12/B/
-           @@ -8,7 +8,7 @@
+           @@
             @@ A
              9
              10
@@ -191,7 +191,7 @@ test_expect_success 'changed message' '
        sed s/Z/\ /g >expected <<-EOF &&
        1:  4de457d = 1:  f686024 s/5/A/
        2:  fccce22 ! 2:  4ab067d s/4/A/
-           @@ -2,6 +2,8 @@
+           @@
            Z
            Z    s/4/A/
            Z
@@ -210,7 +210,7 @@ test_expect_success 'dual-coloring' '
        sed -e "s|^:||" >expect <<-\EOF &&
        :<YELLOW>1:  a4b3333 = 1:  f686024 s/5/A/<RESET>
        :<RED>2:  f51d370 <RESET><YELLOW>!<RESET><GREEN> 2:  4ab067d<RESET><YELLOW> s/4/A/<RESET>
-       :    <REVERSE><CYAN>@@ -2,6 +2,8 @@<RESET>
+       :    <REVERSE><CYAN>@@<RESET>
        :     <RESET>
        :         s/4/A/<RESET>
        :     <RESET>
@@ -220,7 +220,7 @@ test_expect_success 'dual-coloring' '
        :      --- a/file<RESET>
        :      +++ b/file<RESET>
        :<RED>3:  0559556 <RESET><YELLOW>!<RESET><GREEN> 3:  b9cb956<RESET><YELLOW> s/11/B/<RESET>
-       :    <REVERSE><CYAN>@@ -10,7 +10,7 @@<RESET>
+       :    <REVERSE><CYAN>@@<RESET>
        :      9<RESET>
        :      10<RESET>
        :    <RED> -11<RESET>
@@ -230,7 +230,7 @@ test_expect_success 'dual-coloring' '
        :      13<RESET>
        :      14<RESET>
        :<RED>4:  d966c5c <RESET><YELLOW>!<RESET><GREEN> 4:  8add5f1<RESET><YELLOW> s/12/B/<RESET>
-       :    <REVERSE><CYAN>@@ -8,7 +8,7 @@<RESET>
+       :    <REVERSE><CYAN>@@<RESET>
        :    <CYAN> @@ A<RESET>
        :      9<RESET>
        :      10<RESET>