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

Re: [PATCH v2] refs/files: skip lock files during consistency checks

From
Karthik Nayak <karthik.188@gmail.com>
Date
Apr 22, 2026, 12:04 UTC
Message-ID
<CAOLa=ZT1zE+MLeaYE_5jWmNzSvtTTBw3ZAopai+2Ei27kmYm2g@mail.gmail.com>
In-Reply-To
<aeil2Q_Mh_fKCwGa@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 14 quoted lines
> On Wed, Apr 22, 2026 at 11:49:58AM +0200, Karthik Nayak wrote:
>> Consistency checks in the files reference backend involve two steps:
>>
>> 1. Iterate over all entries within the 'refs/' directory and call
>> `files_fsck_ref()` on each.
>> 2. Iterate over all root refs via `for_each_root_ref()` and call
>> `files_fsck_ref()` on each.
>>
>> `files_fsck_ref()` then runs all fsck checks defined in
>> `fsck_refs_fn[]`. Step 2 goes through the refs API and only sees valid
>> refs, but step 1 iterates the directory directly and will also encounter
>
> Nit, obviously not worth a reroll: maybe do s/will/may/?
>

I thought will would go with 'intermediate' better, but 'may' is the right choice I guess. Will add it in locally.

Show 32 quoted lines
>> intermediate '*.lock' files.
>>
>> Currently, `files_fsck_refs_name()`, one of the functions in
>> `fsck_refs_fn[]`, filters out lock files itself. The other function,
>> `files_fsck_refs_content()`, has no such check and would parse the lock
>> file. Any new function added to `fsck_refs_fn[]` would have the same
>> problem.
>>
>> Move the filter up into `files_fsck_refs_dir()`, where the directory
>> iteration happens. Since step 2 cannot produce lock files, this is the
>> only site where the filter is needed, and individual checks no longer
>> have to re-implement it.
>
> Makes sense.
>
>> diff --git a/refs/files-backend.c b/refs/files-backend.c
>> index b3b0c25f84..1504a1e2f3 100644
>> --- a/refs/files-backend.c
>> +++ b/refs/files-backend.c
>> @@ -3962,6 +3953,15 @@ static int files_fsck_refs_dir(struct ref_store *ref_store,
>>  			strbuf_addf(&refname, "worktrees/%s/", wt->id);
>>  		strbuf_addf(&refname, "refs/%s", iter->relative_path);
>>
>> +		filename = basename((char *) iter->path.buf);
>
> Not a new issue, but this cast made me wonder. As it turns out,
> basename(3p) is documented as "may modify the string pointed to by
> path". I assume that this can happen if the path itself ends with a
> slash for example, as in that case the basename should of course not
> include the slash itself. So maybe it modifies the caller-provided path
> directly in that case?
>

I guess it depends on the implementation, the glibc for example doesn't seem to [1].

Show 5 quoted lines
> In any case, it shouldn't be much of an issue as we only use this on
> discovered path names, and those cannot contain contain a trailing
> slash.
>
> Patrick

Yeah we should be fine here. Thanks for the review. I'll avoid re-rolling for now and see if there are other changes needed.

[1]: https://sourceware.org/git/?p=glibc.git;a=blob;f=string/basename.c;h=1658ba98d3ff89e8257b36219599184866798d0d;hb=refs/heads/master
Previous: Patrick SteinhardtNext: Karthik Nayak
Message 9 of 10 in “refs/files: skip lock files during consistency checks”
  1. refs/files: skip lock files during consistency checksKarthik Nayak, Apr 20, 2026
  2. Junio C HamanoApr 20, 2026
  3. Karthik NayakApr 21, 2026
  4. Christian CouderApr 21, 2026
  5. Karthik NayakApr 21, 2026
  6. Karthik NayakApr 21, 2026
  7. refs/files: skip lock files during consistency checksKarthik Nayak, Apr 22, 2026
  8. Patrick SteinhardtApr 22, 2026
  9. Karthik NayakApr 22, 2026
  10. refs/files: skip lock files during consistency checksKarthik Nayak, May 17, 2026

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.