Skip to content

Commit 14e1a4e

Browse files
Jan H. Schönherrgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bafc478 commit 14e1a4e

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

t/t4202-log.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ cat > expect << EOF
7272
commit.
7373
EOF
7474

75-
test_expect_success 'format %w(12,1,2)' '
75+
test_expect_success 'format %w(11,1,2)' '
7676
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 &&
7878
test_cmp expect actual
7979
'
8080

utf8.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ int strbuf_add_wrapped_text(struct strbuf *buf,
353353

354354
c = *text;
355355
if (!c || isspace(c)) {
356-
if (w < width || !space) {
356+
if (w <= width || !space) {
357357
const char *start = bol;
358358
if (!c && text == start)
359359
return w;

0 commit comments

Comments
 (0)