From: Patrick Steinhardt Date: Mon, 15 Dec 2025 05:33:14 GMT Subject: Re: [PATCH v2 3/7] builtin/repo: humanise count values in structure output Message-ID: In-Reply-To: <20251212223644.3090879-4-jltobler@gmail.com> On Fri, Dec 12, 2025 at 04:36:40PM -0600, Justin Tobler wrote: > diff --git a/strbuf.c b/strbuf.c > index 1fb47bf21b..cebb1593ab 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); > } > > +char *strbuf_humanise_count_value(struct strbuf *buf, size_t value) > +{ > + if (value >= 1000000000) { > + uintmax_t x = (uintmax_t)value + 5000000; /* for rounding */ > + strbuf_addf(buf, "%" PRIuMAX ".%02" PRIuMAX, > + x / 1000000000, x % 1000000000 / 10000000); > + return xstrfmt(_("G")); > + } else if (value >= 1000000) { > + uintmax_t x = (uintmax_t)value + 5000; /* for rounding */ > + strbuf_addf(buf, "%" PRIuMAX ".%02" PRIuMAX, > + x / 1000000, x % 1000000 / 10000); > + return xstrfmt(_("M")); > + } else if (value >= 1000) { > + uintmax_t x = (uintmax_t)value + 5; /* for rounding */ > + strbuf_addf(buf, "%" PRIuMAX ".%02" PRIuMAX, > + x / 1000, x % 1000 / 10); > + return xstrfmt(_("k")); > + } else { > + strbuf_addf(buf, "%" PRIuMAX, (uintmax_t)value); > + return NULL; > + } > +} Same comment here as in the previous patch, can't we return `const char *` here in case we drop all allocations? Patrick