# [GSoC] [PATCH 0/1] t0001: replace "test [-d|-f]" with test_path_is_* functions

13 messages from 2022-01-21 to 2022-02-14. Participants: Shaoxuan Yuan, Taylor Blau, Junio C Hamano, Christian Couder.
Thread: https://gitlist.dev/t/57281

## Shaoxuan Yuan, 2022-01-21 10:21

Subject: [GSoC] [PATCH 0/1] t0001: replace "test [-d|-f]" with test_path_is_* functions
Message-ID: <20220121102109.433457-1-shaoxuan.yuan02@gmail.com>
URL: https://gitlist.dev/e/20220121102109.433457-1-shaoxuan.yuan02%40gmail.com

```
As a microproject, I found that the "test [-d|-f]" in t0001 test script
can be replaced by appropriate helper functions.

Shaoxuan Yuan (1):
  t0001-init.sh use test_path_is_* functions

 t/t0001-init.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.25.1


```

## Shaoxuan Yuan, 2022-01-21 10:21

Subject: [GSoC] [PATCH 1/1] t0001: replace "test [-d|-f]" with test_path_is_* functions
Message-ID: <20220121102109.433457-2-shaoxuan.yuan02@gmail.com>
URL: https://gitlist.dev/e/20220121102109.433457-2-shaoxuan.yuan02%40gmail.com
In-Reply-To: <20220121102109.433457-1-shaoxuan.yuan02@gmail.com>

```
Signed-off-by: Shaoxuan Yuan <shaoxuan.yuan02@gmail.com>
---
 t/t0001-init.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 3235ab4d53..c72a28d3a5 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -6,7 +6,7 @@ TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 check_config () {
-	if test -d "$1" && test -f "$1/config" && test -d "$1/refs"
+	if test_path_is_dir "$1" && test_path_is_file "$1/config" && test_path_is_dir "$1/refs"
 	then
 		: happy
 	else
-- 
2.25.1


```

## Taylor Blau, 2022-01-21 18:46

Subject: Re: [GSoC] [PATCH 1/1] t0001: replace "test [-d|-f]" with test_path_is_* functions
Message-ID: <Yer/oEZK6TBFSsde@nand.local>
URL: https://gitlist.dev/e/Yer%2FoEZK6TBFSsde%40nand.local
In-Reply-To: <20220121102109.433457-2-shaoxuan.yuan02@gmail.com>

```
Hi Shaoxuan,

On Fri, Jan 21, 2022 at 06:21:09PM +0800, Shaoxuan Yuan wrote:
> diff --git a/t/t0001-init.sh b/t/t0001-init.sh
> index 3235ab4d53..c72a28d3a5 100755
> --- a/t/t0001-init.sh
> +++ b/t/t0001-init.sh
> @@ -6,7 +6,7 @@ TEST_PASSES_SANITIZE_LEAK=true
>  . ./test-lib.sh
>
>  check_config () {
> -	if test -d "$1" && test -f "$1/config" && test -d "$1/refs"
> +	if test_path_is_dir "$1" && test_path_is_file "$1/config" && test_path_is_dir "$1/refs"
>  	then
>  		: happy
>  	else

Looks very reasonable to me. Indeed, this line comes from 6adcca3fe8
(Fix initialization of a bare repository, 2007-08-27) which predates
2caf20c52b (test-lib: user-friendly alternatives to test [-d|-f|-e],
2010-08-10) when these helpers were originally introduced.

I thought that we could probably just shorten this to calling
"test_path_is_file" twice: once for "$1/config" and a second time for
"$1/refs", but that assumes "$1" is non-empty. And to ensure that you'd
need another check, which amounts to the same amount of code overall.

So the fix here looks good to me, and thanks for your contribution!

Thanks,
Taylor

```

## Junio C Hamano, 2022-01-21 20:49

Subject: Re: [GSoC] [PATCH 1/1] t0001: replace "test [-d|-f]" with test_path_is_* functions
Message-ID: <xmqqr190g6gd.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqr190g6gd.fsf%40gitster.g
In-Reply-To: <Yer/oEZK6TBFSsde@nand.local>

