]> Pileus Git - ~andy/git/commitdiff
utf8: fix off-by-one wrapping of text
authorJan H. Schönherr <schnhrr@cs.tu-berlin.de>
Thu, 18 Oct 2012 14:43:28 +0000 (16:43 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 18 Oct 2012 21:20:49 +0000 (14:20 -0700)
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>
t/t4202-log.sh
utf8.c

index 45058cc8cbe038edfb7bb953d9e10067eb5dc4b6..37023e30ea7c747f7dd92efebd2195127e94103a 100755 (executable)
@@ -72,9 +72,9 @@ cat > expect << EOF
   commit.
 EOF
 
-test_expect_success 'format %w(12,1,2)' '
+test_expect_success 'format %w(11,1,2)' '
 
-       git log -2 --format="%w(12,1,2)This is the %s commit." > actual &&
+       git log -2 --format="%w(11,1,2)This is the %s commit." > actual &&
        test_cmp expect actual
 '
 
diff --git a/utf8.c b/utf8.c
index 8acbc660d31a3552a4451749353139e0dcd371bd..523a78a651c50129ab759fa319f8bfce55b2bee7 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -353,7 +353,7 @@ retry:
 
                c = *text;
                if (!c || isspace(c)) {
-                       if (w < width || !space) {
+                       if (w <= width || !space) {
                                const char *start = bol;
                                if (!c && text == start)
                                        return w;