Phillip Wood [off-list ref] writes:
How does it ensure proper column alignment for non-utf8 encodings? I
don't see how it is possible to calculate the display width without
knowing the encoding.
Correct. But for Git, pretty much the ship has sailed, I am afraid.
All tools that rely on utf8_strwidth() are "broken" in that way if
you feed latin-1 or ISO/IEC 2022, and that includes "diff --stat"
with pathnames in non-UTF8 encodings (I do not remember if we fully
fixed the codepath for UTF-8---it used to be broken even for UTF-8).
Using strbuf_utf8_align ends up being quite verbose. An alternative
would be to keep using printf() but calculate the padding ourselves as
shown below.
I think that has been the preferred way to do this, utf8_strwidth()
to measure and decide how wide each column can be, then for each row,
we measure and make printf() fit, or truncate when the column we decide
to allocate cannot accomodate the data on a particular row that is
overly long.
Thanks.