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

[PATCH v2 3/3] untracked-cache: write index when populating empty untracked cache

From
Tao Klerks via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 25, 2022, 17:10 UTC
Message-ID
<190b27e518a22e2253b318e8087446d761e918b2.1645809015.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.986.v2.git.1645809015.gitgitgadget@gmail.com>
From: Tao Klerks <tao@klerks.biz>

It is expected that an empty/unpopulated untracked cache structure can be written to the index - by update-index, or by a "git status" call that sees the untracked cache should be enabled and is not, but is running with options that make the untracked cache non-applicable in that run (eg a pathspec).

Currently, if that happens, then subsequent "git status" calls end up populating the untracked cache, but not writing the index (not saving their work) - so the performance outcome is almost identical to the cache being altogether disabled.

This continues until the index gets written with the untracked cache populated, for some *other* reason, such as a working tree change.

Detect the condition where an empty untracked cache exists in the index and we will collect the list of untracked paths, and queue an index write under that condition, so that the collected untracked paths can be written out to the untracked cache extension in the index.

This change depends on previous fixes to t7519 for the "ignore .git changes when invalidating UNTR" test case to pass - before this fix, the test never actually did anything as it was not set up correctly.

Signed-off-by: Tao Klerks <tao@klerks.biz>
---
 dir.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/dir.c b/dir.c
index d91295f2bcd..4eee45dec91 100644
--- a/dir.c
+++ b/dir.c
@@ -2781,7 +2781,8 @@ void remove_untracked_cache(struct index_state *istate)
 
 static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *dir,
 						      int base_len,
-						      const struct pathspec *pathspec)
+						      const struct pathspec *pathspec,
+						      struct index_state *istate)
 {
 	struct untracked_cache_dir *root;
 	static int untracked_cache_disabled = -1;
@@ -2845,8 +2846,11 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
 		return NULL;
 	}
 
-	if (!dir->untracked->root)
+	if (!dir->untracked->root) {
+		/* Untracked cache existed but is not initialized; fix that */
 		FLEX_ALLOC_STR(dir->untracked->root, name, "");
+		istate->cache_changed |= UNTRACKED_CHANGED;
+	}
 
 	/* Validate $GIT_DIR/info/exclude and core.excludesfile */
 	root = dir->untracked->root;
@@ -2916,7 +2920,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
 		return dir->nr;
 	}
 
-	untracked = validate_untracked_cache(dir, len, pathspec);
+	untracked = validate_untracked_cache(dir, len, pathspec, istate);
 	if (!untracked)
 		/*
 		 * make sure untracked cache code path is disabled,
-- 
gitgitgadget
Previous: Tao Klerks via GitGitGadgetNext: Junio C Hamano
Message 14 of 19 in “Empty untracked cache performance issue”
  1. 0/3 Empty untracked cache performance issueTao Klerks via GitGitGadget, Jun 24, 2021
  2. 1/3 Add a second's delay to t7519 for untracked cacheTao Klerks via GitGitGadget, Jun 24, 2021
  3. Junio C HamanoJun 29, 2021
  4. 2/3 In t7519, populate untracked cache before testTao Klerks via GitGitGadget, Jun 24, 2021
  5. 3/3 Write index when populating empty untracked cacheTao Klerks via GitGitGadget, Jun 24, 2021
  6. Junio C HamanoJun 29, 2021
  7. Tao KlerksFeb 24, 2022
  8. Junio C HamanoFeb 24, 2022
  9. 0/3 Empty untracked cache performance issueTao Klerks via GitGitGadget, Feb 25, 2022
  10. 1/3 t7519: avoid file to index mtime race for untracked cacheTao Klerks via GitGitGadget, Feb 25, 2022
  11. Junio C HamanoFeb 25, 2022
  12. Tao KlerksFeb 27, 2022
  13. 2/3 t7519: populate untracked cache before testTao Klerks via GitGitGadget, Feb 25, 2022
  14. 3/3 untracked-cache: write index when populating empty untracked cacheTao Klerks via GitGitGadget, Feb 25, 2022
  15. Junio C HamanoFeb 25, 2022
  16. 0/3 Empty untracked cache performance issueTao Klerks via GitGitGadget, Feb 27, 2022
  17. 1/3 t7519: avoid file to index mtime race for untracked cacheTao Klerks via GitGitGadget, Feb 27, 2022
  18. 2/3 t7519: populate untracked cache before testTao Klerks via GitGitGadget, Feb 27, 2022
  19. 3/3 untracked-cache: write index when populating empty untracked cacheTao Klerks via GitGitGadget, Feb 27, 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.