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

[PATCH 3/1] t3920: simplify redirection of loop output

From
René Scharfe <l.s.r@web.de>
Date
Dec 2, 2022, 16:51 UTC
Message-ID
<9dd8764d-bda9-6602-9ce5-af14de32e315@web.de>
In-Reply-To
<febcfb0a-c410-fb71-cff9-92acfcb269e2@kdbg.org>

Redirect the output of for loops once instead of deleting the receiving file and appending the output of individual commands. This reduces repetition and speeds up the test. Here are the numbers on my Windows machine before:

   $ (cd t && hyperfine.exe -w3 "sh.exe t3920-crlf-messages.sh")
   Benchmark 1: sh.exe t3920-crlf-messages.sh
     Time (mean ± σ):      5.923 s ±  0.037 s    [User: 0.000 s, System: 0.004 s]
     Range (min … max):    5.889 s …  5.997 s    10 runs
... and with this patch:
   Benchmark 1: sh.exe t3920-crlf-messages.sh
     Time (mean ± σ):      5.705 s ±  0.047 s    [User: 0.000 s, System: 0.001 s]
     Range (min … max):    5.632 s …  5.772 s    10 runs
Signed-off-by: René Scharfe <l.s.r@web.de>
---
 t/t3920-crlf-messages.sh | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/t/t3920-crlf-messages.sh b/t/t3920-crlf-messages.sh
index 67fd2345af..4fc9fa9cad 100755
--- a/t/t3920-crlf-messages.sh
+++ b/t/t3920-crlf-messages.sh
@@ -68,12 +68,11 @@ test_crlf_subject_body_and_contents() {
 		set ${atoms} && atom=$1 && shift && atoms="$*" &&
 		set ${files} && file=$1 && shift && files="$*" &&
 		test_expect_success "${command}: --format='%${atom}' works with messages using CRLF" "
-			rm -f expect &&
 			for ref in ${LIB_CRLF_BRANCHES}
 			do
-				cat .crlf-${file}-\"\${ref}\".txt >>expect &&
-				printf \"\n\" >>expect || return 1
-			done &&
+				cat .crlf-${file}-\"\${ref}\".txt &&
+				printf \"\n\" || return 1
+			done >expect &&
 			git $command_and_args --format=\"%${atom}\" >actual &&
 			test_cmp expect actual
 		"
@@ -87,13 +86,12 @@ test_expect_success 'Setup refs with commit and tag messages using CRLF' '
 '

 test_expect_success 'branch: --verbose works with messages using CRLF' '
-	rm -f expect &&
 	for branch in $LIB_CRLF_BRANCHES
 	do
-		printf "  " >>expect &&
-		cat .crlf-subject-${branch}.txt >>expect &&
-		printf "\n" >>expect || return 1
-	done &&
+		printf "  " &&
+		cat .crlf-subject-${branch}.txt &&
+		printf "\n" t || return 1
+	done >expect &&
 	git branch -v >tmp &&
 	# Remove first two columns, and the line for the currently checked out branch
 	current=$(git branch --show-current) &&
--
2.38.1.windows.1
Previous: René ScharfeNext: René Scharfe
Message 18 of 25 in “t3920: don't ignore errors of more than one command with `|| true`”
  1. t3920: don't ignore errors of more than one command with `|| true`Johannes Sixt, Nov 21, 2022
  2. René ScharfeNov 21, 2022
  3. Junio C HamanoNov 22, 2022
  4. Philippe BlainNov 22, 2022
  5. Ævar Arnfjörð BjarmasonNov 22, 2022
  6. Johannes SixtNov 22, 2022
  7. Ævar Arnfjörð BjarmasonNov 22, 2022
  8. Junio C HamanoNov 23, 2022
  9. 2/1 t3920: support CR-eating grepRené Scharfe, Dec 2, 2022
  10. Philippe BlainDec 2, 2022
  11. René ScharfeDec 3, 2022
  12. Eric SunshineDec 2, 2022
  13. René ScharfeDec 3, 2022
  14. Junio C HamanoDec 5, 2022
  15. René ScharfeDec 5, 2022
  16. Junio C HamanoDec 5, 2022
  17. René ScharfeDec 5, 2022
  18. 3/1 t3920: simplify redirection of loop outputRené Scharfe, Dec 2, 2022
  19. 4/1 t3920: replace two cats with a teeRené Scharfe, Dec 2, 2022
  20. Eric SunshineDec 3, 2022
  21. René ScharfeDec 3, 2022
  22. Ævar Arnfjörð BjarmasonDec 3, 2022
  23. René ScharfeDec 3, 2022
  24. Ævar Arnfjörð BjarmasonDec 4, 2022
  25. Eric SunshineDec 4, 2022

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.