repo-settings: parse core.untrackedCache

The core.untrackedCache config setting is slightly complicated,
so clarify its use and centralize its parsing into the repo
settings.

The default value is "keep" (returned as -1), which persists the
untracked cache if it exists.

If the value is set as "false" (returned as 0), then remove the
untracked cache if it exists.

If the value is set as "true" (returned as 1), then write the
untracked cache and persist it.

Instead of relying on magic values of -1, 0, and 1, split these
options into an enum. This allows the use of "-1" as a
default value. After parsing the config options, if the value is
unset we can initialize it to UNTRACKED_CACHE_KEEP.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Derrick Stolee
2019-08-13 11:37:46 -07:00
committed by Junio C Hamano
parent 31b1de6a09
commit ad0fb65999
5 changed files with 40 additions and 36 deletions

View File

@ -2277,30 +2277,6 @@ int git_config_get_expiry_in_days(const char *key, timestamp_t *expiry, timestam
return -1; /* thing exists but cannot be parsed */
}
int git_config_get_untracked_cache(void)
{
int val = -1;
const char *v;
/* Hack for test programs like test-dump-untracked-cache */
if (ignore_untracked_cache_config)
return -1;
if (!git_config_get_maybe_bool("core.untrackedcache", &val))
return val;
if (!git_config_get_value("core.untrackedcache", &v)) {
if (!strcasecmp(v, "keep"))
return -1;
error(_("unknown core.untrackedCache value '%s'; "
"using 'keep' default value"), v);
return -1;
}
return -1; /* default value */
}
int git_config_get_split_index(void)
{
int val;