git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] dir: force untracked cache with core.untrackedCache

From
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 14, 2022, 17:37 UTC
Message-ID
<pull.1058.git.1644860224151.gitgitgadget@gmail.com>
From: Derrick Stolee <derrickstolee@github.com>

The GIT_FORCE_UNTRACKED_CACHE environment variable writes the untracked cache more frequently than the core.untrackedCache config variable. This is due to how read_directory() handles the creation of an untracked cache. The old mechanism required using something like 'git update-index --untracked-cache' before the index would actually contain an untracked cache. This was noted as a performance problem on macOS in the past, and this is a resolution for that issue.

The decision to not write the untracked cache without an environment variable tracks back to fc9ecbeb9 (dir.c: don't flag the index as dirty for changes to the untracked cache, 2018-02-05). The motivation of that change is that writing the index is expensive, and if the untracked cache is the only thing that needs to be written, then it is more expensive than the benefit of the cache. However, this also means that the untracked cache never gets populated, so the user who enabled it via config does not actually get the extension until running 'git update-index --untracked-cache' manually or using the environment variable.

We have had a version of this change in the microsoft/git fork for a few major releases now. It has been working well to get users into a good state. Yes, that first index write is slow, but the remaining index writes are much faster than they would be without this change.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
---
    dir: force untracked cache with core.untrackedCache
    
    We have seen users in the wild that have had core.untrackedCache
    enabled, but never actually have an untracked cache created for them. We
    have a test in t7063 that shows git status should write the untracked
    cache, so I'm not exactly sure how users are in this state for long.
    
    This patch fixes the situation. I also know of another group that sets
    GIT_FORCE_UNTRACKED_CACHE=1 in their developer environment in order to
    get this behavior.
    
    -Stolee
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1058%2Fderrickstolee%2Funtracked-cache-write-more-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1058/derrickstolee/untracked-cache-write-more-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1058
 dir.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/dir.c b/dir.c
index d91295f2bcd..79a5f6918c8 100644
--- a/dir.c
+++ b/dir.c
@@ -2936,7 +2936,9 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
 
 		if (force_untracked_cache < 0)
 			force_untracked_cache =
-				git_env_bool("GIT_FORCE_UNTRACKED_CACHE", 0);
+				git_env_bool("GIT_FORCE_UNTRACKED_CACHE", -1);
+		if (force_untracked_cache < 0)
+			force_untracked_cache = (istate->repo->settings.core_untracked_cache == UNTRACKED_CACHE_WRITE);
 		if (force_untracked_cache &&
 			dir->untracked == istate->untracked &&
 		    (dir->untracked->dir_opened ||

base-commit: b80121027d1247a0754b3cc46897fee75c050b44
-- 
gitgitgadget
Next: Junio C Hamano
Message 1 of 5 in “dir: force untracked cache with core.untrackedCache”
  1. dir: force untracked cache with core.untrackedCacheDerrick Stolee via GitGitGadget, Feb 14, 2022
  2. Junio C HamanoFeb 14, 2022
  3. Derrick StoleeFeb 14, 2022
  4. dir: force untracked cache with core.untrackedCacheDerrick Stolee via GitGitGadget, Feb 17, 2022
  5. Junio C HamanoFeb 17, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.