utf8: fix off-by-one wrapping of text
The wrapping logic in strbuf_add_wrapped_text() does currently not allow lines that entirely fill the allowed width, instead it wraps the line one character too early. For example, the text "This is the sixth commit." formatted via "%w(11,1,2)" (wrap at 11 characters, 1 char indent of first line, 2 char indent of following lines) results in four lines: " This is", " the", " sixth", " commit." This is wrong, because " the sixth" is exactly 11 characters long, and thus allowed. Fix this by allowing the (width+1) character of a line to be a valid wrapping point if it is a whitespace character. Signed-off-by: Jan H. Schönherr <schnhrr@cs.tu-berlin.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jan H. Schönherr committed
Oct 18, 2012 at 16:43 UTC
14e1a4e1ff70aff36db3f5d2a8b806efd0134d50
2 files changed
+3
-3
t/t4202-log.sh
+2
-2
@@ -72,9 +72,9 @@ cat > expect << EOF
72
commit.
73
EOF
74
75
-test_expect_success 'format %w(12,1,2)' '
75
+test_expect_success 'format %w(11,1,2)' '
76
77
- git log -2 --format="%w(12,1,2)This is the %s commit." > actual &&
77
+ git log -2 --format="%w(11,1,2)This is the %s commit." > actual &&
78
test_cmp expect actual
79
'
80
utf8.c
+1
-1
@@ -353,7 +353,7 @@ retry:
353
354
c = *text;
355
if (!c || isspace(c)) {
356
- if (w < width || !space) {
356
+ if (w <= width || !space) {
357
const char *start = bol;
358
if (!c && text == start)
359
return w;