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

[PATCH next] git-notes: fix printing of multi-line notes

From
Tor Arne Vestbø <tavestbo@trolltech.com>
Date
Jan 13, 2009, 19:57 UTC
Message-ID
<496CF21C.2050500@trolltech.com>

The line length was read from the same position every time, causing mangled output when printing notes with multiple lines.

Also, adding new-line manually for each line ensures that we get a new-line between commits, matching git-log for commits without notes.

Signed-off-by: Tor Arne Vestbø <tavestbo@trolltech.com>
---

This approach uses a msg pointer, but I started out with just using msg + msgoffset all over the place, so if that's a preferred way to do things I'm happy to provide an alternate patch.

Also, I'm guessing this printing should go into pretty.c at some point, so you can reference the notes as part of a custom pretty format. If so, this code could be converted to use helpers such as get_one_line().

This is my first patch to Git, so sorry if I messed something up :)
notes.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/notes.c b/notes.c
index ad43a2e..bd73784 100644
--- a/notes.c
+++ b/notes.c
@@ -110,8 +110,8 @@ void get_commit_notes(const struct commit *commit, struct strbuf *sb,
 {
 	static const char *utf8 = "utf-8";
 	unsigned char *sha1;
-	char *msg;
-	unsigned long msgoffset, msglen;
+	char *msg, *msg_p;
+	unsigned long linelen, msglen;
 	enum object_type type;
 
 	if (!initialized) {
@@ -148,12 +148,13 @@ void get_commit_notes(const struct commit *commit, struct strbuf *sb,
 
 	strbuf_addstr(sb, "\nNotes:\n");
 
-	for (msgoffset = 0; msgoffset < msglen;) {
-		int linelen = strchrnul(msg, '\n') - msg;
+	for (msg_p = msg; msg_p < msg + msglen; msg_p += linelen + 1) {
+		linelen = strchrnul(msg_p, '\n') - msg_p;
 
 		strbuf_addstr(sb, "    ");
-		strbuf_add(sb, msg + msgoffset, linelen);
-		msgoffset += linelen;
+		strbuf_add(sb, msg_p, linelen);
+		strbuf_addch(sb, '\n');
 	}
+
 	free(msg);
 }
-- 
1.6.0.2.GIT
Next: Johannes Schindelin
Message 1 of 17 in “git-notes: fix printing of multi-line notes”
  1. git-notes: fix printing of multi-line notesTor Arne Vestbø, Jan 13, 2009
  2. Johannes SchindelinJan 13, 2009
  3. Junio C HamanoJan 14, 2009
  4. Johannes SchindelinJan 14, 2009
  5. git-notes: add test case for multi-line notesTor Arne Vestbø, Jan 14, 2009
  6. Johannes SchindelinJan 14, 2009
  7. git-notes: add test case for multi-line notesTor Arne Vestbø, Jan 14, 2009
  8. Jeff KingJan 14, 2009
  9. Boyd Stephen Smith Jr.Jan 14, 2009
  10. Jeff KingJan 14, 2009
  11. Johannes SixtJan 14, 2009
  12. Jeff KingJan 14, 2009
  13. Johannes SchindelinJan 14, 2009
  14. git-notes: add test case for multi-line notesTor Arne Vestbø, Jan 14, 2009
  15. Johannes SchindelinJan 14, 2009
  16. git-notes: fix printing of multi-line notesTor Arne Vestbø, Jan 16, 2009
  17. Junio C HamanoJan 18, 2009

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.