Re: [PATCH v3 4/7] builtin/repo: introduce stats subcommand
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Sep 25, 2025, 23:51 UTC
- Message-ID
- <CAPig+cTSpq132SZQHUzYHJNqY-nOYizFW71Lu3o6a6m3jDNVJQ@mail.gmail.com>
- In-Reply-To
- <20250925232928.3846-5-jltobler@gmail.com>
On Thu, Sep 25, 2025 at 7:30 PM Justin Tobler <jltobler@gmail.com> wrote:
Show 23 quoted lines
> The shape of a repository's history can have huge impacts on the
> performance and health of the repository itself. Currently, Git lacks a
> means to surface key stats/information regarding the shape of a
> repository via a single command. Acquiring this information requires
> users to be fairly knowledgeable about the structure of a Git repository
> and how to identify the relevant data points. To fill this gap,
> supplemental tools such as git-sizer(1) have been developed.
> [...]
> Signed-off-by: Justin Tobler <jltobler@gmail.com>
> ---
> diff --git a/builtin/repo.c b/builtin/repo.c
> @@ -156,12 +159,205 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
> +static void stats_table_vaddf(struct stats_table *table,
> + struct stats_table_entry *entry,
> + const char *format, va_list ap)
> +{
> + size_t name_width;
> +
> + 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...
Show 12 quoted lines
> +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.