From: Jeff King <peff@peff.net>
To: Vitaly Potyarkin <sio.wtf@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Truncating file names with Unicode characters
Date: Sat, 9 Jun 2018 02:23:51 -0400 [thread overview]
Message-ID: <20180609062351.GC30224@sigill.intra.peff.net> (raw)
In-Reply-To: <CA+v=Qh7eiLoN4YcnSdtjL4-wp8rTjCpA85BkQD2fRoG7u=9_Fw@mail.gmail.com>
On Fri, Jun 08, 2018 at 09:25:29PM +0300, Vitaly Potyarkin wrote:
> # Truncating file names with Unicode characters
>
> When shortening file names that contain Unicode characters, git performs
> truncation without awareness of two-byte characters. That often leads to
> splitting a character in half and displaying a garbage byte that's left.
>
> Unawareness of Unicode also means that filename length is calculated incorrectly
> and some output gets misaligned.
Yeah, I agree it would be nice for this to be more aware of multi-byte
glyphs.
Unfortunately, we don't actually know what encoding the paths are in
(and they might not even all be in the same encoding). But hopefully we
could at least make the common case work a bit better. If we know that
core.quotepath is off, then the user is expecting paths in their
terminal encoding. So possibly we could just rely on
i18n.logOutputEncoding at that point (which of course defaults to utf8).
If anyone is interested in working on it, the relevant code is in
diff.c:show_stats(). Looks like we do a straight strlen() to get the
width, which should become utf8_strwidth(). That would solve the
problem where we use the wrong width.
To deal with the broken code points, I think you'd need to copy the name
into a strbuf and use strbuf_utf8_replace() to truncate (it doesn't seem
to be well documented, but you can grep for a few other callers).
-Peff
prev parent reply other threads:[~2018-06-09 6:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-08 18:25 Truncating file names with Unicode characters Vitaly Potyarkin
2018-06-09 6:23 ` Jeff King [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180609062351.GC30224@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=sio.wtf@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).