Subject: Re: [PATCH v3 3/7] builtin/repo: humanise count values in structure output

From: Patrick Steinhardt <[email-masked]>
Date: Tue, 16 Dec 2025 09:25:24 +0100

On Mon, Dec 15, 2025 at 02:56:35PM -0600, Justin Tobler wrote:
> diff --git a/strbuf.c b/strbuf.c
> index bb8e98872f..662edd4d19 100644
> --- a/strbuf.c
> +++ b/strbuf.c
> @@ -836,6 +836,29 @@ void strbuf_addstr_urlencode(struct strbuf *sb, const char *s,
>  	strbuf_add_urlencode(sb, s, strlen(s), allow_unencoded_fn);
>  }
>  
> +void humanise_count(size_t count, char **value, const char **unit)
> +{
> +	if (count >= 1000000000) {
> +		size_t x = count + 5000000; /* for rounding */
> +		*value = xstrfmt(_("%u.%2.2u"), (unsigned)(x / 1000000000),
> +				 (unsigned)(x % 1000000000 / 10000000));
> +		*unit = _("G");
> +	} else if (count >= 1000000) {
> +		size_t x = count + 5000; /* for rounding */
> +		*value = xstrfmt(_("%u.%2.2u"), (unsigned)(x / 1000000),
> +				 (unsigned)(x % 1000000 / 10000));
> +		*unit = _("M");
> +	} else if (count >= 1000) {
> +		size_t x = count + 5; /* for rounding */
> +		*value = xstrfmt(_("%u.%2.2u"), (unsigned)(x / 1000),
> +				 (unsigned)(x % 1000 / 10));
> +		*unit = _("k");
> +	} else {
> +		*value = xstrfmt(_("%u"), (unsigned)count);
> +		*unit = NULL;
> +	}
> +}

I guess these here could also all use TRANSLATOR comments.

Patrick