git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: git@vger.kernel.org
Cc: Eric Sunshine <sunshine@sunshineco.com>
Subject: [PATCH 3/3] notes: don't indent empty lines
Date: Mon, 30 Aug 2021 03:21:18 -0400	[thread overview]
Message-ID: <20210830072118.91921-4-sunshine@sunshineco.com> (raw)
In-Reply-To: <20210830072118.91921-1-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>
---
 notes.c                 |  2 +-
 t/t4014-format-patch.sh | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/notes.c b/notes.c
index f87dac4068..25e0a59899 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/t4014-format-patch.sh b/t/t4014-format-patch.sh
index 712d4b5ddf..7406e5fe99 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -906,6 +906,23 @@ test_expect_success 'format-patch with multiple notes refs in config' '
 	grep "this is note 2" out
 '
 
+test_expect_success 'format-patch --notes does not indent empty lines' '
+	git notes add --file=- HEAD <<-\EOF &&
+	paragraph 1
+
+	paragraph 2
+	EOF
+	test_when_finished "git notes remove HEAD" &&
+	git format-patch -1 --stdout --notes >out &&
+	sed -n "/^[ 	]*paragraph 1$/,/^[ 	]*paragraph 2$/{s/^[ 	][ 	]*/[indent]/;p;}" out >actual &&
+	cat >expect <<-\EOF &&
+	[indent]paragraph 1
+
+	[indent]paragraph 2
+	EOF
+	test_cmp expect actual
+'
+
 echo "fatal: --name-only does not make sense" >expect.name-only
 echo "fatal: --name-status does not make sense" >expect.name-status
 echo "fatal: --check does not make sense" >expect.check
-- 
2.33.0.153.gba50c8fa24


  parent reply	other threads:[~2021-08-30  7:23 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 ` Eric Sunshine [this message]
2021-08-30 17:10   ` [PATCH 3/3] notes: don't indent empty lines 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   ` [RFC PATCH v2 2/2] notes: don't indent empty lines Ævar Arnfjörð Bjarmason
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

  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=20210830072118.91921-4-sunshine@sunshineco.com \
    --to=sunshine@sunshineco.com \
    --cc=git@vger.kernel.org \
    /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).