mirror of
https://github.com/git/git
synced 2024-08-27 03:29:21 +00:00
git-notes: fix printing of multi-line notes
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> Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
bb1dff9def
commit
22a3d06093
13
notes.c
13
notes.c
|
@ -110,8 +110,8 @@ void get_commit_notes(const struct commit *commit, struct strbuf *sb,
|
||||||
{
|
{
|
||||||
static const char *utf8 = "utf-8";
|
static const char *utf8 = "utf-8";
|
||||||
unsigned char *sha1;
|
unsigned char *sha1;
|
||||||
char *msg;
|
char *msg, *msg_p;
|
||||||
unsigned long msgoffset, msglen;
|
unsigned long linelen, msglen;
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
|
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
|
@ -148,12 +148,13 @@ void get_commit_notes(const struct commit *commit, struct strbuf *sb,
|
||||||
|
|
||||||
strbuf_addstr(sb, "\nNotes:\n");
|
strbuf_addstr(sb, "\nNotes:\n");
|
||||||
|
|
||||||
for (msgoffset = 0; msgoffset < msglen;) {
|
for (msg_p = msg; msg_p < msg + msglen; msg_p += linelen + 1) {
|
||||||
int linelen = strchrnul(msg, '\n') - msg;
|
linelen = strchrnul(msg_p, '\n') - msg_p;
|
||||||
|
|
||||||
strbuf_addstr(sb, " ");
|
strbuf_addstr(sb, " ");
|
||||||
strbuf_add(sb, msg + msgoffset, linelen);
|
strbuf_add(sb, msg_p, linelen);
|
||||||
msgoffset += linelen;
|
strbuf_addch(sb, '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
free(msg);
|
free(msg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,37 @@ EOF
|
||||||
test_expect_success 'show notes' '
|
test_expect_success 'show notes' '
|
||||||
! (git cat-file commit HEAD | grep b1) &&
|
! (git cat-file commit HEAD | grep b1) &&
|
||||||
git log -1 > output &&
|
git log -1 > output &&
|
||||||
git diff expect output
|
test_cmp expect output
|
||||||
|
'
|
||||||
|
test_expect_success 'create multi-line notes (setup)' '
|
||||||
|
: > a3 &&
|
||||||
|
git add a3 &&
|
||||||
|
test_tick &&
|
||||||
|
git commit -m 3rd &&
|
||||||
|
MSG="b3
|
||||||
|
c3c3c3c3
|
||||||
|
d3d3d3" git notes edit
|
||||||
|
'
|
||||||
|
|
||||||
|
cat > expect-multiline << EOF
|
||||||
|
commit 1584215f1d29c65e99c6c6848626553fdd07fd75
|
||||||
|
Author: A U Thor <author@example.com>
|
||||||
|
Date: Thu Apr 7 15:15:13 2005 -0700
|
||||||
|
|
||||||
|
3rd
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
b3
|
||||||
|
c3c3c3c3
|
||||||
|
d3d3d3
|
||||||
|
EOF
|
||||||
|
|
||||||
|
printf "\n" >> expect-multiline
|
||||||
|
cat expect >> expect-multiline
|
||||||
|
|
||||||
|
test_expect_success 'show multi-line notes' '
|
||||||
|
git log -2 > output &&
|
||||||
|
test_cmp expect-multiline output
|
||||||
'
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in a new issue