git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Altmanninger <aclopte@gmail.com>
To: gitster@pobox.com
Cc: git@vger.kernel.org, newren@gmail.com, peff@peff.net,
	Johannes Altmanninger <aclopte@gmail.com>
Subject: [PATCH 1/3] range-diff: move " ## filename ##" headers to the first column
Date: Tue, 17 Nov 2020 22:35:49 +0100	[thread overview]
Message-ID: <20201117213551.2539438-2-aclopte@gmail.com> (raw)
In-Reply-To: <20201117213551.2539438-1-aclopte@gmail.com>

Output of range-diff may include comparisons of metadata like commit messages
and filenames. Metadata lines look like " ## <content> ##".

When range-diff compares two matching commits, it computes a diff of two
special commit diffs. In these commit diffs, each changed file is introduced
with a " ## filename ##" line which is followed by the diff hunks with changes
to the file's contents.

The leading space makes it hard to distinguish between file metadata lines
and context lines from a diff hunk, especially when looking only at the
output of range-diff.  Drop the space prefix to facilitate that.
---
 range-diff.c          |  4 ++--
 t/t3206-range-diff.sh | 42 +++++++++++++++++++++---------------------
 2 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/range-diff.c b/range-diff.c
index 24dc435e48..72660453bd 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -136,7 +136,7 @@ static int read_patches(const char *range, struct string_list *list,
 			if (len < 0)
 				die(_("could not parse git header '%.*s'"),
 				    orig_len, line);
-			strbuf_addstr(&buf, " ## ");
+			strbuf_addstr(&buf, "## ");
 			if (patch.is_new > 0)
 				strbuf_addf(&buf, "%s (new)", patch.new_name);
 			else if (patch.is_delete > 0)
@@ -432,7 +432,7 @@ static void output_pair_header(struct diff_options *diffopt,
 }
 
 static struct userdiff_driver section_headers = {
-	.funcname = { "^ ## (.*) ##$\n"
+	.funcname = { "^ ?## (.*) ##$\n"
 		      "^.?@@ (.*)$", REG_EXTENDED }
 };
 
diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh
index 6eb344be03..f875843b5e 100755
--- a/t/t3206-range-diff.sh
+++ b/t/t3206-range-diff.sh
@@ -304,8 +304,8 @@ test_expect_success 'renamed file' '
 	    -    s/4/A/
 	    +    s/4/A/ + rename file
 	    Z
-	    - ## file ##
-	    + ## file => renamed-file ##
+	    -## file ##
+	    +## file => renamed-file ##
 	    Z@@
 	    Z 1
 	    Z 2
@@ -314,9 +314,9 @@ test_expect_success 'renamed file' '
 	    Z ## Commit message ##
 	    Z    s/11/B/
 	    Z
-	    - ## file ##
+	    -## file ##
 	    -@@ file: A
-	    + ## renamed-file ##
+	    +## renamed-file ##
 	    +@@ renamed-file: A
 	    Z 8
 	    Z 9
@@ -326,9 +326,9 @@ test_expect_success 'renamed file' '
 	    Z ## Commit message ##
 	    Z    s/12/B/
 	    Z
-	    - ## file ##
+	    -## file ##
 	    -@@ file: A
-	    + ## renamed-file ##
+	    +## renamed-file ##
 	    +@@ renamed-file: A
 	    Z 9
 	    Z 10
@@ -348,14 +348,14 @@ test_expect_success 'file with mode only change' '
 	    -    s/4/A/
 	    +    s/4/A/ + add other-file
 	    Z
-	    Z ## file ##
+	    Z## file ##
 	    Z@@
 	    @@ file
 	    Z A
 	    Z 6
 	    Z 7
 	    +
-	    + ## other-file (new) ##
+	    +## other-file (new) ##
 	2:  $(test_oid t3) ! 2:  $(test_oid o2) s/11/B/
 	    @@ Metadata
 	    ZAuthor: Thomas Rast <trast@inf.ethz.ch>
@@ -364,14 +364,14 @@ test_expect_success 'file with mode only change' '
 	    -    s/11/B/
 	    +    s/11/B/ + mode change other-file
 	    Z
-	    Z ## file ##
+	    Z## file ##
 	    Z@@ file: A
 	    @@ file: A
 	    Z 12
 	    Z 13
 	    Z 14
 	    +
-	    + ## other-file (mode change 100644 => 100755) ##
+	    +## other-file (mode change 100644 => 100755) ##
 	3:  $(test_oid t4) = 3:  $(test_oid o3) s/12/B/
 	EOF
 	test_cmp expect actual
@@ -389,14 +389,14 @@ test_expect_success 'file added and later removed' '
 	    -    s/4/A/
 	    +    s/4/A/ + new-file
 	    Z
-	    Z ## file ##
+	    Z## file ##
 	    Z@@
 	    @@ file
 	    Z A
 	    Z 6
 	    Z 7
 	    +
-	    + ## new-file (new) ##
+	    +## new-file (new) ##
 	3:  $(test_oid t3) ! 3:  $(test_oid s3) s/11/B/
 	    @@ Metadata
 	    ZAuthor: Thomas Rast <trast@inf.ethz.ch>
@@ -405,14 +405,14 @@ test_expect_success 'file added and later removed' '
 	    -    s/11/B/
 	    +    s/11/B/ + remove file
 	    Z
-	    Z ## file ##
+	    Z## file ##
 	    Z@@ file: A
 	    @@ file: A
 	    Z 12
 	    Z 13
 	    Z 14
 	    +
-	    + ## new-file (deleted) ##
+	    +## new-file (deleted) ##
 	4:  $(test_oid t4) = 4:  $(test_oid s4) s/12/B/
 	EOF
 	test_cmp expect actual
@@ -434,7 +434,7 @@ test_expect_success 'changed message' '
 	    Z
 	    +    Also a silly comment here!
 	    +
-	    Z ## file ##
+	    Z## file ##
 	    Z@@
 	    Z 1
 	3:  $(test_oid t3) = 3:  $(test_oid m3) s/11/B/
@@ -453,7 +453,7 @@ test_expect_success 'dual-coloring' '
 	:     <RESET>
 	:    <REVERSE><GREEN>+<RESET><BOLD>    Also a silly comment here!<RESET>
 	:    <REVERSE><GREEN>+<RESET>
-	:      ## file ##<RESET>
+	:     ## file ##<RESET>
 	:    <CYAN> @@<RESET>
 	:      1<RESET>
 	:<RED>3:  $(test_oid c3) <RESET><YELLOW>!<RESET><GREEN> 3:  $(test_oid m3)<RESET><YELLOW> s/11/B/<RESET>
@@ -537,7 +537,7 @@ test_expect_success 'range-diff compares notes by default' '
 	    -    topic note
 	    +    unmodified note
 	    Z
-	    Z ## file ##
+	    Z## file ##
 	    Z@@ file: A
 	EOF
 	test_cmp expect actual
@@ -584,7 +584,7 @@ test_expect_success 'range-diff with multiple --notes' '
 	    -    topic note2
 	    +    unmodified note2
 	    Z
-	    Z ## file ##
+	    Z## file ##
 	    Z@@ file: A
 	EOF
 	test_cmp expect actual
@@ -645,7 +645,7 @@ test_expect_success 'format-patch --range-diff with --notes' '
 	    -    topic note
 	    +    unmodified note
 	    Z
-	    Z ## file ##
+	    Z## file ##
 	    Z@@ file: A
 	EOF
 	sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
@@ -674,7 +674,7 @@ test_expect_success 'format-patch --range-diff with format.notes config' '
 	    -    topic note
 	    +    unmodified note
 	    Z
-	    Z ## file ##
+	    Z## file ##
 	    Z@@ file: A
 	EOF
 	sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
@@ -710,7 +710,7 @@ test_expect_success 'format-patch --range-diff with multiple notes' '
 	    -    topic note2
 	    +    unmodified note2
 	    Z
-	    Z ## file ##
+	    Z## file ##
 	    Z@@ file: A
 	EOF
 	sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
-- 
2.29.2


  reply	other threads:[~2020-11-17 21:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-05 13:34 range-diff should suppress context-only changes? Jeff King
2020-11-05 20:55 ` Junio C Hamano
2020-11-17 21:35   ` Johannes Altmanninger
2020-11-17 21:35     ` Johannes Altmanninger [this message]
2020-11-17 21:35     ` [PATCH 2/3] range-diff: ignore context-only changes Johannes Altmanninger
2020-11-17 22:56       ` Eric Sunshine
2020-11-17 21:35     ` [PATCH 3/3] range-diff: only compute patch diff when patches are different Johannes Altmanninger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201117213551.2539438-2-aclopte@gmail.com \
    --to=aclopte@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=newren@gmail.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).