Re: [PATCH v2 1/2] t: add "test-tool genbytes" to avoid slow tr(1) on macOS
- From
Kristofer Karlsson <krka@spotify.com>
- Date
- Nov 9, 2026, 07:43 UTC
- Message-ID
- <CAL71e4Mrw2h-D+yKLVE30q-7dnkT31CVsyVmktmS9Wx6Xu6ocQ@mail.gmail.com>
- In-Reply-To
- <avFvYD5K4SKlveiI@pks.im>
On Mon, 9 Nov 2026 at 07:59, Patrick Steinhardt <ps@pks.im> wrote:
Show 12 quoted lines
> > Okay. The diff is unfortunately quite useless as we do the file rename > plus all the changes in a single step. It might've been helpful to split > this up into: > > 1. A rename of the file. > > 2. A refactoring of `cmd_genzeros()` to use the write buffer. > > 3. A change to introduce `cmd_genbytes()`. > > But maybe I'm also overdoing this.
v1 had the rename as a separate commit, and Junio preferred to have it squashed into the change. I do not have a strong opinion either way, so I will wait for a consensus before sending v3.
Show 10 quoted lines
>
> > + return 0;
> > +}
> > +
> > +static intmax_t parse_count(int argc, const char **argv, int pos)
> > +{
> > + return pos < argc ? strtoimax(argv[pos], NULL, 0) : -1;
> > +}
>
> We can use `git_parse_signed()` instead.Good idea. It would also reject invalid counts, which are currently silently treated as 0.
Show 12 quoted lines
> I wonder about the regression in readability though. Maybe that's just > me, but I don't happen to know all ASCII values by heart, so if I were > to read this I would now wonder what's so special about 61. And the next > thing to wonder about is whether this is supposed to encode "=" (decimal > 61) or "a" (hexadecimal 61), and without reading the code of genbytes I > would not be able to tell. > > So can we maybe make the underpinning logic a bit more intelligent, e.g. > by accepting "\NNN" or "\xNN" syntax instead of two hex characters? That > might also make it more extensible going forward if the next developer > wants to make genbytes take and repeat strings of arbitrary length > as-is.
That made me look at what the callers actually need:
callers need
t1007 (4x), t5318 NUL bytes
t1051 (2x), t1450 (2x), any byte, only the size matters
t4141
t0613, t4205, t7006, t9850 any byte except NUL and newline
t5300 three different non-NUL bytesSo none of them needs a particular byte value, and the only special case is NUL, which "genzeros" already covers. For everything else, a plain character is the most readable:
Given that, I am now leaning towards keeping "genzeros" as it is and adding "genbytes <char> [<count>]" for the other callers, i.e. going back to v1 without its last patch (and without a separate rename patch). That avoids inventing a syntax for NUL, keeps the call sites readable, and also leaves the existing "genzeros" callers alone, which addresses Johannes' concern about the churn.
Junio, would that be acceptable, given your suggestion to use hex digits so that NUL does not need special treatment?
The rename is perhaps less important to do if genzeros is kept (though it also gains the genbytes function).
Thanks, Kristofer