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

Re: [PATCH] fsmonitor: check the untracked cache after a trivial response

From
IKIlia K <ki.stfu@gmail.com>
Date
Nov 9, 2026, 18:59 UTC
Message-ID
<CAMmqxguRpCFL2cRJ_LCXaPd9d91zFb-Yo6MVbhSsi57S14xseA@mail.gmail.com>
In-Reply-To
<xmqqld77uofw.fsf@gitster.g>
On Thu, Nov 5, 2026 at 4:01 PM Derrick Stolee <stolee@gmail.com> wrote:
Show 28 quoted lines
>
> > +             strbuf_setlen(path, len);
> > +     }
> > +
> > +     return nr_invalidated;
> > +}
> > +
> > +int untracked_cache_invalidate_stale_dirs(struct index_state *istate)
> > +{
> > +     struct strbuf path = STRBUF_INIT;
> > +     const char *worktree;
> > +     int nr_invalidated;
> > +
> > +     if (!istate->untracked || !istate->untracked->root)
> > +             return 0;
> > +
> > +     /*
> > +      * The index is also read and written by commands that do not
> > +      * run in the top-level directory of the worktree.
> > +      */
> > +     worktree = repo_get_work_tree(istate->repo);
> > +     if (!worktree)
> > +             return 0;
>
> I wonder if this is the right response if we fail to get a worktree. Maybe
> we should invalidate the entire untracked cache in this case, along with a
> warning that we couldn't evaluate the worktree? Or should we return -1 to
> signal an error?
Fixed, thank you!
Show 29 quoted lines
> > diff --git a/read-cache.c b/read-cache.c
> > index c4cf08a3a3..00c9960c8e 100644
> > --- a/read-cache.c
> > +++ b/read-cache.c
> > @@ -3034,6 +3034,22 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
> >           istate->untracked) {
> >               strbuf_reset(&sb);
> >
> > +             /*
> > +              * The monitor could not say what changed (see the trivial
> > +              * response in refresh_fsmonitor()), so nothing kept the
> > +              * valid bits up to date. Check them before they are saved
> > +              * next to the new token, which later commands trust even
> > +              * when this command did not look for untracked files.
> > +              */
> > +             if (write_extensions & WRITE_FSMONITOR_EXTENSION &&
> > +                 istate->fsmonitor_last_update &&
> > +                 !istate->untracked->use_fsmonitor) {
> > +                     int nr = untracked_cache_invalidate_stale_dirs(istate);
> > +
> > +                     trace2_data_intmax("index", istate->repo,
> > +                                        "extension/untr/invalidated", nr);
> > +             }
>
> This surprised me, that you're computing this in do_write_index(). I suppose
> that this avoids doing this computation unless the index is written, but is
> it possible that between refresh_fsmonitor() and do_write_index() that the
> untracked cache is read and used to determine what this index update should
> be?

No, nothing between `refresh_fsmonitor()` and `do_write_index()` trusts the cache because use_fsmonitor stays 0 until the index is written.

Show 6 quoted lines
> > +# After a trivial response ("/") the monitor cannot vouch for the
> > +# untracked cache. Even a command that does not look for untracked
> > +# files must drop the stale entries, or the next "git status" trusts them.
>
> nit: Generally, we don't need these comments because the tests should be
> self-documenting.
Fixed, thank you!
Show 13 quoted lines
> > +             EOF
> > +             git status --porcelain >../actual 2>../err &&
> > +             test_must_be_empty ../err &&
> > +             test_cmp ../expect ../actual
> > +     )
> > +'
>
> > +# After a restart the daemon sends a trivial response ("/"), because it
> > +# cannot know what changed while it was down. Even a command that does
> > +# not look for untracked files must then drop the stale untracked cache
> > +# entries, or the next "git status" trusts them.
>
> same nit: comments shouldn't be necessary here.
Fixed, thank you!
--
- Ilia
Previous: Junio C HamanoNext: Ilia via GitGitGadget
Message 4 of 8 in “fsmonitor: check the untracked cache after a trivial response”
  1. fsmonitor: check the untracked cache after a trivial responseIlia via GitGitGadget, Oct 4, 2026
  2. Derrick StoleeNov 5, 2026
  3. Junio C HamanoNov 5, 2026
  4. Ilia KNov 9, 2026
  5. fsmonitor: check the untracked cache after a trivial responseIlia via GitGitGadget, Nov 9, 2026
  6. Derrick StoleeNov 9, 2026
  7. Junio C HamanoNov 9, 2026
  8. Junio C HamanoNov 9, 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.