From: Eric Sunshine <sunshine@sunshineco.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Mahendra Dani <danimahendra0904@gmail.com>,
Patrick Steinhardt <ps@pks.im>,
git@vger.kernel.org
Subject: Re: [PATCH 1/1] t1403: prefer test_path_exists helper function
Date: Tue, 4 Mar 2025 13:07:22 -0500 [thread overview]
Message-ID: <CAPig+cS3QZhZ=W2WfM3T3EngaMOSV37KH4Pqp78QHzOAODtenA@mail.gmail.com> (raw)
In-Reply-To: <xmqqcyewr8j7.fsf@gitster.g>
On Tue, Mar 4, 2025 at 12:49 PM Junio C Hamano <gitster@pobox.com> wrote:
> Eric Sunshine <sunshine@sunshineco.com> writes:
> > On Tue, Mar 4, 2025 at 7:05 AM Junio C Hamano <gitster@pobox.com> wrote:
> >> Mahendra Dani <danimahendra0904@gmail.com> writes:
> >> >> > remove_object() {
> >> >> > file=$(sha1_file "$*") &&
> >> >> > - test -e "$file" &&
> >> >> > + test_path_exists "$file" &&
> >> >> > rm -f "$file"
> >> >> > } &&
> > That's a good question to ask, but isn't the implied suggestion of
> > dropping "-f" going in the wrong direction? If I'm reading
> > remove_object() correctly, `test -e` is being used as control flow,
> > *not* as an assertion that the file exists.
>
> If sha1_file says the loose object must be at path $file, and the
> call to test -e "$file" returns false, two things happen in this
> function:
>
> (1) control stops and "rm -f" does not trigger
> (2) the function returns non-zero status to the caller
True enough. I was misreading `test -e "$file"` as _only_ control flow.
However, it's still not clear to me why this function is making the
`test -e "$file"` assertion in the first place or why the enclosing
test should care, especially since that assertion is only checking
that `git commit` worked correctly, but that's not the intent of this
particular test[1]. So, `test -e "$file"` seems pointless or at least
misleading.
> If you omit the check and say rm "$file" instead, under the same
> scenario, (1) "rm" is attempted, but there is nothing to remove so
> the command returns non-zero status, and (2) the function returns
> that non-zero status to the caller
Yes, I understood the implication of your suggestion, but as mentioned
above, it's not clear (at least to me) why `test -e "$file"` is there
at all since this test is not about checking functionality of `git
commit`.
[1]: d01b8203ec (show-ref: detect dangling refs under --verify as
well, 2017-01-23) doesn't explain why `test -e "$file"` was used.
next prev parent reply other threads:[~2025-03-04 18:07 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-01 10:58 [GSOC][PATCH 0/1] t1403: prefer test_path_exists helper function Mahendra Dani
2025-03-01 10:58 ` [PATCH 1/1] " Mahendra Dani
2025-03-03 10:26 ` Patrick Steinhardt
2025-03-04 2:27 ` Mahendra Dani
2025-03-04 12:05 ` Junio C Hamano
2025-03-04 17:24 ` Mahendra Dani
2025-03-04 17:26 ` Junio C Hamano
2025-03-04 17:35 ` Mahendra Dani
2025-03-04 17:44 ` Junio C Hamano
2025-03-04 17:49 ` Mahendra Dani
2025-03-04 18:07 ` Junio C Hamano
2025-03-04 17:35 ` Eric Sunshine
2025-03-04 17:49 ` Junio C Hamano
2025-03-04 18:07 ` Eric Sunshine [this message]
2025-03-04 18:28 ` Eric Sunshine
2025-03-04 18:30 ` Junio C Hamano
2025-03-04 9:15 ` [GSOC][PATCH v2 0/1] t1403: verify path exists and is a file Mahendra Dani
2025-03-04 9:41 ` [GSOC][PATCH v3 " Mahendra Dani
2025-03-04 9:41 ` [PATCH v3 1/1] t1403: verify that " Mahendra Dani
2025-03-04 18:05 ` Junio C Hamano
2025-03-04 18:06 ` Junio C Hamano
2025-03-04 18:13 ` Mahendra Dani
2025-03-04 11:23 ` [PATCH v4 0/1] t1403: verify " Mahendra Dani
2025-03-04 11:27 ` Mahendra Dani
2025-03-04 11:27 ` [PATCH v4 1/1] t1403: verify that " Mahendra Dani
2025-03-04 18:13 ` Junio C Hamano
2025-03-04 18:19 ` Mahendra Dani
2025-03-04 16:00 ` [GSOC][PATCH v3 0/1] t1403: verify " Junio C Hamano
2025-03-04 9:27 ` [PATCH v2 1/1] t1403: verify that " Mahendra Dani
2025-03-04 11:02 ` Patrick Steinhardt
2025-03-04 11:15 ` Mahendra Dani
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='CAPig+cS3QZhZ=W2WfM3T3EngaMOSV37KH4Pqp78QHzOAODtenA@mail.gmail.com' \
--to=sunshine@sunshineco.com \
--cc=danimahendra0904@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=ps@pks.im \
/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).