git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] lib-submodule-update.sh: drop unneeded shell
@ 2017-01-11 18:47 Stefan Beller
  2017-01-13 18:40 ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Beller @ 2017-01-11 18:47 UTC (permalink / raw)
  To: gitster; +Cc: git, Stefan Beller

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

Signed-off-by: Stefan Beller <sbeller@google.com>
---

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(-)

diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 79cdd34a54..915eb4a7c6 100755
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -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.11.0.259.g7b30ecf4f0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] lib-submodule-update.sh: drop unneeded shell
  2017-01-11 18:47 [PATCH] lib-submodule-update.sh: drop unneeded shell Stefan Beller
@ 2017-01-13 18:40 ` Junio C Hamano
  2017-01-13 19:03   ` [PATCH] lib-submodule-update.sh: reduce use of subshell by using git -C <dir> Stefan Beller
  2017-01-13 19:55   ` [PATCH] lib-submodule-update.sh: drop unneeded shell Junio C Hamano
  0 siblings, 2 replies; 6+ messages in thread
From: Junio C Hamano @ 2017-01-13 18:40 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git

Stefan Beller <sbeller@google.com> writes:

> 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.

> 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.

>
> 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(-)
>
> diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
> index 79cdd34a54..915eb4a7c6 100755
> --- a/t/lib-submodule-update.sh
> +++ b/t/lib-submodule-update.sh
> @@ -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" &&

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] lib-submodule-update.sh: reduce use of subshell by using git -C <dir>
  2017-01-13 18:40 ` Junio C Hamano
@ 2017-01-13 19:03   ` Stefan Beller
  2017-01-13 19:55   ` [PATCH] lib-submodule-update.sh: drop unneeded shell Junio C Hamano
  1 sibling, 0 replies; 6+ messages in thread
From: Stefan Beller @ 2017-01-13 19:03 UTC (permalink / raw)
  To: gitster; +Cc: git, Stefan Beller

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

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 t/lib-submodule-update.sh | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 79cdd34a54..915eb4a7c6 100755
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -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.11.0.300.g08194d1431


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] lib-submodule-update.sh: drop unneeded shell
  2017-01-13 18:40 ` Junio C Hamano
  2017-01-13 19:03   ` [PATCH] lib-submodule-update.sh: reduce use of subshell by using git -C <dir> Stefan Beller
@ 2017-01-13 19:55   ` Junio C Hamano
  2017-01-13 20:01     ` Stefan Beller
  1 sibling, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2017-01-13 19:55 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git

Junio C Hamano <gitster@pobox.com> writes:

> Stefan Beller <sbeller@google.com> writes:
>
>> 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 <sbeller@google.com>
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.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 79cdd34a54..915eb4a7c6 100755
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -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" &&

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] lib-submodule-update.sh: drop unneeded shell
  2017-01-13 19:55   ` [PATCH] lib-submodule-update.sh: drop unneeded shell Junio C Hamano
@ 2017-01-13 20:01     ` Stefan Beller
  2017-01-13 20:19       ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Beller @ 2017-01-13 20:01 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org

On Fri, Jan 13, 2017 at 11:55 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Stefan Beller <sbeller@google.com> writes:
>>
>>> 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.

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] lib-submodule-update.sh: drop unneeded shell
  2017-01-13 20:01     ` Stefan Beller
@ 2017-01-13 20:19       ` Junio C Hamano
  0 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2017-01-13 20:19 UTC (permalink / raw)
  To: Stefan Beller; +Cc: git@vger.kernel.org

Stefan Beller <sbeller@google.com> writes:

> On Fri, Jan 13, 2017 at 11:55 AM, Junio C Hamano <gitster@pobox.com> wrote:
>> Junio C Hamano <gitster@pobox.com> writes:
>>
>>> Stefan Beller <sbeller@google.com> writes:
>>>
>>>> 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.
>
> 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.



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-01-13 20:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-11 18:47 [PATCH] lib-submodule-update.sh: drop unneeded shell Stefan Beller
2017-01-13 18:40 ` Junio C Hamano
2017-01-13 19:03   ` [PATCH] lib-submodule-update.sh: reduce use of subshell by using git -C <dir> Stefan Beller
2017-01-13 19:55   ` [PATCH] lib-submodule-update.sh: drop unneeded shell Junio C Hamano
2017-01-13 20:01     ` Stefan Beller
2017-01-13 20:19       ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).