Re: [PATCH v3 4/7] builtin/repo: introduce stats subcommand
- From
Justin Tobler <jltobler@gmail.com>
- Date
- Sep 26, 2025, 01:38 UTC
- Message-ID
- <wugagxpikclvhv5ajxzmeb42rneuv3hoi3bd23lqt5uysdotdg@gxvmipzrajdu>
- In-Reply-To
- <CAPig+cTSpq132SZQHUzYHJNqY-nOYizFW71Lu3o6a6m3jDNVJQ@mail.gmail.com>
On 25/09/25 07:51PM, Eric Sunshine wrote:
> On Thu, Sep 25, 2025 at 7:30 PM Justin Tobler <jltobler@gmail.com> wrote:
[snip]
Show 29 quoted lines
> > + strbuf_vaddf(&buf, format, ap);
> > + formatted_name = strbuf_detach(&buf, &name_width);
> > + [...]
> > + if (name_width > table->name_col_width)
> > + table->name_col_width = name_width;
>
> Here, you're using the byte length of the composed string to compute
> the table width which you will use for alignment purposes when
> rendering the table...
>
> > +static void stats_table_setup(struct stats_table *table, struct ref_stats *refs)
> > +{
> > + size_t ref_total;
> > +
> > + ref_total = refs->branches + refs->remotes + refs->tags + refs->others;
> > + stats_table_addf(table, "* %s", _("References"));
> > + stats_table_count_addf(table, ref_total, " * %s", _("Count"));
> > + stats_table_count_addf(table, refs->branches, " * %s", _("Branches"));
> > + stats_table_count_addf(table, refs->tags, " * %s", _("Tags"));
> > + stats_table_count_addf(table, refs->remotes, " * %s", _("Remotes"));
> > + stats_table_count_addf(table, refs->others, " * %s", _("Others"));
> > +}
>
> ...however, here you feed the function translatable strings, which
> means that the display length of the composed string is not guaranteed
> to be the same as the byte length.
>
> To resolve this, you probably want to investigate Git's utf8.h header,
> in particular, the utf8_strwidth() function.Thanks for raising this. I hadn't considered the fact that the characters in translated strings could occupy more than one byte. I'll address this in the next version by using utf8_strwidth() as you mentioned. :)
Thanks, -Justin