git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: phillip.wood@dunelm.org.uk,  shejialuo <shejialuo@gmail.com>,
	git@vger.kernel.org,  Kristoffer Haugsbakk <code@khaugsbakk.name>,
	Karthik Nayak <karthik.188@gmail.com>,
	 Eric Sunshine <sunshine@sunshineco.com>
Subject: Re: [PATCH] fsck: ignore missing "refs" directory for linked worktrees
Date: Mon, 02 Jun 2025 12:49:13 -0700	[thread overview]
Message-ID: <xmqq34chudom.fsf@gitster.g> (raw)
In-Reply-To: <aD176UYWKEbmhiaw@pks.im> (Patrick Steinhardt's message of "Mon, 2 Jun 2025 12:24:41 +0200")

Patrick Steinhardt <ps@pks.im> writes:

> On Mon, Jun 02, 2025 at 10:53:50AM +0100, Phillip Wood wrote:
>> Hi Shejialuo
>> 
>> On 31/05/2025 04:39, shejialuo wrote:
>> > diff --git a/refs/files-backend.c b/refs/files-backend.c
>> > index 4d1f65a57a..bf6f89b1d1 100644
>> > --- a/refs/files-backend.c
>> > +++ b/refs/files-backend.c
>> > @@ -3762,6 +3762,9 @@ static int files_fsck_refs_dir(struct ref_store *ref_store,
>> >   	iter = dir_iterator_begin(sb.buf, 0);
>> >   	if (!iter) {
>> > +		if (errno == ENOENT && !is_main_worktree(wt))
>> > +			goto out;
>> > +
>> >   		ret = error_errno(_("cannot open directory %s"), sb.buf);
>> >   		goto out;
>> >   	}
>> 
>> I think it would be clearer to write this as
>> 
>> 	if (is_main_worktree(wt) || errno != ENOENT)
>> 		ret = error_errno(_("cannot open directory %s"), sb.buf);
>> 	goto out;
>> 
>> so that the condition that triggers the error message is explicit rather
>> than having to mentally invert the condition to figure out when we return an
>> error
>
> The downside though is that this mandates that `is_main_worktree()` must
> never set `errno` itself. So while it may be clearer, the original
> version feels safer to me.

FWIW, I found that the logic flow of the original more natural than
the proposed rewrite.  "dir_iterator_begin() appears to have failed
by not returning a usable iterator, so we may need to complain, but
as a special case, we can tolerate missing refs/ hierarchy if we are
not in the primary working tree." was how I read these three
additional lines.



  parent reply	other threads:[~2025-06-02 19:49 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-30 19:00 [BUG] refs: verify does not work if there are v2.43.0 or older worktrees w/o wt. refs kristofferhaugsbakk
2025-05-30 22:23 ` Eric Sunshine
2025-05-31  1:03   ` shejialuo
2025-05-31  9:52   ` Kristoffer Haugsbakk
2025-05-31  3:39 ` [PATCH] fsck: ignore missing "refs" directory for linked worktrees shejialuo
2025-05-31 12:17   ` Kristoffer Haugsbakk
2025-06-02  1:33     ` Junio C Hamano
2025-06-02 11:30     ` shejialuo
2025-06-02  9:53   ` Phillip Wood
2025-06-02 10:24     ` Patrick Steinhardt
2025-06-02 13:50       ` phillip.wood123
2025-06-02 19:49       ` Junio C Hamano [this message]
2025-06-02 12:16     ` shejialuo
2025-06-02 12:41   ` shejialuo
2025-06-02 13:26   ` [PATCH v2 0/1] [BUG] refs: verify does not work if there are v2.43.0 or older worktrees w/o wt. refs shejialuo
2025-06-02 13:29     ` [PATCH v2 1/1] fsck: ignore missing "refs" directory for linked worktrees shejialuo
2025-06-02 13:59       ` Kristoffer Haugsbakk
2025-06-02 14:11         ` shejialuo
2025-06-02 14:40     ` [PATCH v3 0/1] [BUG] refs: verify does not work if there are v2.43.0 or older worktrees w/o wt. refs shejialuo
2025-06-02 14:41       ` [PATCH v3 1/1] fsck: ignore missing "refs" directory for linked worktrees shejialuo
2025-06-02 15:01       ` [PATCH v3 0/1] [BUG] refs: verify does not work if there are v2.43.0 or older worktrees w/o wt. refs Kristoffer Haugsbakk

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=xmqq34chudom.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=code@khaugsbakk.name \
    --cc=git@vger.kernel.org \
    --cc=karthik.188@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=ps@pks.im \
    --cc=shejialuo@gmail.com \
    --cc=sunshine@sunshineco.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).