```
Taylor Blau <me@ttaylorr.com> writes:

>> -	if test -d "$1" && test -f "$1/config" && test -d "$1/refs"
>> +	if test_path_is_dir "$1" && test_path_is_file "$1/config" && test_path_is_dir "$1/refs"
>>  	then
>>  		: happy
>>  	else
>
> Looks very reasonable to me. Indeed, this line comes from 6adcca3fe8
> (Fix initialization of a bare repository, 2007-08-27) which predates
> 2caf20c52b (test-lib: user-friendly alternatives to test [-d|-f|-e],
> 2010-08-10) when these helpers were originally introduced.
>
> I thought that we could probably just shorten this to calling
> "test_path_is_file" twice: once for "$1/config" and a second time for
> "$1/refs", but that assumes "$1" is non-empty. And to ensure that you'd
> need another check, which amounts to the same amount of code overall.

I had the same thought.

Since the first "$GIT_DIR must be a directory" matters only when the
caller is crazy enough to have a bare repository at the root of the
filesystem and to think that it is a good idea to say "" is the
"$GIT_DIR" (in which case, "test -d ''" would fail, even though the
tests for /config and /refs are checking the right thing), I do not
see much downside from omitting the first one, but I think that is
something we need to do _outside_ the topic of this change, which is
purely "modernize, using the helpers we already have, without
changing what we do".



```

## Shaoxuan Yuan, 2022-01-24 05:56

Subject: Re: [GSoC] [PATCH 1/1] t0001: replace "test [-d|-f]" with test_path_is_* functions
Message-ID: <CAJyCBORyjNaPXshQrGjbrUCUv832MJsNew6ez-EOWJo2od9a8g@mail.gmail.com>
URL: https://gitlist.dev/e/CAJyCBORyjNaPXshQrGjbrUCUv832MJsNew6ez-EOWJo2od9a8g%40mail.gmail.com
In-Reply-To: <xmqqr190g6gd.fsf@gitster.g>

```
On Sat, Jan 22, 2022 at 4:49 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Taylor Blau <me@ttaylorr.com> writes:
>
> >> -    if test -d "$1" && test -f "$1/config" && test -d "$1/refs"
> >> +    if test_path_is_dir "$1" && test_path_is_file "$1/config" && test_path_is_dir "$1/refs"
> >>      then
> >>              : happy
> >>      else
> >
> > Looks very reasonable to me. Indeed, this line comes from 6adcca3fe8
> > (Fix initialization of a bare repository, 2007-08-27) which predates
> > 2caf20c52b (test-lib: user-friendly alternatives to test [-d|-f|-e],
> > 2010-08-10) when these helpers were originally introduced.
> >
> > I thought that we could probably just shorten this to calling
> > "test_path_is_file" twice: once for "$1/config" and a second time for
> > "$1/refs", but that assumes "$1" is non-empty. And to ensure that you'd
> > need another check, which amounts to the same amount of code overall.
>
> I had the same thought.
>
> Since the first "$GIT_DIR must be a directory" matters only when the
> caller is crazy enough to have a bare repository at the root of the
> filesystem and to think that it is a good idea to say "" is the
> "$GIT_DIR" (in which case, "test -d ''" would fail, even though the
> tests for /config and /refs are checking the right thing), I do not
> see much downside from omitting the first one, but I think that is
> something we need to do _outside_ the topic of this change, which is
> purely "modernize, using the helpers we already have, without
> changing what we do"
>
Yes I feel the same way, one patch for one thing :)

```

## Shaoxuan Yuan, 2022-02-10 03:11

Subject: Re: [GSoC] [PATCH 1/1] t0001: replace "test [-d|-f]" with test_path_is_* functions
Message-ID: <CAJyCBORHE2+UMKYFfKArgK68fAT=pKVabVmfifzg--rHAFkaqg@mail.gmail.com>
URL: https://gitlist.dev/e/CAJyCBORHE2%2BUMKYFfKArgK68fAT%3DpKVabVmfifzg--rHAFkaqg%40mail.gmail.com
In-Reply-To: <xmqqr190g6gd.fsf@gitster.g>

