All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Eric Sunshine" <sunshine@sunshineco.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [RFC PATCH v2 2/2] notes: don't indent empty lines
Date: Mon, 30 Aug 2021 12:47:14 +0200	[thread overview]
Message-ID: <RFC-patch-v2-2.2-4b546b83fd7-20210830T103913Z-avarab@gmail.com> (raw)
In-Reply-To: <RFC-cover-v2-0.2-00000000000-20210830T103913Z-avarab@gmail.com>

From: Eric Sunshine <sunshine@sunshineco.com>

Like other Git commands, `git notes` takes care to call `stripspace` on
the user-supplied note content, thereby ensuring that it has no trailing
whitespace, among other cleanups. However, when notes are inserted into
a patch via `git format-patch --notes`, all lines of the note are
indented unconditionally, including empty lines, which leaves trailing
whitespace on lines which previously were empty, thus negating the
normalization done earlier. Fix this shortcoming.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 notes.c          |  2 +-
 t/t3301-notes.sh | 28 ++++++++++++++--------------
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/notes.c b/notes.c
index f87dac40684..25e0a598996 100644
--- a/notes.c
+++ b/notes.c
@@ -1295,7 +1295,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
 	for (msg_p = msg; msg_p < msg + msglen; msg_p += linelen + 1) {
 		linelen = strchrnul(msg_p, '\n') - msg_p;
 
-		if (!raw)
+		if (!raw && linelen)
 			strbuf_addstr(sb, "    ");
 		strbuf_add(sb, msg_p, linelen);
 		strbuf_addch(sb, '\n');
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index d742be88402..74e5bfbc863 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -326,7 +326,7 @@ test_expect_success 'show -m notes' '
 
 		Notes:
 		${indent}spam
-		${indent}
+
 		${indent}foo
 		${indent}bar
 		${indent}baz
@@ -849,7 +849,7 @@ test_expect_success 'append to note from other note with "git notes append -C"'
 
 		Notes:
 		${indent}yet another note
-		${indent}
+
 		${indent}yet another note
 	EOF
 	note=$(git notes list HEAD^) &&
@@ -887,7 +887,7 @@ test_expect_success 'append to note from other note with "git notes append -c"'
 
 		Notes:
 		${indent}other note
-		${indent}
+
 		${indent}yet another note
 	EOF
 	note=$(git notes list HEAD) &&
@@ -928,7 +928,7 @@ test_expect_success 'copy note with "git notes copy" with default' '
 
 		Notes:
 		${indent}other note
-		${indent}
+
 		${indent}yet another note
 	EOF
 	git notes copy HEAD^ &&
@@ -950,7 +950,7 @@ test_expect_success 'prevent overwrite with "git notes copy"' '
 
 		Notes:
 		${indent}other note
-		${indent}
+
 		${indent}yet another note
 	EOF
 	git log -1 >actual &&
@@ -991,7 +991,7 @@ test_expect_success 'allow overwrite with "git notes copy -f" with default' '
 
 		Notes:
 		${indent}yet another note
-		${indent}
+
 		${indent}yet another note
 	EOF
 	git notes copy -f HEAD~2 &&
@@ -1020,7 +1020,7 @@ test_expect_success 'git notes copy --stdin' '
 
 		Notes:
 		${indent}yet another note
-		${indent}
+
 		${indent}yet another note
 
 		commit $parent
@@ -1031,7 +1031,7 @@ test_expect_success 'git notes copy --stdin' '
 
 		Notes:
 		${indent}other note
-		${indent}
+
 		${indent}yet another note
 	EOF
 	from=$(git rev-parse HEAD~3) &&
@@ -1092,7 +1092,7 @@ test_expect_success 'git notes copy --for-rewrite (enabled)' '
 
 		Notes:
 		${indent}yet another note
-		${indent}
+
 		${indent}yet another note
 
 		commit $parent
@@ -1103,7 +1103,7 @@ test_expect_success 'git notes copy --for-rewrite (enabled)' '
 
 		Notes:
 		${indent}other note
-		${indent}
+
 		${indent}yet another note
 	EOF
 	test_config notes.rewriteMode overwrite &&
@@ -1174,7 +1174,7 @@ test_expect_success 'git notes copy --for-rewrite (append)' '
 
 		Notes:
 		${indent}a fresh note
-		${indent}
+
 		${indent}another fresh note
 	EOF
 	git notes add -f -m"another fresh note" HEAD^ &&
@@ -1199,11 +1199,11 @@ test_expect_success 'git notes copy --for-rewrite (append two to one)' '
 
 		Notes:
 		${indent}a fresh note
-		${indent}
+
 		${indent}another fresh note
-		${indent}
+
 		${indent}append 1
-		${indent}
+
 		${indent}append 2
 	EOF
 	git notes add -f -m"append 1" HEAD^ &&
-- 
2.33.0.737.g0eefde7d76


  parent reply	other threads:[~2021-08-30 10:47 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-30  7:21 [PATCH 0/3] suppress trailing whitespace on empty "notes" lines Eric Sunshine
2021-08-30  7:21 ` [PATCH 1/3] t3301: tolerate minor notes-related presentation changes Eric Sunshine
2021-08-30 17:09   ` Junio C Hamano
2021-08-30 18:16     ` Eric Sunshine
2021-08-30  7:21 ` [PATCH 2/3] t3303/t9301: make `notes` tests less brittle Eric Sunshine
2021-08-30  7:21 ` [PATCH 3/3] notes: don't indent empty lines Eric Sunshine
2021-08-30 17:10   ` Junio C Hamano
2021-08-30 17:41     ` Eric Sunshine
2021-08-30 17:56       ` Junio C Hamano
2021-08-30 18:04         ` Eric Sunshine
2021-09-10  5:18           ` Eric Sunshine
2021-09-10  5:21             ` Eric Sunshine
2021-09-10 18:33             ` Junio C Hamano
2021-09-10 20:31               ` Eric Sunshine
2021-09-11  1:53                 ` Ævar Arnfjörð Bjarmason
2021-09-11  9:15                   ` Eric Sunshine
2021-09-11 10:39                     ` Ævar Arnfjörð Bjarmason
2021-09-12  5:53                       ` Eric Sunshine
2021-09-12  8:22                         ` Junio C Hamano
2021-08-30 10:47 ` [RFC PATCH v2 0/2] suppress trailing whitespace on empty "notes" lines Ævar Arnfjörð Bjarmason
2021-08-30 10:47   ` [RFC PATCH v2 1/2] t3303/t9301: make `notes` tests less brittle Ævar Arnfjörð Bjarmason
2021-08-30 10:47   ` Ævar Arnfjörð Bjarmason [this message]
2021-08-30 16:45   ` [RFC PATCH v2 0/2] suppress trailing whitespace on empty "notes" lines Eric Sunshine
2021-08-30 16:50     ` Eric Sunshine
2021-08-30 17:04   ` Junio C Hamano

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

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

  git send-email \
    --in-reply-to=RFC-patch-v2-2.2-4b546b83fd7-20210830T103913Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=sunshine@sunshineco.com \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.