diff mbox series

[05/19] t5516: drop unnecessary subshell and command invocation

Message ID 20211209051115.52629-6-sunshine@sunshineco.com (mailing list archive)
State Accepted
Commit e57ea501d00eab6191993f35e502aface5ceac5e
Headers show
Series tests: fix broken &&-chains & abort loops on error | expand

Commit Message

Eric Sunshine Dec. 9, 2021, 5:11 a.m. UTC
To create its "expect" file, this test pipes into `sort` the output of
`git for-each-ref` and a copy of that same output but with a minor
textual transformation applied. To do so, it employs a subshell and
commands `cat` and `sed` even though the same result can be accomplished
by `sed` alone (without a subshell).

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 t/t5516-fetch-push.sh | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

Jeff King Dec. 10, 2021, 9:10 a.m. UTC | #1
On Thu, Dec 09, 2021 at 12:11:01AM -0500, Eric Sunshine wrote:

> To create its "expect" file, this test pipes into `sort` the output of
> `git for-each-ref` and a copy of that same output but with a minor
> textual transformation applied. To do so, it employs a subshell and
> commands `cat` and `sed` even though the same result can be accomplished
> by `sed` alone (without a subshell).

Clever. The ordering of output from sed is different than the original,
but because it all gets fed into sort anyway, that's OK.

In theory it could change the output of a stable sort of lines which
match (which won't be totally identical, because you are sorting with
-k3), but it seems we don't care in this instance.

-Peff
diff mbox series

Patch

diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 8212ca56dc..d5e19b54af 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -1316,10 +1316,7 @@  test_expect_success 'fetch follows tags by default' '
 		git pull ../testrepo main &&
 		git tag -m "annotated" tag &&
 		git for-each-ref >tmp1 &&
-		(
-			cat tmp1
-			sed -n "s|refs/heads/main$|refs/remotes/origin/main|p" tmp1
-		) |
+		sed -n "p; s|refs/heads/main$|refs/remotes/origin/main|p" tmp1 |
 		sort -k 3 >../expect
 	) &&
 	git init dst &&