git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Phillip Wood <phillip.wood123@gmail.com>
Cc: Jiang Xin <worldhello.net@gmail.com>,
	 Git List <git@vger.kernel.org>,
	Justin Tobler <jltobler@gmail.com>
Subject: Re: [PATCH v2 2/2] builtin/repo: fix table alignment for UTF-8 characters
Date: Sat, 15 Nov 2025 08:49:32 -0800	[thread overview]
Message-ID: <xmqqjyzrfdgj.fsf@gitster.g> (raw)
In-Reply-To: <0eee1597-3e83-4a47-90a5-60942da01673@gmail.com> (Phillip Wood's message of "Sat, 15 Nov 2025 15:04:11 +0000")

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.

      reply	other threads:[~2025-11-15 16:49 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 ` [PATCH 2/2] builtin/repo: fix table alignment for UTF-8 characters Jiang Xin
2025-11-14 17:50   ` 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 [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=xmqqjyzrfdgj.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jltobler@gmail.com \
    --cc=phillip.wood123@gmail.com \
    --cc=worldhello.net@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).