```
Hi Junio,

Since I didn't see this change in seen or next, do you plan to apply it?

--
Thanks,
Shaoxuan

On Sat, Jan 22, 2022 at 4:49 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Taylor Blau <me@ttaylorr.com> writes:
>
> >> -    if test -d "$1" && test -f "$1/config" && test -d "$1/refs"
> >> +    if test_path_is_dir "$1" && test_path_is_file "$1/config" && test_path_is_dir "$1/refs"
> >>      then
> >>              : happy
> >>      else
> >
> > Looks very reasonable to me. Indeed, this line comes from 6adcca3fe8
> > (Fix initialization of a bare repository, 2007-08-27) which predates
> > 2caf20c52b (test-lib: user-friendly alternatives to test [-d|-f|-e],
> > 2010-08-10) when these helpers were originally introduced.
> >
> > I thought that we could probably just shorten this to calling
> > "test_path_is_file" twice: once for "$1/config" and a second time for
> > "$1/refs", but that assumes "$1" is non-empty. And to ensure that you'd
> > need another check, which amounts to the same amount of code overall.
>
> I had the same thought.
>
> Since the first "$GIT_DIR must be a directory" matters only when the
> caller is crazy enough to have a bare repository at the root of the
> filesystem and to think that it is a good idea to say "" is the
> "$GIT_DIR" (in which case, "test -d ''" would fail, even though the
> tests for /config and /refs are checking the right thing), I do not
> see much downside from omitting the first one, but I think that is
> something we need to do _outside_ the topic of this change, which is
> purely "modernize, using the helpers we already have, without
> changing what we do".
>
>

```

## Junio C Hamano, 2022-02-10 07:12

Subject: Re: [GSoC] [PATCH 1/1] t0001: replace "test [-d|-f]" with test_path_is_* functions
Message-ID: <xmqqo83fw5yc.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqo83fw5yc.fsf%40gitster.g
In-Reply-To: <CAJyCBORHE2+UMKYFfKArgK68fAT=pKVabVmfifzg--rHAFkaqg@mail.gmail.com>

```
Shaoxuan Yuan <shaoxuan.yuan02@gmail.com> writes:

> Since I didn't see this change in seen or next, do you plan to apply it?

I actually wasn't, as my understanding of it was primarily your
practice.

```

## Shaoxuan Yuan, 2022-02-10 07:21

Subject: Re: [GSoC] [PATCH 1/1] t0001: replace "test [-d|-f]" with test_path_is_* functions
Message-ID: <CAJyCBOTBcvgAcSaQ4xs-V=M-im_Umf3ymsWzCAGEmrj6b38pEA@mail.gmail.com>
URL: https://gitlist.dev/e/CAJyCBOTBcvgAcSaQ4xs-V%3DM-im_Umf3ymsWzCAGEmrj6b38pEA%40mail.gmail.com
In-Reply-To: <xmqqo83fw5yc.fsf@gitster.g>

```
On Thu, Feb 10, 2022 at 3:12 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Shaoxuan Yuan <shaoxuan.yuan02@gmail.com> writes:
>
> > Since I didn't see this change in seen or next, do you plan to apply it?
>
> I actually wasn't, as my understanding of it was primarily your
> practice.

Understood, thanks for the reply.

--
Thanks,
Shaoxuan

```

## Junio C Hamano, 2022-02-10 17:23

Subject: Re: [GSoC] [PATCH 1/1] t0001: replace "test [-d|-f]" with test_path_is_* functions
Message-ID: <xmqqv8xmvdoa.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqv8xmvdoa.fsf%40gitster.g
In-Reply-To: <CAJyCBOTBcvgAcSaQ4xs-V=M-im_Umf3ymsWzCAGEmrj6b38pEA@mail.gmail.com>

