{"thread":{"id":"66967","subject":"[PATCH] status: base the \"results were cached\" remark on the untracked cache","startedAt":"2026-12-01T08:01:09Z","lastAt":"2026-12-01T08:01:09Z","messageCount":1,"participants":["blanet via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"559765","messageId":"pull.2345.git.1796112069353.gitgitgadget@gmail.com","threadId":"66967","inReplyTo":null,"subject":"[PATCH] status: base the \"results were cached\" remark on the untracked cache","fromName":"blanet via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-12-01T08:01:09Z","receivedAt":"2026-12-01T08:01:09Z","isPatch":true,"sender":{"key":"name:blanet","avatar":null},"body":"From: Xing Xin <xingxin.xx@bytedance.com>\n\nSince ecbc23e4c5 (status: modernize git-status \"slow untracked files\"\nadvice, 2022-11-30), the advice that \"git status\" gives when\nenumerating untracked files takes more than 2 seconds adds \"but the\nresults were cached, and subsequent runs may be faster\" whenever\ncore.fsmonitor is enabled. But it is the untracked cache that caches\nthese results, with or without fsmonitor:\n\n - Without the untracked cache, which is off by default, every run\n   enumerates all untracked files again, however fsmonitor is\n   configured, and the promised speedup never comes.\n\n - With it, subsequent runs only read the directories that changed,\n   which they find by checking the stat data of all directories, or,\n   with fsmonitor, by asking it.\n\nIn the Linux kernel repository, on an Apple M4 Pro, enumerating the\nuntracked files takes 305ms when the untracked cache is created, then\n17ms with the untracked cache alone, 9ms with fsmonitor as well, and\nstill 313ms with fsmonitor alone.\n\nThe documentation that ecbc23e4c5 added says as much: \"While the\nFSMonitor feature can be enabled without the untracked cache, the\nbenefits are greatly reduced in that case.\" But the code checks only\ncore.fsmonitor.\n\nGive the remark when the untracked cache was used to enumerate the\nuntracked files, whether fsmonitor is enabled or not. Checking\ncore.untrackedCache instead would not be accurate either: the\nuntracked cache is enabled but not used with \"--ignored\" or a\npathspec, and with core.untrackedCache set to \"keep\", its default,\nthe untracked cache is used if the index already has one. So record\nin struct wt_status whether dir.untracked is set after\nfill_directory(), as read_directory() resets it when it cannot use\nthe untracked cache.\n\nSigned-off-by: Xing Xin <xingxin.xx@bytedance.com>\n---\n    status: base the \"results were cached\" remark on the untracked cache\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2345%2Fblanet%2Fxx%2Fstatus-untracked-cache-advice-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2345/blanet/xx/status-untracked-cache-advice-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2345\n\n t/t7508-status.sh | 35 ++++++++++++++++++++++++++++++++++-\n wt-status.c       |  6 +++---\n wt-status.h       |  1 +\n 3 files changed, 38 insertions(+), 4 deletions(-)\n\ndiff --git a/t/t7508-status.sh b/t/t7508-status.sh\nindex e10c961268..47fb48c9d0 100755\n--- a/t/t7508-status.sh\n+++ b/t/t7508-status.sh\n@@ -1853,7 +1853,8 @@ test_expect_success 'slow status advice when core.untrackedCache true, but not f\n \t\tcat >expected <<-\\EOF &&\n \t\tOn branch main\n \n-\t\tIt took 3.25 seconds to enumerate untracked files.\n+\t\tIt took 3.25 seconds to enumerate untracked files,\n+\t\tbut the results were cached, and subsequent runs may be faster.\n \t\tSee '\\''git help status'\\'' for information on how to improve this.\n \n \t\tnothing to commit, working tree clean\n@@ -1881,6 +1882,38 @@ test_expect_success 'slow status advice when core.untrackedCache true, and fsmon\n \t)\n '\n \n+test_expect_success 'slow status advice when fsmonitor, but not core.untrackedCache' '\n+\t(\n+\t\tcd slowstatus &&\n+\t\tgit config core.untrackedCache false &&\n+\t\tgit config core.fsmonitor true &&\n+\t\tGIT_TEST_UF_DELAY_WARNING=1 git status >actual &&\n+\t\tcat >expected <<-\\EOF &&\n+\t\tOn branch main\n+\n+\t\tIt took 3.25 seconds to enumerate untracked files.\n+\t\tSee '\\''git help status'\\'' for information on how to improve this.\n+\n+\t\tnothing to commit, working tree clean\n+\t\tEOF\n+\t\ttest_cmp expected actual\n+\t)\n+'\n+\n+test_expect_success 'slow status advice when the untracked cache is not used' '\n+\t(\n+\t\tcd slowstatus &&\n+\t\tgit config core.untrackedCache true &&\n+\t\tgit config core.fsmonitor true &&\n+\t\tGIT_TEST_UF_DELAY_WARNING=1 git status --ignored >actual &&\n+\t\ttest_grep \"^It took 3.25 seconds to enumerate untracked files\\.$\" actual &&\n+\t\ttest_grep ! \"results were cached\" actual &&\n+\t\tGIT_TEST_UF_DELAY_WARNING=1 git status -- .gitignore >actual &&\n+\t\ttest_grep \"^It took 3.25 seconds to enumerate untracked files\\.$\" actual &&\n+\t\ttest_grep ! \"results were cached\" actual\n+\t)\n+'\n+\n test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'status does not re-read unchanged 4 or 8 GiB file' '\n \t(\n \t\tmkdir large-file &&\ndiff --git a/wt-status.c b/wt-status.c\nindex 238bb48643..0070140f12 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -34,7 +34,6 @@\n #include \"worktree.h\"\n #include \"lockfile.h\"\n #include \"sequencer.h\"\n-#include \"fsmonitor-settings.h\"\n \n #define AB_DELAY_WARNING_IN_MS (2 * 1000)\n #define UF_DELAY_WARNING_IN_MS (2 * 1000)\n@@ -828,6 +827,8 @@ static void wt_status_collect_untracked(struct wt_status *s)\n \tsetup_standard_excludes(&dir);\n \n \tfill_directory(&dir, istate, &s->pathspec);\n+\t/* read_directory() resets it if the untracked cache cannot be used */\n+\ts->untracked_cache_used = !!dir.untracked;\n \n \tfor (i = 0; i < dir.nr; i++) {\n \t\tstruct dir_entry *ent = dir.entries[i];\n@@ -1993,7 +1994,6 @@ static void wt_longstatus_print(struct wt_status *s)\n {\n \tconst char *branch_color = color(WT_STATUS_ONBRANCH, s);\n \tconst char *branch_status_color = color(WT_STATUS_HEADER, s);\n-\tenum fsmonitor_mode fsm_mode = fsm_settings__get_mode(s->repo);\n \n \tif (s->branch) {\n \t\tconst char *on_what = _(\"On branch \");\n@@ -2052,7 +2052,7 @@ static void wt_longstatus_print(struct wt_status *s)\n \t\t\twt_longstatus_print_other(s, &s->ignored, _(\"Ignored files\"), \"add -f\");\n \t\tif (advice_enabled(ADVICE_STATUS_U_OPTION) && uf_was_slow(s)) {\n \t\t\tstatus_printf_ln(s, GIT_COLOR_NORMAL, \"%s\", \"\");\n-\t\t\tif (fsm_mode > FSMONITOR_MODE_DISABLED) {\n+\t\t\tif (s->untracked_cache_used) {\n \t\t\t\tstatus_printf_ln(s, GIT_COLOR_NORMAL,\n \t\t\t\t\t\t_(\"It took %.2f seconds to enumerate untracked files,\\n\"\n \t\t\t\t\t\t\"but the results were cached, and subsequent runs may be faster.\"),\ndiff --git a/wt-status.h b/wt-status.h\nindex e9fe32e98c..894361efb4 100644\n--- a/wt-status.h\n+++ b/wt-status.h\n@@ -145,6 +145,7 @@ struct wt_status {\n \tstruct string_list untracked;\n \tstruct string_list ignored;\n \tuint32_t untracked_in_ms;\n+\tint untracked_cache_used;\n };\n \n size_t wt_status_locate_end(const char *s, size_t len);\n\nbase-commit: acba8bf9753134d9bde89f94369f775838a8c5fe\n-- \ngitgitgadget\n\n"}]}