git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH v2 2/2] notes: don't indent empty lines

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Aug 30, 2021, 10:47 UTC
Message-ID
<RFC-patch-v2-2.2-4b546b83fd7-20210830T103913Z-avarab@gmail.com>
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
Previous: Ævar Arnfjörð BjarmasonNext: Eric Sunshine
Message 22 of 25 in “suppress trailing whitespace on empty "notes" lines”
  1. 0/3 suppress trailing whitespace on empty "notes" linesEric Sunshine, Aug 30, 2021
  2. 1/3 t3301: tolerate minor notes-related presentation changesEric Sunshine, Aug 30, 2021
  3. Junio C HamanoAug 30, 2021
  4. Eric SunshineAug 30, 2021
  5. 2/3 t3303/t9301: make `notes` tests less brittleEric Sunshine, Aug 30, 2021
  6. 3/3 notes: don't indent empty linesEric Sunshine, Aug 30, 2021
  7. Junio C HamanoAug 30, 2021
  8. Eric SunshineAug 30, 2021
  9. Junio C HamanoAug 30, 2021
  10. Eric SunshineAug 30, 2021
  11. Eric SunshineSep 10, 2021
  12. Eric SunshineSep 10, 2021
  13. Junio C HamanoSep 10, 2021
  14. Eric SunshineSep 10, 2021
  15. Ævar Arnfjörð BjarmasonSep 11, 2021
  16. Eric SunshineSep 11, 2021
  17. Ævar Arnfjörð BjarmasonSep 11, 2021
  18. Eric SunshineSep 12, 2021
  19. Junio C HamanoSep 12, 2021
  20. 0/2 suppress trailing whitespace on empty "notes" linesÆvar Arnfjörð Bjarmason, Aug 30, 2021
  21. 1/2 t3303/t9301: make `notes` tests less brittleÆvar Arnfjörð Bjarmason, Aug 30, 2021
  22. 2/2 notes: don't indent empty linesÆvar Arnfjörð Bjarmason, Aug 30, 2021
  23. Eric SunshineAug 30, 2021
  24. Eric SunshineAug 30, 2021
  25. Junio C HamanoAug 30, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.