Skip to contentSkip to conversation

dir: invalidate parents of stale cached directories

PATCH New Maik Riechert via GitGitGadget 1 participant 1 message Nov 20

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dir: invalidate parents of stale cached directories

From: Maik Riechert <[email protected]>

After a failed fsmonitor query or a trivial response, "git status" can report both an untracked directory and a directory below it, for example "?? three/" and "?? three/deep/".

1cf98cb4d9 (fsmonitor: check the untracked cache after a trivial response, 2026-11-09) added a stat check before writing the untracked cache alongside a new fsmonitor token after these responses. The check invalidates stale directories, but does not propagate the invalidation to their parents.

In normal mode, a parent's cached untracked list can contain "three/" from a check-only scan of the child. Writing the invalid child clears its check_only flag. The next cached walk then recurses into the child and reports "three/deep/", while the parent's list still reports "three/".

Invalidate ancestors too when DIR_SHOW_OTHER_DIRECTORIES is set, as invalidate_one_component() does. Leave all-files mode unchanged and reuse the existing traversal without adding stat calls.

Add normal-mode regression tests for failed queries and trivial responses. Use fixed directory mtimes and force an index write without scanning untracked files.

---
dir: invalidate parents of stale cached directories

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2321%2Fletmaik%2Funtracked-cache-stale-dirs-parents-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2321/letmaik/untracked-cache-stale-dirs-parents-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2321

 dir.c                       |  6 +++++
 t/t7519-status-fsmonitor.sh | 46 +++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
dir.c +6 -0
index 4f748800b1..633d259d7a 100644
@@ -4094,6 +4094,12 @@ static int invalidate_stale_dirs(struct untracked_cache *uc,
 		strbuf_setlen(path, len);
 	}
 
+	if (nr_invalidated && ucd->valid &&
+	    (uc->dir_flags & DIR_SHOW_OTHER_DIRECTORIES)) {
+		invalidate_one_directory(uc, ucd);
+		nr_invalidated++;
+	}
+
 	return nr_invalidated;
 }
 
t/t7519-status-fsmonitor.sh +46 -0

52 lines not on this page · raw message

base-commit: f7de81456940dd6f3274e461149bba12965de609

Signature · 1 line
gitgitgadget