public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Aaron Plattner <aplattner@nvidia.com>
Cc: <git@vger.kernel.org>
Subject: Re: [PATCH] t: use test_seq -f and pipes in a few more places
Date: Thu, 19 Feb 2026 09:09:57 -0800	[thread overview]
Message-ID: <xmqqbjhk7j8a.fsf@gitster.g> (raw)
In-Reply-To: <20260218181019.1705160-1-aplattner@nvidia.com> (Aaron Plattner's message of "Wed, 18 Feb 2026 10:10:19 -0800")

Aaron Plattner <aplattner@nvidia.com> writes:

> Several tests use a pattern that writes to a temporary file like this:
>
>   printf "do something with %d\n" $(test_seq <count>) >tmpfile &&
>   git do-something --stdin <tmpfile
>
> Other tests use test_seq's -f parameter, but still write to a temporary file:
>
>   test_seq -f "do something with %d" <count> >input &&
>   git do-something --stdin <input
>
> Simplify both of these patterns to
>
>   test_seq -f "do something with %d" <count> |
>   git do-something --stdin
>
> Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
> ---
> Suggested by Peff and Junio in <20260114173055.GD885771@coredump.intra.peff.net>
> and <xmqqcy3cf5xa.fsf@gitster.g> respectively.

This side topic completely slipped my mind.  Thanks for following it
up.

> diff --git a/t/pack-refs-tests.sh b/t/pack-refs-tests.sh
> @@ -401,18 +401,14 @@ do
>  
>  			# Create 99 packed refs. This should cause the heuristic
>  			# to require more than the minimum amount of loose refs.
> -			test_seq 99 |
> -			while read i
> -			do
> -				printf "create refs/heads/packed-%d HEAD\n" $i || return 1
> -			done >stdin &&
> -			git update-ref --stdin <stdin &&
> +			test_seq -f "create refs/heads/packed-%d HEAD" 99 |
> +			git update-ref --stdin &&

Nice.

The original was doubly bad in that it did not even take advantage
of the fact that printf will iterate over its parameters, but now it
is nicely packaged up in a single "test_seq -f" invocation.

> diff --git a/t/t0613-reftable-write-options.sh b/t/t0613-reftable-write-options.sh
> index e334751759..26b716c75f 100755
> -		test_seq -f "update refs/heads/branch-%d HEAD" 10 >input &&
> -		git update-ref --stdin <input &&
> +		test_seq -f "update refs/heads/branch-%d HEAD" 10 |
> +		git update-ref --stdin &&

Everything after this patch gets applied follows this pattern, and
once the patch is written, this is not important enough to go back
and fix it, but I do not think it a bad idea to use a temporary file
in something like this.  If you were hacking on the "update-ref"
command and find this test breaking, the first thing you may want to
do is to rerun the test with "-i -v -d" options, chdir to the
$TRASH_DIRECTORY left by the failed test, inspect the "input" file
and then run "../../git-update-ref" under the debugger.  Not having
to type the input again while you are doing so would make your life
a bit easier.

Thanks.

      reply	other threads:[~2026-02-19 17:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-18 18:10 [PATCH] t: use test_seq -f and pipes in a few more places Aaron Plattner
2026-02-19 17:09 ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqbjhk7j8a.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=aplattner@nvidia.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox