]> Kevux Git Server - rit/commit
builtin/repo: fix table alignment for UTF-8 characters
authorJiang Xin <worldhello.net@gmail.com>
Sat, 15 Nov 2025 13:36:11 +0000 (08:36 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Nov 2025 00:04:24 +0000 (16:04 -0800)
commit7a03a10a3a746dd8565a3a0e6126f60523b41738
treeb1330f181a430a74e799b08dfc2f2a808ace19e1
parent878fef8ebf6cf513842de14284ee58f4d92fcef3
builtin/repo: fix table alignment for UTF-8 characters

The output table from "git repo structure" is misaligned when displaying
UTF-8 characters (e.g., non-ASCII glyphs). E.g.:

    | 仓库结构   | 值  |
    | -------------- | ---- |
    | * 引用       |      |
    |   * 计数     |   67 |

The previous implementation used simple width formatting with printf()
which didn't properly handle multi-byte UTF-8 characters, causing
misaligned table columns when displaying repository structure
information.

This change modifies the stats_table_print_structure function to use
strbuf_utf8_align() instead of basic printf width specifiers. This
ensures proper column alignment regardless of the character encoding of
the content being displayed.

Also add test cases for strbuf_utf8_align(), a function newly introduced
in "builtin/repo.c".

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/repo.c
t/unit-tests/u-utf8-width.c