Skip to contentSkip to conversation

lib-submodule-update.sh: drop unneeded shell

PATCH In review Stefan Beller 2 participants 6 messages Jan 11, 2017 – Jan 13, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib-submodule-update.sh: drop unneeded shell

In modern Git we prefer "git -C <cmd" over "(cd <somewhere && git <cmd>)" as it doesn't need an extra shell.

---

And because it is in a setup function, we actually save the invocation of 22 shells for a single run of the whole test suite.

Noticed while adding a lot more in near vincinity, though not as near to cause merge conflicts, so sending it extra.

Thanks,
Stefan

 t/lib-submodule-update.sh | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
t/lib-submodule-update.sh +1 -4
index 79cdd34a54..915eb4a7c6 100755
@@ -69,10 +69,7 @@ create_lib_submodule_repo () {
 
 		git checkout -b "replace_sub1_with_directory" "add_sub1" &&
 		git submodule update &&
-		(
-			cd sub1 &&
-			git checkout modifications
-		) &&
+		git -C sub1 checkout modifications &&
 		git rm --cached sub1 &&
 		rm sub1/.git* &&
 		git config -f .gitmodules --remove-section "submodule.sub1" &&
Signature · 1 line
2.11.0.259.g7b30ecf4f0
#1 lore raw
Quoted 2 lines · Stefan Beller

In modern Git we prefer "git -C <cmd" over "(cd <somewhere && git <cmd>)" as it doesn't need an extra shell.

There is a matching '>' missing. The description is correct (I am not sure if there actually is "preference", though), but I found the title a bit misleading. With 'drop unneeded subshell', I would imagine a patch like

		(
	-		( do something )
	+		do something;
			do something else;
		)

It looks more like "reduce use of subshell by using 'git -C <dir>'" to me.

Quoted 2 lines

And because it is in a setup function, we actually save the invocation of 22 shells for a single run of the whole test suite.

Nice.

Quoted 26 lines

Noticed while adding a lot more in near vincinity, though not as near to cause merge conflicts, so sending it extra.

Thanks,
Stefan

 t/lib-submodule-update.sh | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
t/lib-submodule-update.sh +1 -4
index 79cdd34a54..915eb4a7c6 100755
@@ -69,10 +69,7 @@ create_lib_submodule_repo () {
 
 		git checkout -b "replace_sub1_with_directory" "add_sub1" &&
 		git submodule update &&
-		(
-			cd sub1 &&
-			git checkout modifications
-		) &&
+		git -C sub1 checkout modifications &&
 		git rm --cached sub1 &&
 		rm sub1/.git* &&
 		git config -f .gitmodules --remove-section "submodule.sub1" &&
#2 lore raw

PATCH 1/1 lib-submodule-update.sh: reduce use of subshell by using git -C <dir>

In modern Git we prefer

    "git -C <cmd>"
over
    "(cd <somewhere && git <cmd>)"

as it doesn't need an extra shell.

---
 t/lib-submodule-update.sh | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
t/lib-submodule-update.sh +1 -4
index 79cdd34a54..915eb4a7c6 100755
@@ -69,10 +69,7 @@ create_lib_submodule_repo () {
 
 		git checkout -b "replace_sub1_with_directory" "add_sub1" &&
 		git submodule update &&
-		(
-			cd sub1 &&
-			git checkout modifications
-		) &&
+		git -C sub1 checkout modifications &&
 		git rm --cached sub1 &&
 		rm sub1/.git* &&
 		git config -f .gitmodules --remove-section "submodule.sub1" &&
Signature · 1 line
2.11.0.300.g08194d1431
#3 lore raw
In reply to Junio C Hamano
Quoted 8 lines · Junio C Hamano
Quoted 2 lines · Stefan Beller

In modern Git we prefer "git -C <cmd" over "(cd <somewhere && git <cmd>)" as it doesn't need an extra shell.

There is a matching '>' missing. The description is correct (I am not sure if there actually is "preference", though), but I found the title a bit misleading....

It turns out that there were two missing '>' ;-) It tentatively has become like this in my tree.

-- >8 --
From: Stefan Beller <[email protected]>
Date: Wed, 11 Jan 2017 10:47:32 -0800
Subject: [PATCH] lib-submodule-update.sh: reduce use of subshell by using "git -C"

We write

    (cd <dir> && git <cmd>)

to avoid

    cd <dir> && git <cmd> && cd ..

that allows a breakage in one part of the test script to leave the entire test process in an unexpected place. We can do this more concisely with "git -C <dir> <cmd>" with modern Git.

t/lib-submodule-update.sh +1 -4
index 79cdd34a54..915eb4a7c6 100755
@@ -69,10 +69,7 @@ create_lib_submodule_repo () {
 
 		git checkout -b "replace_sub1_with_directory" "add_sub1" &&
 		git submodule update &&
-		(
-			cd sub1 &&
-			git checkout modifications
-		) &&
+		git -C sub1 checkout modifications &&
 		git rm --cached sub1 &&
 		rm sub1/.git* &&
 		git config -f .gitmodules --remove-section "submodule.sub1" &&
#4 lore raw
Quoted 7 lines · Junio C Hamano
Quoted 5 lines · Junio C Hamano
Quoted 2 lines · Stefan Beller

In modern Git we prefer "git -C <cmd" over "(cd <somewhere && git <cmd>)" as it doesn't need an extra shell.

Quoted 6 lines
Quoted 3 lines

There is a matching '>' missing. The description is correct (I am not sure if there actually is "preference", though), but I found the title a bit misleading....

It turns out that there were two missing '>' ;-) It tentatively has become like this in my tree.

Thanks for fixing up locally. I had resent as
"[PATCH] lib-submodule-update.sh: reduce use of subshell by using git -C <dir>" but you can ignore that now.

Thank,
Stefan

#5 lore raw
Quoted 12 lines · Stefan Beller
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · Junio C Hamano
Quoted 2 lines · Stefan Beller

In modern Git we prefer "git -C <cmd" over "(cd <somewhere && git <cmd>)" as it doesn't need an extra shell.

There is a matching '>' missing. The description is correct (I am not sure if there actually is "preference", though), but I found the title a bit misleading....

Quoted 6 lines
Quoted 2 lines

It turns out that there were two missing '>' ;-) It tentatively has become like this in my tree.

Thanks for fixing up locally. I had resent as
"[PATCH] lib-submodule-update.sh: reduce use of subshell by using git -C <dir>" but you can ignore that now.

Yeah, apparently our mails crossed. Yours still have "git -C <cmd>" that should have been "git -C <dir> <cmd>", so I'll keep the locally munged one.

Thanks.