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] 14e1a4e1ff70aff36db3f5d2a8b806efd0134d50 utf8: fix off-by-one wrapping of text Signed-off-by: Steffen Prohaska <prohaska@zib.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Steffen Prohaska committed Dec 11, 2012 at 06:59 UTC 5b59708268c82262fb13fb8681663dd158b030bd
2 files changed +26 -3
builtin/shortlog.c
+2 -3
@@ -306,9 +306,8 @@ parse_done:
306 static void add_wrapped_shortlog_msg(struct strbuf *sb, const char *s,
307 const struct shortlog *log)
308 {
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');
311 }
312
313 void shortlog_output(struct shortlog *log)
t/t4201-shortlog.sh
+24
@@ -120,6 +120,30 @@ test_expect_success 'shortlog from non-git directory' '
120 test_cmp expect out
121 '
122
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 <author@example.com>
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 <author@example.com>
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 +
147 iconvfromutf8toiso88591() {
148 printf "%s" "$*" | iconv -f UTF-8 -t ISO8859-1
149 }