diff --git a/Documentation/pretty-formats.adoc b/Documentation/pretty-formats.adoc index 2ae0eb11a9..4fb0419715 100644 --- a/Documentation/pretty-formats.adoc +++ b/Documentation/pretty-formats.adoc @@ -169,8 +169,13 @@ The placeholders are: on the next placeholders until the color is switched again. ++%m++:: left (`<`), right (`>`) or boundary (`-`) mark -++%w(++`[[,[,]]]`++)++:: switch line wrapping, like the `-w` option of - linkgit:git-shortlog[1]. +++%w(++`[[,[,]]]`++)++:: set line wrapping and indentation. + Output is word-wrapped at __ columns, with the first line + indented by __ spaces and subsequent lines indented by + __ spaces. A width of 0 disables wrapping. Omitted values + default to 0, so ++%w()++ turns off both wrapping and indentation. + Newlines that are followed by an ASCII letter or digit are replaced + by spaces to reflow paragraphs. Existing indentation is kept. ++%<(++`[,(trunc|ltrunc|mtrunc)]`++)++:: make the next placeholder take at least N column widths, padding spaces on the right if necessary. Optionally diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 06552a6271..5895780e8f 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -94,6 +94,12 @@ test_expect_success 'format %w(,1,2)' ' test_cmp expect actual ' +test_expect_success 'format %w(11)' ' + + git log -2 --format="%w(11) This is%n the %s%n commit." > actual && + test_cmp expect actual +' + cat > expect << EOF $(git rev-parse --short :/sixth ) sixth $(git rev-parse --short :/fifth ) fifth diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 4be5c51489..0733f22d58 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -1139,7 +1139,7 @@ test_expect_success 'log --pretty with invalid padding format' ' test_expect_success 'log --pretty with magical wrapping directives' ' commit_id=$(git commit-tree HEAD^{tree} -m "describe me") && git tag describe-me $commit_id && - printf "\n(tag:\ndescribe-me)%%+w(2)" >expect && + printf "\n\n(tag:\ndescribe-me)%%+w(2)" >expect && git log -1 --pretty="format:%w(1)%+d%+w(2)" $commit_id >actual && test_cmp expect actual ' diff --git a/utf8.c b/utf8.c index 96460cc414..bb55bf357f 100644 --- a/utf8.c +++ b/utf8.c @@ -322,6 +322,7 @@ retry: space++; if (*space == '\n') { strbuf_addch(buf, '\n'); + space++; goto new_line; } else if (!isalnum(*space)) @@ -333,9 +334,10 @@ retry: text++; } else { + space += isspace(*space); new_line: strbuf_addch(buf, '\n'); - text = bol = space + isspace(*space); + text = bol = space; space = NULL; w = indent = indent2; }