Skip to content

Commit fc9ecbe

Browse files
benpeartgitster
authored andcommitted
dir.c: don't flag the index as dirty for changes to the untracked cache
The untracked cache saves its current state in the UNTR index extension. Currently, _any_ change to that state causes the index to be flagged as dirty and written out to disk. Unfortunately, the cost to write out the index can exceed the savings gained by using the untracked cache. Since it is a cache that can be updated from the current state of the working directory, there is no functional requirement that the index be written out for every change to the untracked cache. Update the untracked cache logic so that it no longer forces the index to be written to disk except in the case where the extension is being turned on or off. When some other git command requires the index to be written to disk, the untracked cache will take advantage of that to save it's updated state as well. This results in a performance win when looked at over common sequences of git commands (ie such as a status followed by add, commit, etc). After this patch, all the logic to track statistics for the untracked cache could be removed as it is only used by debug tracing used to debug the untracked cache. Signed-off-by: Ben Peart <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5be1f00 commit fc9ecbe

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

dir.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2297,7 +2297,8 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
22972297
dir->untracked->gitignore_invalidated,
22982298
dir->untracked->dir_invalidated,
22992299
dir->untracked->dir_opened);
2300-
if (dir->untracked == istate->untracked &&
2300+
if (getenv("GIT_TEST_UNTRACKED_CACHE") &&
2301+
dir->untracked == istate->untracked &&
23012302
(dir->untracked->dir_opened ||
23022303
dir->untracked->gitignore_invalidated ||
23032304
dir->untracked->dir_invalidated))

t/t7063-status-untracked-cache.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ test_description='test untracked cache'
1414
# See <[email protected]> if you want to know
1515
# more.
1616

17+
GIT_TEST_UNTRACKED_CACHE=true
18+
export GIT_TEST_UNTRACKED_CACHE
19+
1720
sync_mtime () {
1821
find . -type d -ls >/dev/null
1922
}

0 commit comments

Comments
 (0)