Skip to content

Commit 5b59708

Browse files
sprohaskagitster
authored andcommitted
shortlog: fix wrapping lines of wraplen
A recent commit [1] fixed a off-by-one wrapping error. As a side-effect, the conditional in add_wrapped_shortlog_msg() to decide whether to append a newline needs to be removed. The function should always append a newline, which was the case before the off-by-one fix, because strbuf_add_wrapped_text() never returns a value of wraplen; when it returns wraplen, the string does not end with a newline, so this caller needs to add one anyway. [1] 14e1a4e utf8: fix off-by-one wrapping of text Signed-off-by: Steffen Prohaska <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 14e1a4e commit 5b59708

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

builtin/shortlog.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,8 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
306306
static void add_wrapped_shortlog_msg(struct strbuf *sb, const char *s,
307307
const struct shortlog *log)
308308
{
309-
int col = strbuf_add_wrapped_text(sb, s, log->in1, log->in2, log->wrap);
310-
if (col != log->wrap)
311-
strbuf_addch(sb, '\n');
309+
strbuf_add_wrapped_text(sb, s, log->in1, log->in2, log->wrap);
310+
strbuf_addch(sb, '\n');
312311
}
313312

314313
void shortlog_output(struct shortlog *log)

t/t4201-shortlog.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,30 @@ test_expect_success 'shortlog from non-git directory' '
120120
test_cmp expect out
121121
'
122122

123+
test_expect_success 'shortlog should add newline when input line matches wraplen' '
124+
cat >expect <<\EOF &&
125+
A U Thor (2):
126+
bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
127+
aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
128+
129+
EOF
130+
git shortlog -w >out <<\EOF &&
131+
commit 0000000000000000000000000000000000000001
132+
Author: A U Thor <[email protected]>
133+
Date: Thu Apr 7 15:14:13 2005 -0700
134+
135+
aaaaaaaaaaaaaaaaaaaaaa: aaaaaa aaaaaaaaaa aaaa aaaaaaaa aa aaaa aa aaa
136+
137+
commit 0000000000000000000000000000000000000002
138+
Author: A U Thor <[email protected]>
139+
Date: Thu Apr 7 15:14:13 2005 -0700
140+
141+
bbbbbbbbbbbbbbbbbb: bbbbbbbb bbb bbbb bbbbbbb bb bbbb bbb bbbbb bbbbbb
142+
143+
EOF
144+
test_cmp expect out
145+
'
146+
123147
iconvfromutf8toiso88591() {
124148
printf "%s" "$*" | iconv -f UTF-8 -t ISO8859-1
125149
}

0 commit comments

Comments
 (0)