```
Shaoxuan Yuan <shaoxuan.yuan02@gmail.com> writes:

> On Thu, Feb 10, 2022 at 3:12 PM Junio C Hamano <gitster@pobox.com> wrote:
>>
>> Shaoxuan Yuan <shaoxuan.yuan02@gmail.com> writes:
>>
>> > Since I didn't see this change in seen or next, do you plan to apply it?
>>
>> I actually wasn't, as my understanding of it was primarily your
>> practice.
>
> Understood, thanks for the reply.

FWIW, I have the posted patch plus the following SQUASH??? fix-up
parked in the 'seen' branch.  As the script is quiescent right now,
I do not mind merging it down, now we spent more time on it ;-)

 t/t0001-init.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index c72a28d3a5..d479303efa 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -6,7 +6,8 @@ TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 check_config () {
-	if test_path_is_dir "$1" && test_path_is_file "$1/config" && test_path_is_dir "$1/refs"
+	if test_path_is_dir "$1" &&
+	   test_path_is_file "$1/config" && test_path_is_dir "$1/refs"
 	then
 		: happy
 	else
-- 
2.35.1-102-g2b9c120970


```

## Shaoxuan Yuan, 2022-02-11 09:56

Subject: Re: [GSoC] [PATCH 1/1] t0001: replace "test [-d|-f]" with test_path_is_* functions
Message-ID: <CAJyCBOR7KbRxuXJUJ2TrffAjj=rwB3H-Ys9tVUuWGjUKf_LHsw@mail.gmail.com>
URL: https://gitlist.dev/e/CAJyCBOR7KbRxuXJUJ2TrffAjj%3DrwB3H-Ys9tVUuWGjUKf_LHsw%40mail.gmail.com
In-Reply-To: <xmqqv8xmvdoa.fsf@gitster.g>

```
Hi Junio,

On Fri, Feb 11, 2022 at 1:23 AM Junio C Hamano <gitster@pobox.com> wrote:
> FWIW, I have the posted patch plus the following SQUASH??? fix-up

I'm not so sure what does "SQUASH???" mean especially the three
question marks, i.e. is it just an incidental text or a commit message
convention?
Is it for the convenience of grepping through the
"git log" outputs (cause I found the commit 50d631c71c right away by
grepping through the "git log" output)?

> parked in the 'seen' branch.  As the script is quiescent right now,
> I do not mind merging it down, now we spent more time on it ;-)
>
>  t/t0001-init.sh | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/t/t0001-init.sh b/t/t0001-init.sh
> index c72a28d3a5..d479303efa 100755
> --- a/t/t0001-init.sh
> +++ b/t/t0001-init.sh
> @@ -6,7 +6,8 @@ TEST_PASSES_SANITIZE_LEAK=true
>  . ./test-lib.sh
>
>  check_config () {
> -       if test_path_is_dir "$1" && test_path_is_file "$1/config" && test_path_is_dir "$1/refs"
> +       if test_path_is_dir "$1" &&
> +          test_path_is_file "$1/config" && test_path_is_dir "$1/refs"
>         then
>                 : happy
>         else

Yeah, I think wrapping it around is a good idea :-)

> --
> 2.35.1-102-g2b9c120970
>

-- 
Thanks & Regards,
Shaoxuan

```

## Junio C Hamano, 2022-02-11 16:53

Subject: Re: [GSoC] [PATCH 1/1] t0001: replace "test [-d|-f]" with test_path_is_* functions
Message-ID: <xmqqbkzde44v.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqbkzde44v.fsf%40gitster.g
In-Reply-To: <CAJyCBOR7KbRxuXJUJ2TrffAjj=rwB3H-Ys9tVUuWGjUKf_LHsw@mail.gmail.com>

```
Shaoxuan Yuan <shaoxuan.yuan02@gmail.com> writes:

> On Fri, Feb 11, 2022 at 1:23 AM Junio C Hamano <gitster@pobox.com> wrote:
>> FWIW, I have the posted patch plus the following SQUASH??? fix-up
>
> I'm not so sure what does "SQUASH???" mean especially the three
> question marks, i.e. is it just an incidental text or a commit message
> convention?
> Is it for the convenience of grepping through the
> "git log" outputs (cause I found the commit 50d631c71c right away by
> grepping through the "git log" output)?

It is primarily to remind me not to merge the branch down to 'next'
without dealing with it.

> Yeah, I think wrapping it around is a good idea :-)

Then will squash it in and merge it down.

Thanks.

```

## Christian Couder, 2022-02-14 08:45

