{"thread":{"id":"17152","subject":"[PATCH next] git-notes: fix printing of multi-line notes","startedAt":"2009-01-13T19:57:16Z","lastAt":"2009-01-18T21:27:34Z","messageCount":17,"participants":["Tor Arne Vestbø","Johannes Schindelin","Junio C Hamano","Jeff King","Boyd Stephen Smith Jr.","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"100303","messageId":"496CF21C.2050500@trolltech.com","threadId":"17152","inReplyTo":null,"subject":"[PATCH next] git-notes: fix printing of multi-line notes","fromName":"Tor Arne Vestbø","fromEmail":"tavestbo@trolltech.com","sentAt":"2009-01-13T19:57:16Z","receivedAt":"2009-01-13T19:57:16Z","isPatch":true,"sender":{"key":"torarnv@gmail.com","avatar":"https://gravatar.com/avatar/847af0150a5a28ad86d9db1556a48aba04e7642c6a29a5a767f8c2bdf1720321?d=mp&s=160"},"body":"The line length was read from the same position every time,\ncausing mangled output when printing notes with multiple lines.\n\nAlso, adding new-line manually for each line ensures that we\nget a new-line between commits, matching git-log for commits\nwithout notes.\n\nSigned-off-by: Tor Arne Vestbø <tavestbo@trolltech.com>\n---\n\nThis approach uses a msg pointer, but I started out with just using\nmsg + msgoffset all over the place, so if that's a preferred way\nto do things I'm happy to provide an alternate patch.\n\nAlso, I'm guessing this printing should go into pretty.c at some\npoint, so you can reference the notes as part of a custom pretty\nformat. If so, this code could be converted to use helpers such\nas get_one_line().\n\nThis is my first patch to Git, so sorry if I messed something up :)\n\nnotes.c |   13 +++++++------\n 1 files changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/notes.c b/notes.c\nindex ad43a2e..bd73784 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -110,8 +110,8 @@ void get_commit_notes(const struct commit *commit, struct strbuf *sb,\n {\n \tstatic const char *utf8 = \"utf-8\";\n \tunsigned char *sha1;\n-\tchar *msg;\n-\tunsigned long msgoffset, msglen;\n+\tchar *msg, *msg_p;\n+\tunsigned long linelen, msglen;\n \tenum object_type type;\n \n \tif (!initialized) {\n@@ -148,12 +148,13 @@ void get_commit_notes(const struct commit *commit, struct strbuf *sb,\n \n \tstrbuf_addstr(sb, \"\\nNotes:\\n\");\n \n-\tfor (msgoffset = 0; msgoffset < msglen;) {\n-\t\tint linelen = strchrnul(msg, '\\n') - msg;\n+\tfor (msg_p = msg; msg_p < msg + msglen; msg_p += linelen + 1) {\n+\t\tlinelen = strchrnul(msg_p, '\\n') - msg_p;\n \n \t\tstrbuf_addstr(sb, \"    \");\n-\t\tstrbuf_add(sb, msg + msgoffset, linelen);\n-\t\tmsgoffset += linelen;\n+\t\tstrbuf_add(sb, msg_p, linelen);\n+\t\tstrbuf_addch(sb, '\\n');\n \t}\n+\n \tfree(msg);\n }\n-- \n1.6.0.2.GIT\n"},{"id":"100333","messageId":"alpine.DEB.1.00.0901132339270.3586@pacific.mpi-cbg.de","threadId":"17152","inReplyTo":"496CF21C.2050500@trolltech.com","subject":"Re: [PATCH next] git-notes: fix printing of multi-line notes","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-01-13T22:40:14Z","receivedAt":"2009-01-13T22:40:14Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 13 Jan 2009, Tor Arne Vestbø wrote:\n\n> The line length was read from the same position every time,\n> causing mangled output when printing notes with multiple lines.\n> \n> Also, adding new-line manually for each line ensures that we\n> get a new-line between commits, matching git-log for commits\n> without notes.\n> \n> Signed-off-by: Tor Arne Vestbø <tavestbo@trolltech.com>\n> ---\n\nPatch looks good, so \n\nAcked-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nFor extra browny points, you could add a test with multi-line notes.\n\nCiao,\nDscho"},{"id":"100369","messageId":"7v3afm758u.fsf@gitster.siamese.dyndns.org","threadId":"17152","inReplyTo":"alpine.DEB.1.00.0901132339270.3586@pacific.mpi-cbg.de","subject":"Re: [PATCH next] git-notes: fix printing of multi-line notes","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-01-14T06:48:17Z","receivedAt":"2009-01-14T06:48:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> On Tue, 13 Jan 2009, Tor Arne Vestbø wrote:\n>\n>> The line length was read from the same position every time,\n>> causing mangled output when printing notes with multiple lines.\n>> \n>> Also, adding new-line manually for each line ensures that we\n>> get a new-line between commits, matching git-log for commits\n>> without notes.\n>> \n>> Signed-off-by: Tor Arne Vestbø <tavestbo@trolltech.com>\n>> ---\n>\n> Patch looks good, so \n>\n> Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n>\n> For extra browny points, you could add a test with multi-line notes.\n\nYeah, not just \"extra\", having tests is a good way to make sure a new\nfeature like this evolves healthily.\n\nTor?\n"},{"id":"100388","messageId":"alpine.DEB.1.00.0901141113250.3586@pacific.mpi-cbg.de","threadId":"17152","inReplyTo":"7v3afm758u.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH next] git-notes: fix printing of multi-line notes","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-01-14T10:14:06Z","receivedAt":"2009-01-14T10:14:06Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 13 Jan 2009, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > On Tue, 13 Jan 2009, Tor Arne Vestbø wrote:\n> >\n> >> The line length was read from the same position every time,\n> >> causing mangled output when printing notes with multiple lines.\n> >> \n> >> Also, adding new-line manually for each line ensures that we\n> >> get a new-line between commits, matching git-log for commits\n> >> without notes.\n> >> \n> >> Signed-off-by: Tor Arne Vestbø <tavestbo@trolltech.com>\n> >> ---\n> >\n> > Patch looks good, so \n> >\n> > Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> >\n> > For extra browny points, you could add a test with multi-line notes.\n> \n> Yeah, not just \"extra\", having tests is a good way to make sure a new\n> feature like this evolves healthily.\n\nOh, and of course I meant \"brownie\"...\n\nDucks,\nDscho\n"},{"id":"100412","messageId":"496DF936.3060308@trolltech.com","threadId":"17152","inReplyTo":"7v3afm758u.fsf@gitster.siamese.dyndns.org","subject":"[PATCH next] git-notes: add test case for multi-line notes","fromName":"Tor Arne Vestbø","fromEmail":"tavestbo@trolltech.com","sentAt":"2009-01-14T14:39:50Z","receivedAt":"2009-01-14T14:39:50Z","isPatch":true,"sender":{"key":"torarnv@gmail.com","avatar":"https://gravatar.com/avatar/847af0150a5a28ad86d9db1556a48aba04e7642c6a29a5a767f8c2bdf1720321?d=mp&s=160"},"body":"The tests adds a third commit with a multi-line note. The output of\ngit log -2 is then checked to see if the note lines are wrapped\ncorrectly, and that there's a line separator between the two commits.\n\nAlso, changed from using 'git diff' to test expect vs. output to use\n'test_cmp', as I had problems getting correct results using the former.\n\nSigned-off-by: Tor Arne Vestbø <tavestbo@trolltech.com>\n---\n t/t3301-notes.sh |   35 ++++++++++++++++++++++++++++++++---\n 1 files changed, 32 insertions(+), 3 deletions(-)\n\ndiff --git a/t/t3301-notes.sh b/t/t3301-notes.sh\nindex ba42c45..76bb6dd 100755\n--- a/t/t3301-notes.sh\n+++ b/t/t3301-notes.sh\n@@ -8,8 +8,8 @@ test_description='Test commit notes'\n . ./test-lib.sh\n \n cat > fake_editor.sh << \\EOF\n-echo \"$MSG\" > \"$1\"\n-echo \"$MSG\" >& 2\n+echo -e \"$MSG\" > \"$1\"\n+echo -e \"$MSG\" >& 2\n EOF\n chmod a+x fake_editor.sh\n VISUAL=./fake_editor.sh\n@@ -59,7 +59,36 @@ EOF\n test_expect_success 'show notes' '\n \t! (git cat-file commit HEAD | grep b1) &&\n \tgit log -1 > output &&\n-\tgit diff expect output\n+\ttest_cmp expect output\n+'\n+test_expect_success 'create multi-line notes (setup)' '\n+\t: > a3 &&\n+\tgit add a3 &&\n+\ttest_tick &&\n+\tgit commit -m 3rd &&\n+\tMSG=\"b3\\nc3c3c3c3\\nd3d3d3\" git notes edit\n+\n+'\n+\n+cat > expect-multiline << EOF\n+commit 1584215f1d29c65e99c6c6848626553fdd07fd75\n+Author: A U Thor <author@example.com>\n+Date:   Thu Apr 7 15:15:13 2005 -0700\n+\n+    3rd\n+\n+Notes:\n+    b3\n+    c3c3c3c3\n+    d3d3d3\n+EOF\n+\n+echo >> expect-multiline\n+cat expect >> expect-multiline\n+\n+test_expect_success 'show multi-line notes' '\n+\tgit log -2 > output &&\n+\ttest_cmp expect-multiline output\n '\n \n test_done\n-- \n1.6.0.2.GIT\n"},{"id":"100420","messageId":"alpine.DEB.1.00.0901141627440.3586@pacific.mpi-cbg.de","threadId":"17152","inReplyTo":"496DF936.3060308@trolltech.com","subject":"Re: [PATCH next] git-notes: add test case for multi-line notes","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-01-14T15:34:34Z","receivedAt":"2009-01-14T15:34:34Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 14 Jan 2009, Tor Arne Vestbø wrote:\n\n> The tests adds a third commit with a multi-line note. The output of\n> git log -2 is then checked to see if the note lines are wrapped\n> correctly, and that there's a line separator between the two commits.\n> \n> Also, changed from using 'git diff' to test expect vs. output to use\n> 'test_cmp', as I had problems getting correct results using the former.\n\nYou could skip the part that you had problems, as the test_cmp is \nobviously the correct thing to do.\n\n> diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh\n> index ba42c45..76bb6dd 100755\n> --- a/t/t3301-notes.sh\n> +++ b/t/t3301-notes.sh\n> @@ -8,8 +8,8 @@ test_description='Test commit notes'\n> . ./test-lib.sh\n> \n> cat > fake_editor.sh << \\EOF\n> -echo \"$MSG\" > \"$1\"\n> -echo \"$MSG\" >& 2\n> +echo -e \"$MSG\" > \"$1\"\n> +echo -e \"$MSG\" >& 2\n\nI seem to recall that we had plenty of fun substituting \"echo -e\" with \n\"printf\" whenever it entered the repository (... again...), as some \nplatforms -- ahem, macosx, ahem -- are a bit peculiar with such options.\n\nSo you might want to make sure no % is passed as \"$MSG\", and use printf \ninstead.\n\n> +test_expect_success 'create multi-line notes (setup)' '\n> +\t: > a3 &&\n> +\tgit add a3 &&\n> +\ttest_tick &&\n> +\tgit commit -m 3rd &&\n> +\tMSG=\"b3\\nc3c3c3c3\\nd3d3d3\" git notes edit\n> +\n> +'\n\nMinor style nit: maybe you want to have an empty line at the beginning, \ntoo...\n\n> +cat > expect-multiline << EOF\n> +commit 1584215f1d29c65e99c6c6848626553fdd07fd75\n> +Author: A U Thor <author@example.com>\n> +Date:   Thu Apr 7 15:15:13 2005 -0700\n> +\n> +    3rd\n> +\n> +Notes:\n> +    b3\n> +    c3c3c3c3\n> +    d3d3d3\n> +EOF\n> +\n> +echo >> expect-multiline\n> +cat expect >> expect-multiline\n\nYeah.  My initial reaction was: \"you could have that echo inside the cat \n<<EOF\", but this is clearer.  Except that you should make sure that \nnothing is printed (M$' echo outputs something if you pass no parameters); \nprintf \"\\n\" would be my choice.\n\nOther than that, very good: ACK.\n\nCiao,\nDscho\n"},{"id":"100432","messageId":"496E129B.3020502@trolltech.com","threadId":"17152","inReplyTo":"alpine.DEB.1.00.0901141627440.3586@pacific.mpi-cbg.de","subject":"[PATCH next v2] git-notes: add test case for multi-line notes","fromName":"Tor Arne Vestbø","fromEmail":"tavestbo@trolltech.com","sentAt":"2009-01-14T16:28:11Z","receivedAt":"2009-01-14T16:28:11Z","isPatch":true,"sender":{"key":"torarnv@gmail.com","avatar":"https://gravatar.com/avatar/847af0150a5a28ad86d9db1556a48aba04e7642c6a29a5a767f8c2bdf1720321?d=mp&s=160"},"body":"The tests adds a third commit with a multi-line note. The output of\ngit log -2 is then checked to see if the note lines are wrapped\ncorrectly, and that there's a line separator between the two commits.\n\nSigned-off-by: Tor Arne Vestbø <tavestbo@trolltech.com>\n---\n\nThanks for the feedback Johannes! Here's an updated patch. I removed\nthe blank line instead of adding another, as that's the current style\nof that file.\n\n t/t3301-notes.sh |   35 ++++++++++++++++++++++++++++++++---\n 1 files changed, 32 insertions(+), 3 deletions(-)\n\ndiff --git a/t/t3301-notes.sh b/t/t3301-notes.sh\nindex ba42c45..e260d79 100755\n--- a/t/t3301-notes.sh\n+++ b/t/t3301-notes.sh\n@@ -8,8 +8,9 @@ test_description='Test commit notes'\n . ./test-lib.sh\n \n cat > fake_editor.sh << \\EOF\n-echo \"$MSG\" > \"$1\"\n-echo \"$MSG\" >& 2\n+MSG=${MSG//%/}\n+printf \"$MSG\" > \"$1\"\n+printf \"$MSG\" >& 2\n EOF\n chmod a+x fake_editor.sh\n VISUAL=./fake_editor.sh\n@@ -59,7 +60,35 @@ EOF\n test_expect_success 'show notes' '\n \t! (git cat-file commit HEAD | grep b1) &&\n \tgit log -1 > output &&\n-\tgit diff expect output\n+\ttest_cmp expect output\n+'\n+test_expect_success 'create multi-line notes (setup)' '\n+\t: > a3 &&\n+\tgit add a3 &&\n+\ttest_tick &&\n+\tgit commit -m 3rd &&\n+\tMSG=\"b3\\nc3c3c3c3\\nd3d3d3\" git notes edit\n+'\n+\n+cat > expect-multiline << EOF\n+commit 1584215f1d29c65e99c6c6848626553fdd07fd75\n+Author: A U Thor <author@example.com>\n+Date:   Thu Apr 7 15:15:13 2005 -0700\n+\n+    3rd\n+\n+Notes:\n+    b3\n+    c3c3c3c3\n+    d3d3d3\n+EOF\n+\n+printf \"\\n\" >> expect-multiline\n+cat expect >> expect-multiline\n+\n+test_expect_success 'show multi-line notes' '\n+\tgit log -2 > output &&\n+\ttest_cmp expect-multiline output\n '\n \n test_done\n-- \n1.6.0.2.GIT\n"},{"id":"100438","messageId":"20090114165633.GC15758@coredump.intra.peff.net","threadId":"17152","inReplyTo":"496E129B.3020502@trolltech.com","subject":"Re: [PATCH next v2] git-notes: add test case for multi-line notes","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-01-14T16:56:33Z","receivedAt":"2009-01-14T16:56:33Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Jan 14, 2009 at 05:28:11PM +0100, Tor Arne Vestbø wrote:\n\n> +MSG=${MSG//%/}\n> +printf \"$MSG\" > \"$1\"\n> +printf \"$MSG\" >& 2\n\nSubstitution parameter expansion is a bash-ism, IIRC. How about just\n\n  printf %s \"$MSG\" ?\n\n-Peff\n"},{"id":"100443","messageId":"200901141109.56580.bss@iguanasuicide.net","threadId":"17152","inReplyTo":"20090114165633.GC15758@coredump.intra.peff.net","subject":"Re: [PATCH next v2] git-notes: add test case for multi-line notes","fromName":"Boyd Stephen Smith Jr.","fromEmail":"bss@iguanasuicide.net","sentAt":"2009-01-14T17:09:52Z","receivedAt":"2009-01-14T17:09:52Z","isPatch":true,"sender":{"key":"bss@iguanasuicide.net","avatar":"https://gravatar.com/avatar/84b95eeff194b816c1568b1339e63e4b229825298664a9037b9f1ec713ead1e3?d=mp&s=160"},"body":"On Wednesday 2009 January 14 10:56:33 Jeff King wrote:\n>On Wed, Jan 14, 2009 at 05:28:11PM +0100, Tor Arne Vestbø wrote:\n>> +MSG=${MSG//%/}\n>> +printf \"$MSG\" > \"$1\"\n>> +printf \"$MSG\" >& 2\n>\n>Substitution parameter expansion is a bash-ism, IIRC. How about just\n\nMSG=$(printf '%s\\n' \"$MSG\" | sed -e 's/%/%%/g')\nprintf \"$MSG\" > \"$1\"\nprintf \"$MSG\" >& 2\n\nIs my best attempt at portable and \"safe\".  It's a few extra processes though.\n\n>  printf %s \"$MSG\" ?\n\nOn my box\n$ printf '%s\\n' '\\n'\n\\n\n$\n\nHe wants '\\n' in $MSG to be expanded, and what you gave doesn't do that.\n-- \nBoyd Stephen Smith Jr.                     ,= ,-_-. =. \nbss@iguanasuicide.net                     ((_/)o o(\\_))\nICQ: 514984 YM/AIM: DaTwinkDaddy           `-'(. .)`-' \nhttp://iguanasuicide.net/                      \\_/     \n"},{"id":"100444","messageId":"20090114171315.GA16063@coredump.intra.peff.net","threadId":"17152","inReplyTo":"200901141109.56580.bss@iguanasuicide.net","subject":"Re: [PATCH next v2] git-notes: add test case for multi-line notes","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-01-14T17:13:15Z","receivedAt":"2009-01-14T17:13:15Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Jan 14, 2009 at 11:09:52AM -0600, Boyd Stephen Smith Jr. wrote:\n\n> >  printf %s \"$MSG\" ?\n> \n> On my box\n> $ printf '%s\\n' '\\n'\n> \\n\n> $\n> \n> He wants '\\n' in $MSG to be expanded, and what you gave doesn't do that.\n\nOh, sorry. That's what I get for not reading his patch carefully.\n\nIt looks like all of the input is statically included in the test\nscript. While I think it is nice to be defensive, it is probably\nsimplest to just assume there is no '%' in this case (which we can\nverify by reading the script).\n\n-Peff\n"},{"id":"100445","messageId":"496E1D77.6000307@viscovery.net","threadId":"17152","inReplyTo":"20090114165633.GC15758@coredump.intra.peff.net","subject":"Re: [PATCH next v2] git-notes: add test case for multi-line notes","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2009-01-14T17:14:31Z","receivedAt":"2009-01-14T17:14:31Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Jeff King schrieb:\n> On Wed, Jan 14, 2009 at 05:28:11PM +0100, Tor Arne Vestbø wrote:\n> \n>> +MSG=${MSG//%/}\n>> +printf \"$MSG\" > \"$1\"\n>> +printf \"$MSG\" >& 2\n> \n> Substitution parameter expansion is a bash-ism, IIRC. How about just\n> \n>   printf %s \"$MSG\" ?\n\nA the point was that $MSG contains \\n, which should be turned int LF. IMO,\nthe easiest way to achieve this is:\n\nMSG='b3\nc3c3c3c3\nd3d3d3'\n\ntest_expect_success ' ... ' '\n   ...\n   MSG=\"$MSG\" git notes edit\n'\n\nand go back to using echo in the part cited above.\n\n-- Hannes\n"},{"id":"100447","messageId":"20090114171925.GA16199@coredump.intra.peff.net","threadId":"17152","inReplyTo":"496E1D77.6000307@viscovery.net","subject":"Re: [PATCH next v2] git-notes: add test case for multi-line notes","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-01-14T17:19:25Z","receivedAt":"2009-01-14T17:19:25Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Jan 14, 2009 at 06:14:31PM +0100, Johannes Sixt wrote:\n\n> A the point was that $MSG contains \\n, which should be turned int LF. IMO,\n> the easiest way to achieve this is:\n> \n> MSG='b3\n> c3c3c3c3\n> d3d3d3'\n> \n> test_expect_success ' ... ' '\n>    ...\n>    MSG=\"$MSG\" git notes edit\n> '\n> \n> and go back to using echo in the part cited above.\n\nYes, sorry, I hadn't read his original patch carefully. I think that is\na sane solution.\n\n-Peff\n"},{"id":"100453","messageId":"alpine.DEB.1.00.0901141900490.3586@pacific.mpi-cbg.de","threadId":"17152","inReplyTo":"496E1D77.6000307@viscovery.net","subject":"Re: [PATCH next v2] git-notes: add test case for multi-line notes","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-01-14T18:01:14Z","receivedAt":"2009-01-14T18:01:14Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 14 Jan 2009, Johannes Sixt wrote:\n\n> Jeff King schrieb:\n> > On Wed, Jan 14, 2009 at 05:28:11PM +0100, Tor Arne Vestbø wrote:\n> > \n> >> +MSG=${MSG//%/}\n> >> +printf \"$MSG\" > \"$1\"\n> >> +printf \"$MSG\" >& 2\n> > \n> > Substitution parameter expansion is a bash-ism, IIRC. How about just\n> > \n> >   printf %s \"$MSG\" ?\n> \n> A the point was that $MSG contains \\n, which should be turned int LF. IMO,\n> the easiest way to achieve this is:\n> \n> MSG='b3\n> c3c3c3c3\n> d3d3d3'\n> \n> test_expect_success ' ... ' '\n>    ...\n>    MSG=\"$MSG\" git notes edit\n> '\n> \n> and go back to using echo in the part cited above.\n\nHeh, I almost suggested it, but I know that I get quoting wrong all the \ntime.\n\nCiao,\nDscho\n"},{"id":"100480","messageId":"496E51A3.8050908@gmail.com","threadId":"17152","inReplyTo":"496E1D77.6000307@viscovery.net","subject":"[PATCH next v3] git-notes: add test case for multi-line notes","fromName":"Tor Arne Vestbø","fromEmail":"torarnv@gmail.com","sentAt":"2009-01-14T20:57:07Z","receivedAt":"2009-01-14T20:57:07Z","isPatch":true,"sender":{"key":"torarnv@gmail.com","avatar":"https://gravatar.com/avatar/847af0150a5a28ad86d9db1556a48aba04e7642c6a29a5a767f8c2bdf1720321?d=mp&s=160"},"body":"The tests adds a third commit with a multi-line note. The output of\ngit log -2 is then checked to see if the note lines are wrapped\ncorrectly, and that there's a line separator between the two commits.\n\nSigned-off-by: Tor Arne Vestbø <tavestbo@trolltech.com>\n---\n t/t3301-notes.sh |   32 +++++++++++++++++++++++++++++++-\n 1 files changed, 31 insertions(+), 1 deletions(-)\n\ndiff --git a/t/t3301-notes.sh b/t/t3301-notes.sh\nindex ba42c45..9393a25 100755\n--- a/t/t3301-notes.sh\n+++ b/t/t3301-notes.sh\n@@ -59,7 +59,37 @@ EOF\n test_expect_success 'show notes' '\n \t! (git cat-file commit HEAD | grep b1) &&\n \tgit log -1 > output &&\n-\tgit diff expect output\n+\ttest_cmp expect output\n+'\n+test_expect_success 'create multi-line notes (setup)' '\n+\t: > a3 &&\n+\tgit add a3 &&\n+\ttest_tick &&\n+\tgit commit -m 3rd &&\n+\tMSG=\"b3\n+c3c3c3c3\n+d3d3d3\" git notes edit\n+'\n+\n+cat > expect-multiline << EOF\n+commit 1584215f1d29c65e99c6c6848626553fdd07fd75\n+Author: A U Thor <author@example.com>\n+Date:   Thu Apr 7 15:15:13 2005 -0700\n+\n+    3rd\n+\n+Notes:\n+    b3\n+    c3c3c3c3\n+    d3d3d3\n+EOF\n+\n+printf \"\\n\" >> expect-multiline\n+cat expect >> expect-multiline\n+\n+test_expect_success 'show multi-line notes' '\n+\tgit log -2 > output &&\n+\ttest_cmp expect-multiline output\n '\n \n test_done\n-- \n1.6.0.2.GIT\n"},{"id":"100482","messageId":"alpine.DEB.1.00.0901142209570.3586@pacific.mpi-cbg.de","threadId":"17152","inReplyTo":"496E51A3.8050908@gmail.com","subject":"Re: [PATCH next v3] git-notes: add test case for multi-line notes","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-01-14T21:10:41Z","receivedAt":"2009-01-14T21:10:41Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 14 Jan 2009, Tor Arne Vestbø wrote:\n\n> The tests adds a third commit with a multi-line note. The output of\n> git log -2 is then checked to see if the note lines are wrapped\n> correctly, and that there's a line separator between the two commits.\n> \n> Signed-off-by: Tor Arne Vestbø <tavestbo@trolltech.com>\n> ---\n\nAcked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\nMaybe squash the test into the fix?\n\nCiao,\nDscho"},{"id":"100729","messageId":"49708644.7040809@trolltech.com","threadId":"17152","inReplyTo":"alpine.DEB.1.00.0901142209570.3586@pacific.mpi-cbg.de","subject":"[PATCH next v4] git-notes: fix printing of multi-line notes","fromName":"Tor Arne Vestbø","fromEmail":"tavestbo@trolltech.com","sentAt":"2009-01-16T13:06:12Z","receivedAt":"2009-01-16T13:06:12Z","isPatch":true,"sender":{"key":"torarnv@gmail.com","avatar":"https://gravatar.com/avatar/847af0150a5a28ad86d9db1556a48aba04e7642c6a29a5a767f8c2bdf1720321?d=mp&s=160"},"body":"The line length was read from the same position every time,\ncausing mangled output when printing notes with multiple lines.\n\nAlso, adding new-line manually for each line ensures that we\nget a new-line between commits, matching git-log for commits\nwithout notes.\n\nTest case added to t3301-notes.sh.\n\nSigned-off-by: Tor Arne Vestbø <tavestbo@trolltech.com>\nAcked-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\nSorry about the delay. Here's a squashed patch.\n\n notes.c          |   13 +++++++------\n t/t3301-notes.sh |   32 +++++++++++++++++++++++++++++++-\n 2 files changed, 38 insertions(+), 7 deletions(-)\n\ndiff --git a/notes.c b/notes.c\nindex ad43a2e..bd73784 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -110,8 +110,8 @@ void get_commit_notes(const struct commit *commit, struct strbuf *sb,\n {\n \tstatic const char *utf8 = \"utf-8\";\n \tunsigned char *sha1;\n-\tchar *msg;\n-\tunsigned long msgoffset, msglen;\n+\tchar *msg, *msg_p;\n+\tunsigned long linelen, msglen;\n \tenum object_type type;\n \n \tif (!initialized) {\n@@ -148,12 +148,13 @@ void get_commit_notes(const struct commit *commit, struct strbuf *sb,\n \n \tstrbuf_addstr(sb, \"\\nNotes:\\n\");\n \n-\tfor (msgoffset = 0; msgoffset < msglen;) {\n-\t\tint linelen = strchrnul(msg, '\\n') - msg;\n+\tfor (msg_p = msg; msg_p < msg + msglen; msg_p += linelen + 1) {\n+\t\tlinelen = strchrnul(msg_p, '\\n') - msg_p;\n \n \t\tstrbuf_addstr(sb, \"    \");\n-\t\tstrbuf_add(sb, msg + msgoffset, linelen);\n-\t\tmsgoffset += linelen;\n+\t\tstrbuf_add(sb, msg_p, linelen);\n+\t\tstrbuf_addch(sb, '\\n');\n \t}\n+\n \tfree(msg);\n }\ndiff --git a/t/t3301-notes.sh b/t/t3301-notes.sh\nindex ba42c45..9393a25 100755\n--- a/t/t3301-notes.sh\n+++ b/t/t3301-notes.sh\n@@ -59,7 +59,37 @@ EOF\n test_expect_success 'show notes' '\n \t! (git cat-file commit HEAD | grep b1) &&\n \tgit log -1 > output &&\n-\tgit diff expect output\n+\ttest_cmp expect output\n+'\n+test_expect_success 'create multi-line notes (setup)' '\n+\t: > a3 &&\n+\tgit add a3 &&\n+\ttest_tick &&\n+\tgit commit -m 3rd &&\n+\tMSG=\"b3\n+c3c3c3c3\n+d3d3d3\" git notes edit\n+'\n+\n+cat > expect-multiline << EOF\n+commit 1584215f1d29c65e99c6c6848626553fdd07fd75\n+Author: A U Thor <author@example.com>\n+Date:   Thu Apr 7 15:15:13 2005 -0700\n+\n+    3rd\n+\n+Notes:\n+    b3\n+    c3c3c3c3\n+    d3d3d3\n+EOF\n+\n+printf \"\\n\" >> expect-multiline\n+cat expect >> expect-multiline\n+\n+test_expect_success 'show multi-line notes' '\n+\tgit log -2 > output &&\n+\ttest_cmp expect-multiline output\n '\n \n test_done\n-- \n1.6.0.2.GIT\n"},{"id":"101062","messageId":"7vmydouwxl.fsf@gitster.siamese.dyndns.org","threadId":"17152","inReplyTo":"49708644.7040809@trolltech.com","subject":"Re: [PATCH next v4] git-notes: fix printing of multi-line notes","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-01-18T21:27:34Z","receivedAt":"2009-01-18T21:27:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Tor Arne Vestbø <tavestbo@trolltech.com> writes:\n\n> The line length was read from the same position every time,\n> causing mangled output when printing notes with multiple lines.\n>\n> Also, adding new-line manually for each line ensures that we\n> get a new-line between commits, matching git-log for commits\n> without notes.\n>\n> Test case added to t3301-notes.sh.\n>\n> Signed-off-by: Tor Arne Vestbø <tavestbo@trolltech.com>\n> Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n>\n> Sorry about the delay. Here's a squashed patch.\n\nThanks.  This exactly matches 22a3d06 (git-notes: fix printing of\nmulti-line notes, 2009-01-13) I already have, so we are in a good shape.\n"}]}