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

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Tor Arne Vestbø
Date: Tuesday, January 13, 2009 - 12:57 pm

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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH next] git-notes: fix printing of multi-line notes, Tor Arne Vestbø, (Tue Jan 13, 12:57 pm)
Re: [PATCH next] git-notes: fix printing of multi-line notes, Johannes Schindelin, (Tue Jan 13, 3:40 pm)
Re: [PATCH next] git-notes: fix printing of multi-line notes, Junio C Hamano, (Tue Jan 13, 11:48 pm)
Re: [PATCH next] git-notes: fix printing of multi-line notes, Johannes Schindelin, (Wed Jan 14, 3:14 am)
[PATCH next] git-notes: add test case for multi-line notes, Tor Arne Vestbø, (Wed Jan 14, 7:39 am)
Re: [PATCH next] git-notes: add test case for multi-line notes, Johannes Schindelin, (Wed Jan 14, 8:34 am)
[PATCH next v2] git-notes: add test case for multi-line notes, Tor Arne Vestbø, (Wed Jan 14, 9:28 am)
Re: [PATCH next v2] git-notes: add test case for multi-lin ..., Boyd Stephen Smith Jr., (Wed Jan 14, 10:09 am)
Re: [PATCH next v2] git-notes: add test case for multi-lin ..., Johannes Schindelin, (Wed Jan 14, 11:01 am)
[PATCH next v3] git-notes: add test case for multi-line notes, Tor Arne Vestbø, (Wed Jan 14, 1:57 pm)
Re: [PATCH next v3] git-notes: add test case for multi-lin ..., Johannes Schindelin, (Wed Jan 14, 2:10 pm)
[PATCH next v4] git-notes: fix printing of multi-line notes, Tor Arne Vestbø, (Fri Jan 16, 6:06 am)