From: Jiang Xin <worldhello.net@gmail•com>
To: Junio C Hamano <gitster@pobox•com>,
Git List <git@vger•kernel.org>,
Justin Tobler <jltobler@gmail•com>
Cc: "Jiang Xin" <worldhello.net@gmail•com>,
"Alexander Shopov" <ash@kambanaria•org>,
"Mikel Forcada" <mikel.forcada@gmail•com>,
"Ralf Thielow" <ralf.thielow@gmail•com>,
"Jean-Noël Avila" <jn.avila@free•fr>,
"Bagas Sanjaya" <bagasdotme@gmail•com>,
"Dimitriy Ryazantcev" <DJm00n@mail•ru>,
"Peter Krefting" <peter@softwolves•pp.se>,
"Emir SARI" <bitigchi@me•com>, "Arkadii Yakovets" <ark@cho•red>,
"Vũ Tiến Hưng" <newcomerminecraft@gmail•com>,
"Teng Long" <dyroneteng@gmail•com>,
"Yi-Jyun Pan" <pan93412@gmail•com>,
Gemini <noreply@developers•google.com>
Subject: [PATCH 2/2] builtin/repo: fix table alignment for UTF-8 characters
Date: Fri, 14 Nov 2025 00:52:45 -0500 [thread overview]
Message-ID: <a50bcde6446fbd87b4fb04b28c579a915457813a.1763098804.git.worldhello.net@gmail.com> (raw)
In-Reply-To: <cover.1763098804.git.worldhello.net@gmail.com>
The output table from "git repo structure" is misaligned when displaying
UTF-8 characters (e.g., non-ASCII glyphs). E.g.:
| 仓库结构 | 值 |
| -------------- | ---- |
| * 引用 | |
| * 计数 | 67 |
| * 分支 | 6 |
| * 标签 | 30 |
| * 远程 | 19 |
| * 其它 | 12 |
| | |
| * 可达对象 | |
| * 计数 | 2217 |
| * 提交 | 279 |
| * 树 | 740 |
| * 数据对象 | 1168 |
| * 标签 | 30 |
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.
Co-developed-by: Gemini <noreply@developers•google.com>
Signed-off-by: Jiang Xin <worldhello.net@gmail•com>
---
builtin/repo.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/builtin/repo.c b/builtin/repo.c
index 9d4749f79b..d0b4a060b1 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -292,14 +292,21 @@ static void stats_table_print_structure(const struct stats_table *table)
int name_col_width = utf8_strwidth(name_col_title);
int value_col_width = utf8_strwidth(value_col_title);
struct string_list_item *item;
+ struct strbuf buf = STRBUF_INIT;
if (table->name_col_width > name_col_width)
name_col_width = table->name_col_width;
if (table->value_col_width > value_col_width)
value_col_width = table->value_col_width;
- printf("| %-*s | %-*s |\n", name_col_width, name_col_title,
- value_col_width, value_col_title);
+ strbuf_addstr(&buf, "| ");
+ strbuf_utf8_align(&buf, ALIGN_LEFT, name_col_width, name_col_title);
+ strbuf_addstr(&buf, " | ");
+ strbuf_utf8_align(&buf, ALIGN_LEFT, value_col_width, value_col_title);
+ strbuf_addstr(&buf, " |");
+ printf("%s\n", buf.buf);
+ strbuf_reset(&buf);
+
printf("| ");
for (int i = 0; i < name_col_width; i++)
putchar('-');
@@ -317,9 +324,16 @@ static void stats_table_print_structure(const struct stats_table *table)
value = entry->value;
}
- printf("| %-*s | %*s |\n", name_col_width, item->string,
- value_col_width, value);
+ strbuf_reset(&buf);
+ strbuf_addstr(&buf, "| ");
+ strbuf_utf8_align(&buf, ALIGN_LEFT, name_col_width, item->string);
+ strbuf_addstr(&buf, " | ");
+ strbuf_utf8_align(&buf, ALIGN_RIGHT, value_col_width, value);
+ strbuf_addstr(&buf, " |");
+ printf("%s\n", buf.buf);
}
+
+ strbuf_release(&buf);
}
static void stats_table_clear(struct stats_table *table)
--
2.52.0.rc2.5.g4c20a63325.dirty
next prev parent reply other threads:[~2025-11-14 5:52 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 5:52 [PATCH 0/2] Fix misaligned output of git repo structure Jiang Xin
2025-11-14 5:52 ` [PATCH 1/2] t/unit-tests: add UTF-8 width tests for CJK chars Jiang Xin
2025-11-14 20:17 ` Junio C Hamano
2025-11-15 12:38 ` Jiang Xin
2025-11-14 5:52 ` Jiang Xin [this message]
2025-11-14 17:50 ` [PATCH 2/2] builtin/repo: fix table alignment for UTF-8 characters Justin Tobler
2025-11-15 12:41 ` Jiang Xin
2025-11-14 20:00 ` Junio C Hamano
2025-11-15 12:54 ` Jiang Xin
2025-11-15 16:36 ` Junio C Hamano
2025-11-16 13:32 ` Jiang Xin
2025-11-16 16:51 ` Junio C Hamano
2025-11-14 7:41 ` [PATCH 0/2] Fix misaligned output of git repo structure Kristoffer Haugsbakk
2025-11-14 9:52 ` Jiang Xin
2025-11-14 19:22 ` Junio C Hamano
2025-11-15 12:25 ` Jiang Xin
2025-11-14 16:13 ` Junio C Hamano
2025-11-15 13:36 ` [PATCH v2 " Jiang Xin
2025-11-15 13:36 ` [PATCH v2 1/2] t/unit-tests: add UTF-8 width tests for CJK chars Jiang Xin
2025-11-15 13:36 ` [PATCH v2 2/2] builtin/repo: fix table alignment for UTF-8 characters Jiang Xin
2025-11-15 15:04 ` Phillip Wood
2025-11-15 16:49 ` Junio C Hamano
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=a50bcde6446fbd87b4fb04b28c579a915457813a.1763098804.git.worldhello.net@gmail.com \
--to=worldhello.net@gmail$(echo .)com \
--cc=DJm00n@mail$(echo .)ru \
--cc=ark@cho$(echo .)red \
--cc=ash@kambanaria$(echo .)org \
--cc=bagasdotme@gmail$(echo .)com \
--cc=bitigchi@me$(echo .)com \
--cc=dyroneteng@gmail$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
--cc=jltobler@gmail$(echo .)com \
--cc=jn.avila@free$(echo .)fr \
--cc=mikel.forcada@gmail$(echo .)com \
--cc=newcomerminecraft@gmail$(echo .)com \
--cc=noreply@developers$(echo .)google.com \
--cc=pan93412@gmail$(echo .)com \
--cc=peter@softwolves$(echo .)pp.se \
--cc=ralf.thielow@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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