Merge branch 'po/pretty-format-columns-doc'

Clarify column-padding operators in the pretty format string.

* po/pretty-format-columns-doc:
  doc: pretty-formats note wide char limitations, and add tests
  doc: pretty-formats describe use of ellipsis in truncation
  doc: pretty-formats document negative column alignments
  doc: pretty-formats: delineate `%<|(` parameter values
  doc: pretty-formats: separate parameters from placeholders
This commit is contained in:
Junio C Hamano 2023-01-30 14:24:22 -08:00
commit 4ac326f64f
2 changed files with 48 additions and 11 deletions

View File

@ -146,24 +146,34 @@ The placeholders are:
'%m':: left (`<`), right (`>`) or boundary (`-`) mark '%m':: left (`<`), right (`>`) or boundary (`-`) mark
'%w([<w>[,<i1>[,<i2>]]])':: switch line wrapping, like the -w option of '%w([<w>[,<i1>[,<i2>]]])':: switch line wrapping, like the -w option of
linkgit:git-shortlog[1]. linkgit:git-shortlog[1].
'%<(<N>[,trunc|ltrunc|mtrunc])':: make the next placeholder take at '%<( <N> [,trunc|ltrunc|mtrunc])':: make the next placeholder take at
least N columns, padding spaces on least N column widths, padding spaces on
the right if necessary. Optionally the right if necessary. Optionally
truncate at the beginning (ltrunc), truncate (with ellipsis '..') at the left (ltrunc) `..ft`,
the middle (mtrunc) or the end the middle (mtrunc) `mi..le`, or the end
(trunc) if the output is longer than (trunc) `rig..`, if the output is longer than
N columns. Note that truncating N columns.
Note 1: that truncating
only works correctly with N >= 2. only works correctly with N >= 2.
'%<|(<N>)':: make the next placeholder take at least until Nth Note 2: spaces around the N and M (see below)
columns, padding spaces on the right if necessary values are optional.
'%>(<N>)', '%>|(<N>)':: similar to '%<(<N>)', '%<|(<N>)' respectively, Note 3: Emojis and other wide characters
will take two display columns, which may
over-run column boundaries.
Note 4: decomposed character combining marks
may be misplaced at padding boundaries.
'%<|( <M> )':: make the next placeholder take at least until Mth
display column, padding spaces on the right if necessary.
Use negative M values for column positions measured
from the right hand edge of the terminal window.
'%>( <N> )', '%>|( <M> )':: similar to '%<( <N> )', '%<|( <M> )' respectively,
but padding spaces on the left but padding spaces on the left
'%>>(<N>)', '%>>|(<N>)':: similar to '%>(<N>)', '%>|(<N>)' '%>>( <N> )', '%>>|( <M> )':: similar to '%>( <N> )', '%>|( <M> )'
respectively, except that if the next respectively, except that if the next
placeholder takes more spaces than given and placeholder takes more spaces than given and
there are spaces on its left, use those there are spaces on its left, use those
spaces spaces
'%><(<N>)', '%><|(<N>)':: similar to '%<(<N>)', '%<|(<N>)' '%><( <N> )', '%><|( <M> )':: similar to '%<( <N> )', '%<|( <M> )'
respectively, but padding both sides respectively, but padding both sides
(i.e. the text is centered) (i.e. the text is centered)

View File

@ -1094,4 +1094,31 @@ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit mes
test_cmp expect error test_cmp expect error
' '
# pretty-formats note wide char limitations, and add tests
test_expect_failure 'wide and decomposed characters column counting' '
# from t/lib-unicode-nfc-nfd.sh hex values converted to octal
utf8_nfc=$(printf "\303\251") && # e acute combined.
utf8_nfd=$(printf "\145\314\201") && # e with a combining acute (i.e. decomposed)
utf8_emoji=$(printf "\360\237\221\250") &&
# replacement character when requesting a wide char fits in a single display colum.
# "half wide" alternative could be a plain ASCII dot `.`
utf8_vert_ell=$(printf "\342\213\256") &&
# use ${xxx} here!
nfc10="${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}" &&
nfd10="${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}" &&
emoji5="${utf8_emoji}${utf8_emoji}${utf8_emoji}${utf8_emoji}${utf8_emoji}" &&
# emoji5 uses 10 display columns
test_commit "abcdefghij" &&
test_commit --no-tag "${nfc10}" &&
test_commit --no-tag "${nfd10}" &&
test_commit --no-tag "${emoji5}" &&
printf "${utf8_emoji}..${utf8_emoji}${utf8_vert_ell}\n${utf8_nfd}..${utf8_nfd}${utf8_nfd}\n${utf8_nfc}..${utf8_nfc}${utf8_nfc}\na..ij\n" >expected &&
git log --format="%<(5,mtrunc)%s" -4 >actual &&
test_cmp expected actual
'
test_done test_done