untracked cache: use git_env_bool() not getenv() for customization

GIT_DISABLE_UNTRACKED_CACHE and GIT_TEST_UNTRACKED_CACHE are only sensed for their presense by using getenv(); use git_env_bool() instead so that GIT_DISABLE_UNTRACKED_CACHE=false would work as naïvely expected. Also rename GIT_TEST_UNTRACKED_CACHE to GIT_FORCE_UNTRACKED_CACHE to express what it does more honestly. Forcing its use may be one useful thing to do while testing the feature, but testing does not have to be the only use of the knob. While at it, avoid repeated calls to git_env_bool() by capturing the return value from the first call in a static variable. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Feb 28, 2018 at 13:21 UTC 026336cb277693c5a8cdfa4705a26daf0a754328
2 files changed +14 -4
dir.c
+12 -2
@@ -2164,8 +2164,13 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
2164 const struct pathspec *pathspec)
2165 {
2166 struct untracked_cache_dir *root;
2167 + static int untracked_cache_disabled = -1;
2168
2168 - if (!dir->untracked || getenv("GIT_DISABLE_UNTRACKED_CACHE"))
2169 + if (!dir->untracked)
2170 + return NULL;
2171 + if (untracked_cache_disabled < 0)
2172 + untracked_cache_disabled = git_env_bool("GIT_DISABLE_UNTRACKED_CACHE", 0);
2173 + if (untracked_cache_disabled)
2174 return NULL;
2175
2176 /*
@@ -2287,7 +2292,12 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
2292 }
2293
2294 if (dir->untracked) {
2295 + static int force_untracked_cache = -1;
2296 static struct trace_key trace_untracked_stats = TRACE_KEY_INIT(UNTRACKED_STATS);
2297 +
2298 + if (force_untracked_cache < 0)
2299 + force_untracked_cache =
2300 + git_env_bool("GIT_FORCE_UNTRACKED_CACHE", 0);
2301 trace_printf_key(&trace_untracked_stats,
2302 "node creation: %u\n"
2303 "gitignore invalidation: %u\n"
@@ -2297,7 +2307,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
2307 dir->untracked->gitignore_invalidated,
2308 dir->untracked->dir_invalidated,
2309 dir->untracked->dir_opened);
2300 - if (getenv("GIT_TEST_UNTRACKED_CACHE") &&
2310 + if (force_untracked_cache &&
2311 dir->untracked == istate->untracked &&
2312 (dir->untracked->dir_opened ||
2313 dir->untracked->gitignore_invalidated ||
t/t7063-status-untracked-cache.sh
+2 -2
@@ -14,8 +14,8 @@ test_description='test untracked cache'
14 # See <20160803174522.5571-1-pclouds@gmail.com> if you want to know
15 # more.
16
17 -GIT_TEST_UNTRACKED_CACHE=true
18 -export GIT_TEST_UNTRACKED_CACHE
17 +GIT_FORCE_UNTRACKED_CACHE=true
18 +export GIT_FORCE_UNTRACKED_CACHE
19
20 sync_mtime () {
21 find . -type d -ls >/dev/null