1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-06 13:26:12 +02:00
git/repo-settings.c
Derrick Stolee ad0fb65999 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>
2019-08-13 13:33:55 -07:00

49 lines
1.5 KiB
C

#include "cache.h"
#include "config.h"
#include "repository.h"
#define UPDATE_DEFAULT_BOOL(s,v) do { if (s == -1) { s = v; } } while(0)
void prepare_repo_settings(struct repository *r)
{
int value;
char *strval;
if (r->settings.initialized)
return;
/* Defaults */
memset(&r->settings, -1, sizeof(r->settings));
if (!repo_config_get_bool(r, "core.commitgraph", &value))
r->settings.core_commit_graph = value;
if (!repo_config_get_bool(r, "gc.writecommitgraph", &value))
r->settings.gc_write_commit_graph = value;
UPDATE_DEFAULT_BOOL(r->settings.core_commit_graph, 1);
UPDATE_DEFAULT_BOOL(r->settings.gc_write_commit_graph, 1);
if (!repo_config_get_bool(r, "index.version", &value))
r->settings.index_version = value;
if (!repo_config_get_maybe_bool(r, "core.untrackedcache", &value)) {
if (value == 0)
r->settings.core_untracked_cache = UNTRACKED_CACHE_REMOVE;
else
r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE;
} else if (!repo_config_get_string(r, "core.untrackedcache", &strval)) {
if (!strcasecmp(strval, "keep"))
r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
free(strval);
}
if (!repo_config_get_bool(r, "pack.usesparse", &value))
r->settings.pack_use_sparse = value;
/* Hack for test programs like test-dump-untracked-cache */
if (ignore_untracked_cache_config)
r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
else
UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_KEEP);
}