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

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

From
Karthik Nayak <karthik.188@gmail.com>
Date
Apr 21, 2026, 13:22 UTC
Message-ID
<CAOLa=ZSj_fmDNo5bgtYeRs0piCq+QR4aydDtRsqK19nPnDFvbw@mail.gmail.com>
In-Reply-To
<CAP8UFD2vO415UfEUw34_Whh3bTG0ECV99APH=uaDyiGLiNq1yw@mail.gmail.com>
Christian Couder <christian.couder@gmail.com> writes:
Show 26 quoted lines
> On Mon, Apr 20, 2026 at 5:21 PM Karthik Nayak <karthik.188@gmail.com> wrote:
>
>> @@ -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);
>> +
>> +               /*
>> +                * Ignore the files ending with ".lock" as they may be lock files
>> +                * However, do not allow bare ".lock" files.
>> +                */
>> +               if (filename[0] != '.' && ends_with(filename, ".lock"))
>> +                       continue;
>> +
>>                 if (files_fsck_ref(ref_store, o, refname.buf,
>>                                    iter->path.buf, iter->st.st_mode) < 0)
>>                         ret = -1;
>
> This just moves code and associated comments, so the following are
> probably pre-existing issues, but still it seems to me that:
>
> - "do not allow" is not quite what is actually done. There is no ret =
> -1 set for example, so if files_fsck_ref() succeeds with the ".lock"
> file it could be allowed, or I am missing something?
>

The intent was the same before too, we didn't want to ignore bare '.lock' files. Then, we raised an error and we'll do the same now. 'do not allow' is a bit confusing though, will amend it.

> - a filename like ".stuff.lock" would be treated in the same way as
> ".lock". I wonder if it's what we want.
>

Good catch, we only want to ignore reference lock files, these are files which have a preceding text before the '.lock' text. We could simply check the strlen of the path instead.

Show 17 quoted lines
> Maybe ".lock" or ".stuff.lock" would fail a check_refname_format()
> somewhere, if they are not ignored, but it's still a bit confusing.
>
> It seems to me that either:
>
> 1) we want to ignore all files that end with ".lock" as they might be
> used by some tool as lockfiles, and then:
>
>                if (ends_with(iter->path.buf, ".lock"))
>                        continue;
>
> is enough, or
>
> 2) we want to check that all files matching "XXXX.lock" correspond to
> a valid XXXX ref, and then we should not completely ignore them, just
> ignore their content but check the XXXX part.
>

This would be the most idea solution, but practically it gets complicated. The lock files are created for all reference operations, for new references the lock file would be created before the reference exits and we could encounter such a state.

Also there could be a lock file created for a reference update, while the reference itself is packed.

So to keep it simple, we simply skip/ignore lock files.
Show 5 quoted lines
> For a bug fix, I think implementing 1) is enough. We could implement
> 2) if we think it's worth it in a separate improvement (with perhaps
> a new "staleLockFile" fsck message).
>
> Thanks.
Agreed, will modify accordingly.
Previous: Christian CouderNext: Karthik Nayak
Message 5 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.