dir.c: don't flag the index as dirty for changes to the untracked cache
authorBen Peart <benpeart@microsoft.com>
Mon, 5 Feb 2018 19:56:19 +0000 (14:56 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 Feb 2018 20:55:49 +0000 (12:55 -0800)
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 <benpeart@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir.c
t/t7063-status-untracked-cache.sh
diff --git a/dir.c b/dir.c
index 7c4b45e30e0ac87527ff0ef3fd8c90670a1e2064..da93374f0c7b93a7c602203cb0cb58f5ffde24a1 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -2297,7 +2297,8 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
                                 dir->untracked->gitignore_invalidated,
                                 dir->untracked->dir_invalidated,
                                 dir->untracked->dir_opened);
-               if (dir->untracked == istate->untracked &&
+               if (getenv("GIT_TEST_UNTRACKED_CACHE") &&
+                       dir->untracked == istate->untracked &&
                    (dir->untracked->dir_opened ||
                     dir->untracked->gitignore_invalidated ||
                     dir->untracked->dir_invalidated))
index e5fb892f9575fda4baf0b2a0e6b31cf13a0d6c0b..6ef520e8237dbad4365eab057149678ba1221dba 100755 (executable)
@@ -14,6 +14,9 @@ test_description='test untracked cache'
 # See <20160803174522.5571-1-pclouds@gmail.com> if you want to know
 # more.
 
+GIT_TEST_UNTRACKED_CACHE=true
+export GIT_TEST_UNTRACKED_CACHE
+
 sync_mtime () {
        find . -type d -ls >/dev/null
 }