From: Junio C Hamano Date: Tue, 10 Nov 2026 19:31:16 GMT Subject: Re: [PATCH v3] t: add "test-tool genbytes" to avoid slow tr(1) on macOS Message-ID: In-Reply-To: > * test-genzeros.c is no longer renamed, and "genbytes" lives next to > "genzeros" in the same file. Since "genzeros" stays, the current file > name is still valid and not worth churning. Yes, it is a great realization that the file will have both genbytes and genzeros in it in the end, and there is no strong reason why it needs to be renamed. > diff --git a/t/helper/test-genzeros.c b/t/helper/test-genzeros.c > index b895436a32..e8d83d5012 100644 > --- a/t/helper/test-genzeros.c > +++ b/t/helper/test-genzeros.c > @@ -2,30 +2,28 @@ > > #include "test-tool.h" > #include "git-compat-util.h" > +#include "parse.h" > > +/* > + * Write "count" copies of "byte" to stdout, or an endless stream of them if > + * "count" is negative. > + */ > +static int generate_bytes(unsigned char byte, intmax_t count) > { > + static char buf[256 * 1024]; > ssize_t n; > > + memset(buf, byte, sizeof(buf)); > > + /* Writing out individual bytes is slow... */ > while (count < 0) > + if (xwrite(1, buf, ARRAY_SIZE(buf)) < 0) > die_errno("write error"); A curious infinite loop but that is OK. > while (count > 0) { > + n = xwrite(1, buf, > + count < ARRAY_SIZE(buf) > + ? count : ARRAY_SIZE(buf)); > > if (n < 0) > die_errno("write error"); > @@ -35,3 +33,29 @@ int cmd__genzeros(int argc, const char **argv) > > return 0; > } > +int cmd__genbytes(int argc, const char **argv) > +{ > + intmax_t count = -1; > + > + if (argc < 2 || argc > 3 || strlen(argv[1]) != 1 || > + (argc == 3 && !git_parse_signed(argv[2], &count, INTMAX_MAX))) { > + fprintf(stderr, "usage: %s []\n", argv[0]); > + return 1; > + } > + > + return generate_bytes(argv[1][0], count); > +} > + > +int cmd__genzeros(int argc, const char **argv) > +{ > + intmax_t count = -1; > + > + if (argc > 2 || > + (argc == 2 && !git_parse_signed(argv[1], &count, INTMAX_MAX))) { > + fprintf(stderr, "usage: %s []\n", argv[0]); > + return 1; > + } > + > + return generate_bytes('\0', count); > +} The callers are so straight-forward. > diff --git a/t/t0613-reftable-write-options.sh b/t/t0613-reftable-write-options.sh > diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh > diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh > diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh All conversions of these consumers are so trivially correct. > diff --git a/t/t9850-shell.sh b/t/t9850-shell.sh > index 27cc49bbd1..d56edebda7 100755 > --- a/t/t9850-shell.sh > +++ b/t/t9850-shell.sh > @@ -30,7 +30,7 @@ test_expect_success 'shell allows interactive command' ' > ' > > test_expect_success 'shell complains of overlong commands' ' > - test-tool genzeros | tr "\000" "a" | > + test-tool genbytes a | > test_must_fail git shell 2>err && > test_grep "too long" err > ' OK, so that's how an infinitely long sequence of characters is used. Looking good. Let's mark the topic as ready for 'next'.