git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Chandra Pratap via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,  Chandra Pratap <chandrapratap376@gmail.com>,
	Chandra Pratap <chandrapratap3519@gmail.com>
Subject: Re: [PATCH v2] t9146: replace test -d/-e/-f with appropriate test_path_is_* function
Date: Mon, 12 Feb 2024 12:31:00 -0800	[thread overview]
Message-ID: <xmqq7cj95ssb.fsf@gitster.g> (raw)
In-Reply-To: <pull.1661.v2.git.1707765433663.gitgitgadget@gmail.com> (Chandra Pratap via GitGitGadget's message of "Mon, 12 Feb 2024 19:17:13 +0000")

"Chandra Pratap via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Chandra Pratap <chandrapratap3519@gmail.com>
>
> The helper functions test_path_is_* provide better debugging
> information than test -d/-e/-f.

Correct.

> Replace "if ! test -d then <error message>" with "test_path_exists"
> and "test -d" with "test_path_is_dir" at places where we check for
> existent directories.

The former could result in misconversion, if the intention of the
test was "we cannot have directory here; a regular file is OK", so
we have to be a bit more careful than mechanical conversion.

> Replace "test -f" with "test_path_is_file" at places where we check
> for existent files.

OK.

> Replace "test ! -e" with "test_path_is_missing" where we check for
> non-existent directories.

OK.

>  		for i in a b c d d/e d/e/f "weird file name"
>  		do
> -			if ! test -d "$i"
> -			then
> -				echo >&2 "$i does not exist" &&
> -				exit 1
> -			fi
> +			test_path_exists "$i" || exit 1

We were saying that we are OK if "$i" existed as a file (not a
directory), but now we complain regardless of what "$i" is.  Is that
closer to what the test originally wanted to do?  Just checking.

>  		done
>  	)
>  '
> @@ -37,11 +33,7 @@ test_expect_success 'option automkdirs set to false' '
>  		git svn fetch &&
>  		for i in a b c d d/e d/e/f "weird file name"
>  		do
> -			if test -d "$i"
> -			then
> -				echo >&2 "$i exists" &&
> -				exit 1
> -			fi
> +			test_path_is_missing "$i" || exit 1

Ditto; are we sure the intention of the original is that nothing
should be at "$i" (instead of "as long as it is not a directory,
we are OK")?  Just checking.

The same comment applies to all conversions to test_path_exists and
test_path_is_missing where the original was not "test -e" or "! test -e".
The other ones, like the change from "test -f" to "test_path_is_file",
looked all correct.

Thanks.



  reply	other threads:[~2024-02-12 20:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-11 14:53 [PATCH] t9146: replace test -d/-f with appropriate test_path_is_* function Chandra Pratap via GitGitGadget
2024-02-11 17:58 ` Eric Sunshine
2024-02-12 19:17 ` [PATCH v2] t9146: replace test -d/-e/-f " Chandra Pratap via GitGitGadget
2024-02-12 20:31   ` Junio C Hamano [this message]
2024-02-14 17:50   ` [PATCH v3] " Chandra Pratap via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq7cj95ssb.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=chandrapratap3519@gmail.com \
    --cc=chandrapratap376@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).