In a subsequent commit, byte size values displayed in table output for
the git-repo(1) "structure" subcommand will be shown in a more
human-readable format with the appropriate unit prefixes. For this
usecase, the downscaled values and unit strings must be handled
separately to ensure proper column alignment.
Split out logic from strbuf_humanise() to downscale byte values and
determine the corresponding unit prefix into a separate humanise_bytes()
function that provides seperate value and unit strings.
Note that the "byte" string in "t/helper/test-simple-ipc.c" is unmarked
for translation here so that it doesn't conflict with the newly defined
plural "byte/bytes" translation and instead uses it.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Justin Tobler committedDec 17, 2025 at 11:53 UTCce849b1851102d974653701564573798034492d5
index a580ac6084..698b3cc4a5 100644--- a/strbuf.h+++ b/strbuf.h@@ -367,6 +367,20 @@ void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *src); */ void strbuf_add_percentencode(struct strbuf *dst, const char *src, int flags);+enum humanise_flags {+ /*+ * Use rate based units for humanised values.+ */+ HUMANISE_RATE = (1 << 0),+};++/**+ * Converts the given byte size into a downscaled human-readable value and+ * corresponding unit as two separate strings.+ */+void humanise_bytes(off_t bytes, char **value, const char **unit,+ unsigned flags);+ /** * Append the given byte size as a human-readable string (i.e. 12.23 KiB, * 3.50 MiB).
t/helper/test-simple-ipc.c
+6-1
index 03cc5eea2c..442ad6b16f 100644--- a/t/helper/test-simple-ipc.c+++ b/t/helper/test-simple-ipc.c@@ -603,7 +603,12 @@ int cmd__simple_ipc(int argc, const char **argv) OPT_INTEGER(0, "bytecount", &cl_args.bytecount, N_("number of bytes")), OPT_INTEGER(0, "batchsize", &cl_args.batchsize, N_("number of requests per thread")),- OPT_STRING(0, "byte", &bytevalue, N_("byte"), N_("ballast character")),+ /*+ * The "byte" string here is not marked for translation and+ * instead relies on translation in strbuf.c:humanise_bytes() to+ * avoid conflict with the plural form.+ */+ OPT_STRING(0, "byte", &bytevalue, "byte", N_("ballast character")), OPT_STRING(0, "token", &cl_args.token, N_("token"), N_("command token to send to the server")), OPT_END()