Skip to content

Commit 4ac326f

Browse files
committed
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
2 parents 06f2b5f + 540e7bc commit 4ac326f

File tree

2 files changed

+48
-11
lines changed

2 files changed

+48
-11
lines changed

Documentation/pretty-formats.txt

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,24 +146,34 @@ The placeholders are:
146146
'%m':: left (`<`), right (`>`) or boundary (`-`) mark
147147
'%w([<w>[,<i1>[,<i2>]]])':: switch line wrapping, like the -w option of
148148
linkgit:git-shortlog[1].
149-
'%<(<N>[,trunc|ltrunc|mtrunc])':: make the next placeholder take at
150-
least N columns, padding spaces on
149+
'%<( <N> [,trunc|ltrunc|mtrunc])':: make the next placeholder take at
150+
least N column widths, padding spaces on
151151
the right if necessary. Optionally
152-
truncate at the beginning (ltrunc),
153-
the middle (mtrunc) or the end
154-
(trunc) if the output is longer than
155-
N columns. Note that truncating
152+
truncate (with ellipsis '..') at the left (ltrunc) `..ft`,
153+
the middle (mtrunc) `mi..le`, or the end
154+
(trunc) `rig..`, if the output is longer than
155+
N columns.
156+
Note 1: that truncating
156157
only works correctly with N >= 2.
157-
'%<|(<N>)':: make the next placeholder take at least until Nth
158-
columns, padding spaces on the right if necessary
159-
'%>(<N>)', '%>|(<N>)':: similar to '%<(<N>)', '%<|(<N>)' respectively,
158+
Note 2: spaces around the N and M (see below)
159+
values are optional.
160+
Note 3: Emojis and other wide characters
161+
will take two display columns, which may
162+
over-run column boundaries.
163+
Note 4: decomposed character combining marks
164+
may be misplaced at padding boundaries.
165+
'%<|( <M> )':: make the next placeholder take at least until Mth
166+
display column, padding spaces on the right if necessary.
167+
Use negative M values for column positions measured
168+
from the right hand edge of the terminal window.
169+
'%>( <N> )', '%>|( <M> )':: similar to '%<( <N> )', '%<|( <M> )' respectively,
160170
but padding spaces on the left
161-
'%>>(<N>)', '%>>|(<N>)':: similar to '%>(<N>)', '%>|(<N>)'
171+
'%>>( <N> )', '%>>|( <M> )':: similar to '%>( <N> )', '%>|( <M> )'
162172
respectively, except that if the next
163173
placeholder takes more spaces than given and
164174
there are spaces on its left, use those
165175
spaces
166-
'%><(<N>)', '%><|(<N>)':: similar to '%<(<N>)', '%<|(<N>)'
176+
'%><( <N> )', '%><|( <M> )':: similar to '%<( <N> )', '%<|( <M> )'
167177
respectively, but padding both sides
168178
(i.e. the text is centered)
169179

t/t4205-log-pretty-formats.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,4 +1094,31 @@ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit mes
10941094
test_cmp expect error
10951095
'
10961096

1097+
# pretty-formats note wide char limitations, and add tests
1098+
test_expect_failure 'wide and decomposed characters column counting' '
1099+
1100+
# from t/lib-unicode-nfc-nfd.sh hex values converted to octal
1101+
utf8_nfc=$(printf "\303\251") && # e acute combined.
1102+
utf8_nfd=$(printf "\145\314\201") && # e with a combining acute (i.e. decomposed)
1103+
utf8_emoji=$(printf "\360\237\221\250") &&
1104+
1105+
# replacement character when requesting a wide char fits in a single display colum.
1106+
# "half wide" alternative could be a plain ASCII dot `.`
1107+
utf8_vert_ell=$(printf "\342\213\256") &&
1108+
1109+
# use ${xxx} here!
1110+
nfc10="${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}" &&
1111+
nfd10="${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}" &&
1112+
emoji5="${utf8_emoji}${utf8_emoji}${utf8_emoji}${utf8_emoji}${utf8_emoji}" &&
1113+
# emoji5 uses 10 display columns
1114+
1115+
test_commit "abcdefghij" &&
1116+
test_commit --no-tag "${nfc10}" &&
1117+
test_commit --no-tag "${nfd10}" &&
1118+
test_commit --no-tag "${emoji5}" &&
1119+
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 &&
1120+
git log --format="%<(5,mtrunc)%s" -4 >actual &&
1121+
test_cmp expected actual
1122+
'
1123+
10971124
test_done

0 commit comments

Comments
 (0)