Skip to content

Commit 026336c

Browse files
committed
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 <[email protected]>
1 parent fc9ecbe commit 026336c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

dir.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,8 +2164,13 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
21642164
const struct pathspec *pathspec)
21652165
{
21662166
struct untracked_cache_dir *root;
2167+
static int untracked_cache_disabled = -1;
21672168

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)
21692174
return NULL;
21702175

21712176
/*
@@ -2287,7 +2292,12 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
22872292
}
22882293

22892294
if (dir->untracked) {
2295+
static int force_untracked_cache = -1;
22902296
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);
22912301
trace_printf_key(&trace_untracked_stats,
22922302
"node creation: %u\n"
22932303
"gitignore invalidation: %u\n"
@@ -2297,7 +2307,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
22972307
dir->untracked->gitignore_invalidated,
22982308
dir->untracked->dir_invalidated,
22992309
dir->untracked->dir_opened);
2300-
if (getenv("GIT_TEST_UNTRACKED_CACHE") &&
2310+
if (force_untracked_cache &&
23012311
dir->untracked == istate->untracked &&
23022312
(dir->untracked->dir_opened ||
23032313
dir->untracked->gitignore_invalidated ||

t/t7063-status-untracked-cache.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ 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
17+
GIT_FORCE_UNTRACKED_CACHE=true
18+
export GIT_FORCE_UNTRACKED_CACHE
1919

2020
sync_mtime () {
2121
find . -type d -ls >/dev/null

0 commit comments

Comments
 (0)