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

[PATCH 4/1] t3920: replace two cats with a tee

From
René Scharfe <l.s.r@web.de>
Date
Dec 2, 2022, 16:51 UTC
Message-ID
<203cb627-2423-8a35-d280-9f9ffc66e072@web.de>
In-Reply-To
<febcfb0a-c410-fb71-cff9-92acfcb269e2@kdbg.org>

Use tee(1) to replace two calls of cat(1) for writing files with different line endings. That's shorter and spawns less processes.

It has a small, but measurable performance impact on my Windows machine. Here are the numbers before:

   $ (cd t && hyperfine.exe -w3 "sh.exe t3920-crlf-messages.sh")
   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
... and with this patch:
   $ (cd t && hyperfine.exe -w3 "sh.exe t3920-crlf-messages.sh")
   Benchmark 1: sh.exe t3920-crlf-messages.sh
     Time (mean ± σ):      5.616 s ±  0.021 s    [User: 0.001 s, System: 0.002 s]
     Range (min … max):    5.577 s …  5.644 s    10 runs
Signed-off-by: René Scharfe <l.s.r@web.de>
---
 t/t3920-crlf-messages.sh | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/t/t3920-crlf-messages.sh b/t/t3920-crlf-messages.sh
index 4fc9fa9cad..1f64ce565f 100755
--- a/t/t3920-crlf-messages.sh
+++ b/t/t3920-crlf-messages.sh
@@ -9,8 +9,7 @@ LIB_CRLF_BRANCHES=""

 create_crlf_ref () {
 	branch="$1" &&
-	cat >.crlf-orig-$branch.txt &&
-	cat .crlf-orig-$branch.txt | append_cr >.crlf-message-$branch.txt &&
+	tee .crlf-orig-$branch.txt | append_cr >.crlf-message-$branch.txt &&
 	grep 'Subject' .crlf-orig-$branch.txt | tr '\n' ' ' | sed 's/[ ]*$//' | tr -d '\n' >.crlf-subject-$branch.txt &&
 	grep 'Body' .crlf-orig-$branch.txt | append_cr >.crlf-body-$branch.txt &&
 	LIB_CRLF_BRANCHES="${LIB_CRLF_BRANCHES} ${branch}" &&
--
2.38.1.windows.1
Previous: René ScharfeNext: Eric Sunshine
Message 19 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.