{"thread":{"id":"65014","subject":"[PATCH] t: use test_seq -f and pipes in a few more places","startedAt":"2026-02-18T18:10:55Z","lastAt":"2026-02-19T17:09:59Z","messageCount":2,"participants":["Aaron Plattner","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"536313","messageId":"20260218181019.1705160-1-aplattner@nvidia.com","threadId":"65014","inReplyTo":null,"subject":"[PATCH] t: use test_seq -f and pipes in a few more places","fromName":"Aaron Plattner","fromEmail":"aplattner@nvidia.com","sentAt":"2026-02-18T18:10:19Z","receivedAt":"2026-02-18T18:10:55Z","isPatch":true,"sender":{"key":"aplattner@nvidia.com","avatar":"https://avatars.githubusercontent.com/u/343551?v=4"},"body":"Several tests use a pattern that writes to a temporary file like this:\n\n  printf \"do something with %d\\n\" $(test_seq <count>) >tmpfile &&\n  git do-something --stdin <tmpfile\n\nOther tests use test_seq's -f parameter, but still write to a temporary file:\n\n  test_seq -f \"do something with %d\" <count> >input &&\n  git do-something --stdin <input\n\nSimplify both of these patterns to\n\n  test_seq -f \"do something with %d\" <count> |\n  git do-something --stdin\n\nSigned-off-by: Aaron Plattner <aplattner@nvidia.com>\n---\nSuggested by Peff and Junio in <20260114173055.GD885771@coredump.intra.peff.net>\nand <xmqqcy3cf5xa.fsf@gitster.g> respectively.\n\n t/pack-refs-tests.sh              | 24 ++++++++++--------------\n t/t0613-reftable-write-options.sh | 16 ++++++++--------\n t/t1400-update-ref.sh             |  8 ++++----\n t/t1460-refs-migrate.sh           |  8 ++++----\n t/t5004-archive-corner-cases.sh   |  3 +--\n t/t5401-update-hooks.sh           |  4 ++--\n 6 files changed, 29 insertions(+), 34 deletions(-)\n\ndiff --git a/t/pack-refs-tests.sh b/t/pack-refs-tests.sh\nindex 81086c3690..2fdaccb6c7 100644\n--- a/t/pack-refs-tests.sh\n+++ b/t/pack-refs-tests.sh\n@@ -354,8 +354,8 @@ do\n \n \t\t\t# Create 14 additional references, which brings us to\n \t\t\t# 15 together with the default branch.\n-\t\t\tprintf \"create refs/heads/loose-%d HEAD\\n\" $(test_seq 14) >stdin &&\n-\t\t\tgit update-ref --stdin <stdin &&\n+\t\t\ttest_seq -f \"create refs/heads/loose-%d HEAD\" 14 |\n+\t\t\tgit update-ref --stdin &&\n \t\t\ttest_path_is_missing .git/packed-refs &&\n \t\t\tgit ${pack_refs} --auto --all &&\n \t\t\ttest_path_is_missing .git/packed-refs &&\n@@ -379,8 +379,8 @@ do\n \t\t\ttest_line_count = 2 .git/packed-refs &&\n \n \t\t\t# Create 15 loose references.\n-\t\t\tprintf \"create refs/heads/loose-%d HEAD\\n\" $(test_seq 15) >stdin &&\n-\t\t\tgit update-ref --stdin <stdin &&\n+\t\t\ttest_seq -f \"create refs/heads/loose-%d HEAD\" 15 |\n+\t\t\tgit update-ref --stdin &&\n \t\t\tgit ${pack_refs} --auto --all &&\n \t\t\ttest_line_count = 2 .git/packed-refs &&\n \n@@ -401,18 +401,14 @@ do\n \n \t\t\t# Create 99 packed refs. This should cause the heuristic\n \t\t\t# to require more than the minimum amount of loose refs.\n-\t\t\ttest_seq 99 |\n-\t\t\twhile read i\n-\t\t\tdo\n-\t\t\t\tprintf \"create refs/heads/packed-%d HEAD\\n\" $i || return 1\n-\t\t\tdone >stdin &&\n-\t\t\tgit update-ref --stdin <stdin &&\n+\t\t\ttest_seq -f \"create refs/heads/packed-%d HEAD\" 99 |\n+\t\t\tgit update-ref --stdin &&\n \t\t\tgit ${pack_refs} --all &&\n \t\t\ttest_line_count = 101 .git/packed-refs &&\n \n \t\t\t# Create 24 loose refs, which should not yet cause us to repack.\n-\t\t\tprintf \"create refs/heads/loose-%d HEAD\\n\" $(test_seq 24) >stdin &&\n-\t\t\tgit update-ref --stdin <stdin &&\n+\t\t\ttest_seq -f \"create refs/heads/loose-%d HEAD\" 24 |\n+\t\t\tgit update-ref --stdin &&\n \t\t\tgit ${pack_refs} --auto --all &&\n \t\t\ttest_line_count = 101 .git/packed-refs &&\n \n@@ -420,8 +416,8 @@ do\n \t\t\t# Note that we explicitly do not check for strict\n \t\t\t# boundaries here, as this also depends on the size of\n \t\t\t# the object hash.\n-\t\t\tprintf \"create refs/heads/addn-%d HEAD\\n\" $(test_seq 10) >stdin &&\n-\t\t\tgit update-ref --stdin <stdin &&\n+\t\t\ttest_seq -f \"create refs/heads/addn-%d HEAD\" 10 |\n+\t\t\tgit update-ref --stdin &&\n \t\t\tgit ${pack_refs} --auto --all &&\n \t\t\ttest_line_count = 135 .git/packed-refs\n \t\t)\ndiff --git a/t/t0613-reftable-write-options.sh b/t/t0613-reftable-write-options.sh\nindex e334751759..26b716c75f 100755\n--- a/t/t0613-reftable-write-options.sh\n+++ b/t/t0613-reftable-write-options.sh\n@@ -68,8 +68,8 @@ test_expect_success 'many refs results in multiple blocks' '\n \t(\n \t\tcd repo &&\n \t\ttest_commit initial &&\n-\t\ttest_seq -f \"update refs/heads/branch-%d HEAD\" 200 >input &&\n-\t\tgit update-ref --stdin <input &&\n+\t\ttest_seq -f \"update refs/heads/branch-%d HEAD\" 200 |\n+\t\tgit update-ref --stdin &&\n \t\tgit pack-refs &&\n \n \t\tcat >expect <<-EOF &&\n@@ -178,8 +178,8 @@ test_expect_success 'restart interval at every single record' '\n \t(\n \t\tcd repo &&\n \t\ttest_commit initial &&\n-\t\ttest_seq -f \"update refs/heads/branch-%d HEAD\" 10 >input &&\n-\t\tgit update-ref --stdin <input &&\n+\t\ttest_seq -f \"update refs/heads/branch-%d HEAD\" 10 |\n+\t\tgit update-ref --stdin &&\n \t\tgit -c reftable.restartInterval=1 pack-refs &&\n \n \t\tcat >expect <<-EOF &&\n@@ -218,8 +218,8 @@ test_expect_success 'object index gets written by default with ref index' '\n \t(\n \t\tcd repo &&\n \t\ttest_commit initial &&\n-\t\ttest_seq -f \"update refs/heads/branch-%d HEAD\" 5 >input &&\n-\t\tgit update-ref --stdin <input &&\n+\t\ttest_seq -f \"update refs/heads/branch-%d HEAD\" 5 |\n+\t\tgit update-ref --stdin &&\n \t\tgit -c reftable.blockSize=100 pack-refs &&\n \n \t\tcat >expect <<-EOF &&\n@@ -253,8 +253,8 @@ test_expect_success 'object index can be disabled' '\n \t(\n \t\tcd repo &&\n \t\ttest_commit initial &&\n-\t\ttest_seq -f \"update refs/heads/branch-%d HEAD\" 5 >input &&\n-\t\tgit update-ref --stdin <input &&\n+\t\ttest_seq -f \"update refs/heads/branch-%d HEAD\" 5 |\n+\t\tgit update-ref --stdin &&\n \t\tgit -c reftable.blockSize=100 -c reftable.indexObjects=false pack-refs &&\n \n \t\tcat >expect <<-EOF &&\ndiff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh\nindex db6585b8d8..b2858a9061 100755\n--- a/t/t1400-update-ref.sh\n+++ b/t/t1400-update-ref.sh\n@@ -1380,16 +1380,16 @@ test_expect_success 'fails with duplicate ref update via symref' '\n \n test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches does not burst open file limit' '\n (\n-\ttest_seq -f \"create refs/heads/%d HEAD\" 33 >large_input &&\n-\trun_with_limited_open_files git update-ref --stdin <large_input &&\n+\ttest_seq -f \"create refs/heads/%d HEAD\" 33 |\n+\trun_with_limited_open_files git update-ref --stdin &&\n \tgit rev-parse --verify -q refs/heads/33\n )\n '\n \n test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction deleting branches does not burst open file limit' '\n (\n-\ttest_seq -f \"delete refs/heads/%d HEAD\" 33 >large_input &&\n-\trun_with_limited_open_files git update-ref --stdin <large_input &&\n+\ttest_seq -f \"delete refs/heads/%d HEAD\" 33 |\n+\trun_with_limited_open_files git update-ref --stdin &&\n \ttest_must_fail git rev-parse --verify -q refs/heads/33\n )\n '\ndiff --git a/t/t1460-refs-migrate.sh b/t/t1460-refs-migrate.sh\nindex 0e1116a319..5246468024 100755\n--- a/t/t1460-refs-migrate.sh\n+++ b/t/t1460-refs-migrate.sh\n@@ -276,11 +276,11 @@ test_expect_success 'multiple reftable blocks with multiple entries' '\n \ttest_when_finished \"rm -rf repo\" &&\n \tgit init --ref-format=files repo &&\n \ttest_commit -C repo first &&\n-\tprintf \"create refs/heads/ref-%d HEAD\\n\" $(test_seq 5000) >stdin &&\n-\tgit -C repo update-ref --stdin <stdin &&\n+\ttest_seq -f \"create refs/heads/ref-%d HEAD\" 5000 |\n+\tgit -C repo update-ref --stdin &&\n \ttest_commit -C repo second &&\n-\tprintf \"update refs/heads/ref-%d HEAD\\n\" $(test_seq 3000) >stdin &&\n-\tgit -C repo update-ref --stdin <stdin &&\n+\ttest_seq -f \"update refs/heads/ref-%d HEAD\" 3000 |\n+\tgit -C repo update-ref --stdin &&\n \ttest_migration repo reftable true\n '\n \ndiff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh\nindex 027dedd976..df513a4269 100755\n--- a/t/t5004-archive-corner-cases.sh\n+++ b/t/t5004-archive-corner-cases.sh\n@@ -176,8 +176,7 @@ test_expect_success EXPENSIVE,UNZIP,UNZIP_ZIP64_SUPPORT \\\n \tblob=$(echo $s | git hash-object -w --stdin) &&\n \n \t# create tree containing 65500 entries of that blob\n-\ttest_seq -f \"100644 blob $blob\\t%d\" 1 65500 >tree &&\n-\ttree=$(git mktree <tree) &&\n+\ttree=$(test_seq -f \"100644 blob $blob\\t%d\" 1 65500 | git mktree) &&\n \n \t# zip it, creating an archive a bit bigger than 4GB\n \tgit archive -0 -o many-big.zip $tree &&\ndiff --git a/t/t5401-update-hooks.sh b/t/t5401-update-hooks.sh\nindex 17a46fd3ba..44ec875aef 100755\n--- a/t/t5401-update-hooks.sh\n+++ b/t/t5401-update-hooks.sh\n@@ -134,8 +134,8 @@ test_expect_success 'pre-receive hook that forgets to read its input' '\n \tEOF\n \trm -f victim.git/hooks/update victim.git/hooks/post-update &&\n \n-\tprintf \"create refs/heads/branch_%d main\\n\" $(test_seq 100 999) >input &&\n-\tgit update-ref --stdin <input &&\n+\ttest_seq -f \"create refs/heads/branch_%d main\" 100 999 |\n+\tgit update-ref --stdin &&\n \tgit push ./victim.git \"+refs/heads/*:refs/heads/*\"\n '\n \n-- \n2.53.0\n\n"},{"id":"536420","messageId":"xmqqbjhk7j8a.fsf@gitster.g","threadId":"65014","inReplyTo":"20260218181019.1705160-1-aplattner@nvidia.com","subject":"Re: [PATCH] t: use test_seq -f and pipes in a few more places","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-02-19T17:09:57Z","receivedAt":"2026-02-19T17:09:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Aaron Plattner <aplattner@nvidia.com> writes:\n\n> Several tests use a pattern that writes to a temporary file like this:\n>\n>   printf \"do something with %d\\n\" $(test_seq <count>) >tmpfile &&\n>   git do-something --stdin <tmpfile\n>\n> Other tests use test_seq's -f parameter, but still write to a temporary file:\n>\n>   test_seq -f \"do something with %d\" <count> >input &&\n>   git do-something --stdin <input\n>\n> Simplify both of these patterns to\n>\n>   test_seq -f \"do something with %d\" <count> |\n>   git do-something --stdin\n>\n> Signed-off-by: Aaron Plattner <aplattner@nvidia.com>\n> ---\n> Suggested by Peff and Junio in <20260114173055.GD885771@coredump.intra.peff.net>\n> and <xmqqcy3cf5xa.fsf@gitster.g> respectively.\n\nThis side topic completely slipped my mind.  Thanks for following it\nup.\n\n> diff --git a/t/pack-refs-tests.sh b/t/pack-refs-tests.sh\n> @@ -401,18 +401,14 @@ do\n>  \n>  \t\t\t# Create 99 packed refs. This should cause the heuristic\n>  \t\t\t# to require more than the minimum amount of loose refs.\n> -\t\t\ttest_seq 99 |\n> -\t\t\twhile read i\n> -\t\t\tdo\n> -\t\t\t\tprintf \"create refs/heads/packed-%d HEAD\\n\" $i || return 1\n> -\t\t\tdone >stdin &&\n> -\t\t\tgit update-ref --stdin <stdin &&\n> +\t\t\ttest_seq -f \"create refs/heads/packed-%d HEAD\" 99 |\n> +\t\t\tgit update-ref --stdin &&\n\nNice.\n\nThe original was doubly bad in that it did not even take advantage\nof the fact that printf will iterate over its parameters, but now it\nis nicely packaged up in a single \"test_seq -f\" invocation.\n\n> diff --git a/t/t0613-reftable-write-options.sh b/t/t0613-reftable-write-options.sh\n> index e334751759..26b716c75f 100755\n> -\t\ttest_seq -f \"update refs/heads/branch-%d HEAD\" 10 >input &&\n> -\t\tgit update-ref --stdin <input &&\n> +\t\ttest_seq -f \"update refs/heads/branch-%d HEAD\" 10 |\n> +\t\tgit update-ref --stdin &&\n\nEverything after this patch gets applied follows this pattern, and\nonce the patch is written, this is not important enough to go back\nand fix it, but I do not think it a bad idea to use a temporary file\nin something like this.  If you were hacking on the \"update-ref\"\ncommand and find this test breaking, the first thing you may want to\ndo is to rerun the test with \"-i -v -d\" options, chdir to the\n$TRASH_DIRECTORY left by the failed test, inspect the \"input\" file\nand then run \"../../git-update-ref\" under the debugger.  Not having\nto type the input again while you are doing so would make your life\na bit easier.\n\nThanks.\n"}]}