All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Maik Riechert via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Ilia K <ki.stfu@gmail.com>, Derrick Stolee <stolee@gmail.com>,
	Junio C Hamano <gitster@pobox.com>,
	Maik Riechert <letmaik@outlook.com>,
	Maik Riechert <letmaik@outlook.com>
Subject: [PATCH] dir: invalidate parents of stale cached directories
Date: Fri, 20 Nov 2026 05:33:03 +0000	[thread overview]
Message-ID: <pull.2321.git.1795152783221.gitgitgadget@gmail.com> (raw)

From: Maik Riechert <letmaik@outlook.com>

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.

Signed-off-by: Maik Riechert <letmaik@outlook.com>
---
    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(+)

diff --git a/dir.c b/dir.c
index 4f748800b1..633d259d7a 100644
--- a/dir.c
+++ b/dir.c
@@ -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;
 }
 
diff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh
index 27c3194ae0..3877140b77 100755
--- a/t/t7519-status-fsmonitor.sh
+++ b/t/t7519-status-fsmonitor.sh
@@ -388,6 +388,52 @@ test_expect_success UNTRACKED_CACHE 'untracked cache is checked after a trivial
 	)
 '
 
+for response in trivial failed
+do
+	test_expect_success UNTRACKED_CACHE,!MINGW "stale check-only directories invalidate parents after a $response response" '
+		test_when_finished "rm -rf stale-$response" &&
+		git init stale-$response &&
+		(
+			cd stale-$response &&
+			mkdir -p parent/three/deep &&
+			>parent/keep &&
+			>parent/three/deep/tracked &&
+			git add parent &&
+			git commit -m initial &&
+			git rm --cached parent/three/deep/tracked &&
+			git config core.untrackedCache true &&
+			git config status.showUntrackedFiles normal &&
+			git config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-none" &&
+			git config core.fsmonitorHookVersion 1 &&
+			test-tool chmtime =1000000000 . parent parent/three parent/three/deep &&
+			cat >../expect <<-\EOF &&
+			D  parent/three/deep/tracked
+			?? parent/three/
+			EOF
+			git status --porcelain >../actual &&
+			test_cmp ../expect ../actual &&
+
+			# Change only the check-only directory after caching it.
+			# Write the index without scanning untracked files.
+			test-tool chmtime +60 parent/three &&
+			if test "$response" = trivial
+			then
+				hook_version=1
+			else
+				# fsmonitor-all fails for version 2.
+				hook_version=2
+			fi &&
+			git -c core.fsmonitor="$TEST_DIRECTORY/t7519/fsmonitor-all" \
+				-c core.fsmonitorHookVersion=$hook_version \
+				update-index --force-write-index &&
+			git status --porcelain >../actual &&
+			test_cmp ../expect ../actual &&
+			git status --porcelain >../actual &&
+			test_cmp ../expect ../actual
+		)
+	'
+done
+
 # test that splitting the index doesn't interfere
 test_expect_success 'splitting the index results in the same state' '
 	write_integration_script &&

base-commit: f7de81456940dd6f3274e461149bba12965de609
-- 
gitgitgadget

                 reply	other threads:[~2026-11-20  5:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.2321.git.1795152783221.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=ki.stfu@gmail.com \
    --cc=letmaik@outlook.com \
    --cc=stolee@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.