git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Truncating file names with Unicode characters

From
VPVitaly Potyarkin <sio.wtf@gmail.com>
Date
Jun 8, 2018, 18:25 UTC
Message-ID
<CA+v=Qh7eiLoN4YcnSdtjL4-wp8rTjCpA85BkQD2fRoG7u=9_Fw@mail.gmail.com>
# 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.

I have tested this with git 2.14.1 on Windows and with git 2.11.0 on Linux. My configuration includes setting `core.quotepath = off` to display Unicode paths.

# Example: `git log --stat`
## Bad output: half-characters and wrong text alignment

The last file name gets truncated in the middle of the character (`ˆ` is what's left of it). Text alignment is off because string lengths are calculated in bytes instead of characters.

    Extension/README.md                                |  28 +++++++++
    .../Catalog.Номенклатура.xml           |  32 ++++++++++
    .../Configuration.xml                              |   5 +-
    ...етПереработчика.ObjectModule.txt |  39 ++++++++++++
    ...cument.ОтчетПереработчика.xml |  68 +++++++++++++++++++++
    .../Enum.СтавкиНДС.xml                    |  24 ++++++++
    ...ˆирениеERPПотяркин_2018-06-05.cfe | Bin 0 -> 22018 bytes
    7 files changed, 195 insertions(+), 1 deletion(-)
## Good output with ASCII file names

Truncation and alignment are done right because each character is represented by a single byte.

    .../index.html                                             | 14
++++++++++++++
    docs/posts/2017/loops-in-power-query-m-language/index.html | 14
++++++++++++++
    .../index.html                                             |  7 +++++++
    .../temporary-virtual-environment-for-python/index.html    | 14
++++++++++++++
    .../index.html                                             | 14
++++++++++++++
    docs/posts/2018/getting-started-with-libpq/index.html      | 14
++++++++++++++
    .../index.html                                             | 14
++++++++++++++
    .../2018/unit-testing-in-power-query-m-language/index.html |  7 +++++++
    8 files changed, 98 insertions(+)
Next: Jeff King
Message 1 of 2 in “Truncating file names with Unicode characters”
  1. Vitaly PotyarkinJun 8, 2018
  2. Jeff KingJun 9, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.