git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] fsck: ignore missing "refs" directory for linked worktrees

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 2, 2025, 19:49 UTC
Message-ID
<xmqq34chudom.fsf@gitster.g>
In-Reply-To
<aD176UYWKEbmhiaw@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 31 quoted lines
> 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.

Previous: phillip.wood123@gmail.comNext: shejialuo
Message 12 of 21 in “[BUG] refs: verify does not work if there are v2.43.0 or older worktrees w/o wt. refs”
  1. kristofferhaugsbakk@fastmail.comMay 30, 2025
  2. Eric SunshineMay 30, 2025
  3. shejialuoMay 31, 2025
  4. Kristoffer HaugsbakkMay 31, 2025
  5. fsck: ignore missing "refs" directory for linked worktreesshejialuo, May 31, 2025
  6. Kristoffer HaugsbakkMay 31, 2025
  7. Junio C HamanoJun 2, 2025
  8. shejialuoJun 2, 2025
  9. Phillip WoodJun 2, 2025
  10. Patrick SteinhardtJun 2, 2025
  11. phillip.wood123@gmail.comJun 2, 2025
  12. Junio C HamanoJun 2, 2025
  13. shejialuoJun 2, 2025
  14. shejialuoJun 2, 2025
  15. 0/1 [BUG] refs: verify does not work if there are v2.43.0 or older worktrees w/o wt. refsshejialuo, Jun 2, 2025
  16. 1/1 fsck: ignore missing "refs" directory for linked worktreesshejialuo, Jun 2, 2025
  17. Kristoffer HaugsbakkJun 2, 2025
  18. shejialuoJun 2, 2025
  19. 0/1 [BUG] refs: verify does not work if there are v2.43.0 or older worktrees w/o wt. refsshejialuo, Jun 2, 2025
  20. 1/1 fsck: ignore missing "refs" directory for linked worktreesshejialuo, Jun 2, 2025
  21. Kristoffer HaugsbakkJun 2, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.