git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 1/2] t: add "test-tool genbytes" to avoid slow tr(1) on macOS

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 9, 2026, 06:59 UTC
Message-ID
<avFvYD5K4SKlveiI@pks.im>
In-Reply-To
<54139a3a97127732e11fc5abbc9a3687542669f6.1794165304.git.gitgitgadget@gmail.com>

On Sun, Nov 08, 2026 at 07:15:03PM +0000, Kristofer Karlsson via GitGitGadget wrote: [snip]

Show 9 quoted lines
> This makes t4205 much faster on macOS in CI.  The Linux jobs, shown
> for comparison, only save the few seconds that GNU tr(1) took, which
> is within the usual noise:
> 
>   job                before    after   change
>   osx-gcc            821.1s   243.3s   -70.4%
>   osx-reftable       911.0s   194.0s   -78.7%
>   linux-asan-ubsan   226.7s   222.1s    -2.0%
>   linux-leaks        320.2s   298.8s    -6.7%
Nice improvement.
Show 6 quoted lines
> diff --git a/t/helper/test-genbytes.c b/t/helper/test-genbytes.c
> new file mode 100644
> index 0000000000..b760326b24
> --- /dev/null
> +++ b/t/helper/test-genbytes.c
> @@ -0,0 +1,61 @@

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.
Show 32 quoted lines
> +#define DISABLE_SIGN_COMPARE_WARNINGS
> +
> +#include "test-tool.h"
> +#include "git-compat-util.h"
> +#include "hex-ll.h"
> +
> +/*
> + * Write "count" copies of "byte" to stdout, or an endless stream of them if
> + * "count" is negative.
> + */
> +static int generate_bytes(char byte, intmax_t count)
> +{
> +	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");
> +
> +	while (count > 0) {
> +		n = xwrite(1, buf,
> +			   count < ARRAY_SIZE(buf)
> +			   ? count : ARRAY_SIZE(buf));
> +
> +		if (n < 0)
> +			die_errno("write error");
> +
> +		count -= n;
> +	}

Okay. These two loops are a bit ugly if you ask me, but they are carried over from preexisting code. So this is good enough.

Show 7 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.
Show 13 quoted lines
> diff --git a/t/t0613-reftable-write-options.sh b/t/t0613-reftable-write-options.sh
> index 0b27d75fe3..b2032a799d 100755
> --- a/t/t0613-reftable-write-options.sh
> +++ b/t/t0613-reftable-write-options.sh
> @@ -146,7 +146,7 @@ test_expect_success 'small block size fails with large reflog message' '
>  	(
>  		cd repo &&
>  		test_commit A &&
> -		test-tool genzeros 500 | tr "\000" "a" >logmsg &&
> +		test-tool genbytes 61 500 >logmsg &&
>  		cat >expect <<-EOF &&
>  		fatal: update_ref failed for ref ${SQ}refs/heads/logme${SQ}: reftable: transaction failure: entry too large
>  		EOF
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.

Patrick
Previous: Junio C HamanoNext: Kristofer Karlsson
Message 30 of 39 in “t: add "test-tool genbytes" to avoid slow tr(1) on macOS”
  1. 0/3 t: add "test-tool genbytes" to avoid slow tr(1) on macOSKristofer Karlsson via GitGitGadget, Nov 7, 2026
  2. 1/3 t/helper: rename test-genzeros.c to test-genbytes.cKristofer Karlsson via GitGitGadget, Nov 7, 2026
  3. Junio C HamanoNov 7, 2026
  4. Junio C HamanoNov 8, 2026
  5. Kristofer KarlssonNov 8, 2026
  6. Junio C HamanoNov 8, 2026
  7. Kristofer KarlssonNov 8, 2026
  8. 2/3 t: add "test-tool genbytes" to avoid slow tr(1) on macOSKristofer Karlsson via GitGitGadget, Nov 7, 2026
  9. Johannes SixtNov 8, 2026
  10. Kristofer KarlssonNov 8, 2026
  11. Johannes SixtNov 8, 2026
  12. Kristofer KarlssonNov 8, 2026
  13. Johannes SixtNov 8, 2026
  14. Johannes SixtNov 9, 2026
  15. Kristofer KarlssonNov 9, 2026
  16. Johannes SixtNov 9, 2026
  17. Collin FunkNov 10, 2026
  18. Kristofer KarlssonNov 10, 2026
  19. Junio C HamanoNov 8, 2026
  20. 3/3 t: replace "test-tool genzeros" with "genbytes NUL"Kristofer Karlsson via GitGitGadget, Nov 7, 2026
  21. Junio C HamanoNov 7, 2026
  22. Kristofer KarlssonNov 8, 2026
  23. Junio C HamanoNov 7, 2026
  24. Kristofer KarlssonNov 8, 2026
  25. 0/2 t: add "test-tool genbytes" to avoid slow tr(1) on macOSKristofer Karlsson via GitGitGadget, Nov 8, 2026
  26. 1/2 t: add "test-tool genbytes" to avoid slow tr(1) on macOSKristofer Karlsson via GitGitGadget, Nov 8, 2026
  27. Junio C HamanoNov 9, 2026
  28. Kristofer KarlssonNov 9, 2026
  29. Junio C HamanoNov 9, 2026
  30. Patrick SteinhardtNov 9, 2026
  31. Kristofer KarlssonNov 9, 2026
  32. 2/2 t: replace "test-tool genzeros" with "genbytes 00"Kristofer Karlsson via GitGitGadget, Nov 8, 2026
  33. t: add "test-tool genbytes" to avoid slow tr(1) on macOSKristofer Karlsson via GitGitGadget, Nov 10, 2026
  34. Junio C HamanoNov 10, 2026
  35. Patrick SteinhardtNov 11, 2026
  36. Junio C HamanoNov 11, 2026
  37. Kristofer KarlssonNov 11, 2026
  38. Junio C HamanoNov 11, 2026
  39. t: add "test-tool genbytes" to avoid slow tr(1) on macOSKristofer Karlsson via GitGitGadget, Nov 11, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.