From: Ilia K Date: Mon, 09 Nov 2026 18:59:10 GMT Subject: Re: [PATCH] fsmonitor: check the untracked cache after a trivial response Message-ID: In-Reply-To: On Thu, Nov 5, 2026 at 4:01 PM Derrick Stolee wrote: > > > + 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! > > 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. > > +# 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! > > + 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