Git development
 help / color / mirror / Atom feed
From: "blanet via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: blanet <bupt_xingxin@163.com>, Xing Xin <xingxin.xx@bytedance.com>
Subject: [PATCH] status: base the "results were cached" remark on the untracked cache
Date: Tue, 01 Dec 2026 08:01:09 +0000	[thread overview]
Message-ID: <pull.2345.git.1796112069353.gitgitgadget@gmail.com> (raw)

From: Xing Xin <xingxin.xx@bytedance.com>

Since ecbc23e4c5 (status: modernize git-status "slow untracked files"
advice, 2022-11-30), the advice that "git status" gives when
enumerating untracked files takes more than 2 seconds adds "but the
results were cached, and subsequent runs may be faster" whenever
core.fsmonitor is enabled. But it is the untracked cache that caches
these results, with or without fsmonitor:

 - Without the untracked cache, which is off by default, every run
   enumerates all untracked files again, however fsmonitor is
   configured, and the promised speedup never comes.

 - With it, subsequent runs only read the directories that changed,
   which they find by checking the stat data of all directories, or,
   with fsmonitor, by asking it.

In the Linux kernel repository, on an Apple M4 Pro, enumerating the
untracked files takes 305ms when the untracked cache is created, then
17ms with the untracked cache alone, 9ms with fsmonitor as well, and
still 313ms with fsmonitor alone.

The documentation that ecbc23e4c5 added says as much: "While the
FSMonitor feature can be enabled without the untracked cache, the
benefits are greatly reduced in that case." But the code checks only
core.fsmonitor.

Give the remark when the untracked cache was used to enumerate the
untracked files, whether fsmonitor is enabled or not. Checking
core.untrackedCache instead would not be accurate either: the
untracked cache is enabled but not used with "--ignored" or a
pathspec, and with core.untrackedCache set to "keep", its default,
the untracked cache is used if the index already has one. So record
in struct wt_status whether dir.untracked is set after
fill_directory(), as read_directory() resets it when it cannot use
the untracked cache.

Signed-off-by: Xing Xin <xingxin.xx@bytedance.com>
---
    status: base the "results were cached" remark on the untracked cache

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2345%2Fblanet%2Fxx%2Fstatus-untracked-cache-advice-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2345/blanet/xx/status-untracked-cache-advice-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2345

 t/t7508-status.sh | 35 ++++++++++++++++++++++++++++++++++-
 wt-status.c       |  6 +++---
 wt-status.h       |  1 +
 3 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index e10c961268..47fb48c9d0 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -1853,7 +1853,8 @@ test_expect_success 'slow status advice when core.untrackedCache true, but not f
 		cat >expected <<-\EOF &&
 		On branch main
 
-		It took 3.25 seconds to enumerate untracked files.
+		It took 3.25 seconds to enumerate untracked files,
+		but the results were cached, and subsequent runs may be faster.
 		See '\''git help status'\'' for information on how to improve this.
 
 		nothing to commit, working tree clean
@@ -1881,6 +1882,38 @@ test_expect_success 'slow status advice when core.untrackedCache true, and fsmon
 	)
 '
 
+test_expect_success 'slow status advice when fsmonitor, but not core.untrackedCache' '
+	(
+		cd slowstatus &&
+		git config core.untrackedCache false &&
+		git config core.fsmonitor true &&
+		GIT_TEST_UF_DELAY_WARNING=1 git status >actual &&
+		cat >expected <<-\EOF &&
+		On branch main
+
+		It took 3.25 seconds to enumerate untracked files.
+		See '\''git help status'\'' for information on how to improve this.
+
+		nothing to commit, working tree clean
+		EOF
+		test_cmp expected actual
+	)
+'
+
+test_expect_success 'slow status advice when the untracked cache is not used' '
+	(
+		cd slowstatus &&
+		git config core.untrackedCache true &&
+		git config core.fsmonitor true &&
+		GIT_TEST_UF_DELAY_WARNING=1 git status --ignored >actual &&
+		test_grep "^It took 3.25 seconds to enumerate untracked files\.$" actual &&
+		test_grep ! "results were cached" actual &&
+		GIT_TEST_UF_DELAY_WARNING=1 git status -- .gitignore >actual &&
+		test_grep "^It took 3.25 seconds to enumerate untracked files\.$" actual &&
+		test_grep ! "results were cached" actual
+	)
+'
+
 test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'status does not re-read unchanged 4 or 8 GiB file' '
 	(
 		mkdir large-file &&
diff --git a/wt-status.c b/wt-status.c
index 238bb48643..0070140f12 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -34,7 +34,6 @@
 #include "worktree.h"
 #include "lockfile.h"
 #include "sequencer.h"
-#include "fsmonitor-settings.h"
 
 #define AB_DELAY_WARNING_IN_MS (2 * 1000)
 #define UF_DELAY_WARNING_IN_MS (2 * 1000)
@@ -828,6 +827,8 @@ static void wt_status_collect_untracked(struct wt_status *s)
 	setup_standard_excludes(&dir);
 
 	fill_directory(&dir, istate, &s->pathspec);
+	/* read_directory() resets it if the untracked cache cannot be used */
+	s->untracked_cache_used = !!dir.untracked;
 
 	for (i = 0; i < dir.nr; i++) {
 		struct dir_entry *ent = dir.entries[i];
@@ -1993,7 +1994,6 @@ static void wt_longstatus_print(struct wt_status *s)
 {
 	const char *branch_color = color(WT_STATUS_ONBRANCH, s);
 	const char *branch_status_color = color(WT_STATUS_HEADER, s);
-	enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(s->repo);
 
 	if (s->branch) {
 		const char *on_what = _("On branch ");
@@ -2052,7 +2052,7 @@ static void wt_longstatus_print(struct wt_status *s)
 			wt_longstatus_print_other(s, &s->ignored, _("Ignored files"), "add -f");
 		if (advice_enabled(ADVICE_STATUS_U_OPTION) && uf_was_slow(s)) {
 			status_printf_ln(s, GIT_COLOR_NORMAL, "%s", "");
-			if (fsm_mode > FSMONITOR_MODE_DISABLED) {
+			if (s->untracked_cache_used) {
 				status_printf_ln(s, GIT_COLOR_NORMAL,
 						_("It took %.2f seconds to enumerate untracked files,\n"
 						"but the results were cached, and subsequent runs may be faster."),
diff --git a/wt-status.h b/wt-status.h
index e9fe32e98c..894361efb4 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -145,6 +145,7 @@ struct wt_status {
 	struct string_list untracked;
 	struct string_list ignored;
 	uint32_t untracked_in_ms;
+	int untracked_cache_used;
 };
 
 size_t wt_status_locate_end(const char *s, size_t len);

base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe
-- 
gitgitgadget

                 reply	other threads:[~2026-12-01  8:01 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.2345.git.1796112069353.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=bupt_xingxin@163.com \
    --cc=git@vger.kernel.org \
    --cc=xingxin.xx@bytedance.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox