Skip to content

Commit

Permalink
utf8: fix off-by-one wrapping of text
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jan H. Schönherr authored and Junio C Hamano committed Oct 18, 2012
1 parent bafc478 commit 14e1a4e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions t/t4202-log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
'

Expand Down
2 changes: 1 addition & 1 deletion utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ int strbuf_add_wrapped_text(struct strbuf *buf,

c = *text;
if (!c || isspace(c)) {
if (w < width || !space) {
if (w <= width || !space) {
const char *start = bol;
if (!c && text == start)
return w;
Expand Down

0 comments on commit 14e1a4e

Please sign in to comment.