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

Re: [PATCH v2 2/2] builtin/repo: fix table alignment for UTF-8 characters

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 15, 2025, 16:49 UTC
Message-ID
<xmqqjyzrfdgj.fsf@gitster.g>
In-Reply-To
<0eee1597-3e83-4a47-90a5-60942da01673@gmail.com>
Phillip Wood <phillip.wood123@gmail.com> 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.
Previous: Phillip Wood
Message 22 of 22 in “Fix misaligned output of git repo structure”
  1. 0/2 Fix misaligned output of git repo structureJiang Xin, Nov 14, 2025
  2. 1/2 t/unit-tests: add UTF-8 width tests for CJK charsJiang Xin, Nov 14, 2025
  3. Junio C HamanoNov 14, 2025
  4. Jiang XinNov 15, 2025
  5. 2/2 builtin/repo: fix table alignment for UTF-8 charactersJiang Xin, Nov 14, 2025
  6. Justin ToblerNov 14, 2025
  7. Jiang XinNov 15, 2025
  8. Junio C HamanoNov 14, 2025
  9. Jiang XinNov 15, 2025
  10. Junio C HamanoNov 15, 2025
  11. Jiang XinNov 16, 2025
  12. Junio C HamanoNov 16, 2025
  13. Kristoffer HaugsbakkNov 14, 2025
  14. Jiang XinNov 14, 2025
  15. Junio C HamanoNov 14, 2025
  16. Jiang XinNov 15, 2025
  17. Junio C HamanoNov 14, 2025
  18. 0/2 Fix misaligned output of git repo structureJiang Xin, Nov 15, 2025
  19. 1/2 t/unit-tests: add UTF-8 width tests for CJK charsJiang Xin, Nov 15, 2025
  20. 2/2 builtin/repo: fix table alignment for UTF-8 charactersJiang Xin, Nov 15, 2025
  21. Phillip WoodNov 15, 2025
  22. Junio C HamanoNov 15, 2025

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.