Subject: Re: [GSoC] [PATCH 1/1] t0001: replace "test [-d|-f]" with test_path_is_* functions
Message-ID: <CAP8UFD3=kd8ACA8PPHyV7fCYLuJSb4Qj2OSdBFJ3RHtnwbGO2A@mail.gmail.com>
URL: https://gitlist.dev/e/CAP8UFD3%3Dkd8ACA8PPHyV7fCYLuJSb4Qj2OSdBFJ3RHtnwbGO2A%40mail.gmail.com
In-Reply-To: <CAJyCBOR7KbRxuXJUJ2TrffAjj=rwB3H-Ys9tVUuWGjUKf_LHsw@mail.gmail.com>

```
On Mon, Feb 14, 2022 at 9:32 AM Shaoxuan Yuan <shaoxuan.yuan02@gmail.com> wrote:
> On Fri, Feb 11, 2022 at 1:23 AM Junio C Hamano <gitster@pobox.com> wrote:
> > FWIW, I have the posted patch plus the following SQUASH??? fix-up
>
> I'm not so sure what does "SQUASH???" mean especially the three
> question marks, i.e. is it just an incidental text or a commit message
> convention?

It means that you might want to squash the fix-up commit or a similar
commit into your commit (or one of your commits in case of a
commit/patch series), and then resubmit a new version.

> Is it for the convenience of grepping through the
> "git log" outputs (cause I found the commit 50d631c71c right away by
> grepping through the "git log" output)?

It is for convenience that it's named "SQUASH???" as everyone (who is
familiar with the mailing list) then knows what needs to be done on
the proposed commit(s).

> > parked in the 'seen' branch.  As the script is quiescent right now,
> > I do not mind merging it down, now we spent more time on it ;-)

Alternatively as Junio says he is ok with merging that down, you might
just accept his offer and he will squash the "SQUASH???" commit for
you before merging the result into the "next" branch.

```

## Shaoxuan Yuan, 2022-02-14 08:53

Subject: Re: [GSoC] [PATCH 1/1] t0001: replace "test [-d|-f]" with test_path_is_* functions
Message-ID: <CAJyCBOTg+5m6s6Nw+ma4Y7RgMe_0GmjyN_f+BBeEc-BhzJi_Qw@mail.gmail.com>
URL: https://gitlist.dev/e/CAJyCBOTg%2B5m6s6Nw%2Bma4Y7RgMe_0GmjyN_f%2BBBeEc-BhzJi_Qw%40mail.gmail.com
In-Reply-To: <CAP8UFD3=kd8ACA8PPHyV7fCYLuJSb4Qj2OSdBFJ3RHtnwbGO2A@mail.gmail.com>

```
On Mon, Feb 14, 2022 at 4:45 PM Christian Couder
<christian.couder@gmail.com> wrote:
>
> On Mon, Feb 14, 2022 at 9:32 AM Shaoxuan Yuan <shaoxuan.yuan02@gmail.com> wrote:
> > On Fri, Feb 11, 2022 at 1:23 AM Junio C Hamano <gitster@pobox.com> wrote:
> > > FWIW, I have the posted patch plus the following SQUASH??? fix-up
> >
> > I'm not so sure what does "SQUASH???" mean especially the three
> > question marks, i.e. is it just an incidental text or a commit message
> > convention?
>
> It means that you might want to squash the fix-up commit or a similar
> commit into your commit (or one of your commits in case of a
> commit/patch series), and then resubmit a new version.
>
> > Is it for the convenience of grepping through the
> > "git log" outputs (cause I found the commit 50d631c71c right away by
> > grepping through the "git log" output)?
>
> It is for convenience that it's named "SQUASH???" as everyone (who is
> familiar with the mailing list) then knows what needs to be done on
> the proposed commit(s).

Yeah, now I see :)

> > > parked in the 'seen' branch.  As the script is quiescent right now,
> > > I do not mind merging it down, now we spent more time on it ;-)
>
> Alternatively as Junio says he is ok with merging that down, you might
> just accept his offer and he will squash the "SQUASH???" commit for
> you before merging the result into the "next" branch.

Yeah, I saw the squashed version in the latest "What's cooking in git.git".
Thanks for the help and suggestions :)

-- 
Thanks & Regards,
Shaoxuan

```
