Skip to content

Commit 317956d

Browse files
TaoKgitster
authored andcommitted
untracked-cache: write index when populating empty untracked cache
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 37482b4 commit 317956d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

dir.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2781,7 +2781,8 @@ void remove_untracked_cache(struct index_state *istate)
27812781

27822782
static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *dir,
27832783
int base_len,
2784-
const struct pathspec *pathspec)
2784+
const struct pathspec *pathspec,
2785+
struct index_state *istate)
27852786
{
27862787
struct untracked_cache_dir *root;
27872788
static int untracked_cache_disabled = -1;
@@ -2845,8 +2846,11 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
28452846
return NULL;
28462847
}
28472848

2848-
if (!dir->untracked->root)
2849+
if (!dir->untracked->root) {
2850+
/* Untracked cache existed but is not initialized; fix that */
28492851
FLEX_ALLOC_STR(dir->untracked->root, name, "");
2852+
istate->cache_changed |= UNTRACKED_CHANGED;
2853+
}
28502854

28512855
/* Validate $GIT_DIR/info/exclude and core.excludesfile */
28522856
root = dir->untracked->root;
@@ -2916,7 +2920,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
29162920
return dir->nr;
29172921
}
29182922

2919-
untracked = validate_untracked_cache(dir, len, pathspec);
2923+
untracked = validate_untracked_cache(dir, len, pathspec, istate);
29202924
if (!untracked)
29212925
/*
29222926
* make sure untracked cache code path is disabled,

0 commit comments

Comments
 (0)