Skip to content

Commit ec0abff

Browse files
committed
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 <[email protected]>
1 parent 651e2d5 commit ec0abff

File tree

5 files changed

+40
-36
lines changed

5 files changed

+40
-36
lines changed

builtin/update-index.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
966966
struct parse_opt_ctx_t ctx;
967967
strbuf_getline_fn getline_fn;
968968
int parseopt_state = PARSE_OPT_UNKNOWN;
969+
struct repository *r = the_repository;
969970
struct option options[] = {
970971
OPT_BIT('q', NULL, &refresh_args.flags,
971972
N_("continue refresh even when index needs update"),
@@ -1180,11 +1181,12 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11801181
remove_split_index(&the_index);
11811182
}
11821183

1184+
prepare_repo_settings(r);
11831185
switch (untracked_cache) {
11841186
case UC_UNSPECIFIED:
11851187
break;
11861188
case UC_DISABLE:
1187-
if (git_config_get_untracked_cache() == 1)
1189+
if (r->settings.core_untracked_cache == UNTRACKED_CACHE_WRITE)
11881190
warning(_("core.untrackedCache is set to true; "
11891191
"remove or change it, if you really want to "
11901192
"disable the untracked cache"));
@@ -1196,7 +1198,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11961198
return !test_if_untracked_cache_is_supported();
11971199
case UC_ENABLE:
11981200
case UC_FORCE:
1199-
if (git_config_get_untracked_cache() == 0)
1201+
if (r->settings.core_untracked_cache == UNTRACKED_CACHE_REMOVE)
12001202
warning(_("core.untrackedCache is set to false; "
12011203
"remove or change it, if you really want to "
12021204
"enable the untracked cache"));

config.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,30 +2277,6 @@ int git_config_get_expiry_in_days(const char *key, timestamp_t *expiry, timestam
22772277
return -1; /* thing exists but cannot be parsed */
22782278
}
22792279

2280-
int git_config_get_untracked_cache(void)
2281-
{
2282-
int val = -1;
2283-
const char *v;
2284-
2285-
/* Hack for test programs like test-dump-untracked-cache */
2286-
if (ignore_untracked_cache_config)
2287-
return -1;
2288-
2289-
if (!git_config_get_maybe_bool("core.untrackedcache", &val))
2290-
return val;
2291-
2292-
if (!git_config_get_value("core.untrackedcache", &v)) {
2293-
if (!strcasecmp(v, "keep"))
2294-
return -1;
2295-
2296-
error(_("unknown core.untrackedCache value '%s'; "
2297-
"using 'keep' default value"), v);
2298-
return -1;
2299-
}
2300-
2301-
return -1; /* default value */
2302-
}
2303-
23042280
int git_config_get_split_index(void)
23052281
{
23062282
int val;

read-cache.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,18 +1845,17 @@ static void check_ce_order(struct index_state *istate)
18451845

18461846
static void tweak_untracked_cache(struct index_state *istate)
18471847
{
1848-
switch (git_config_get_untracked_cache()) {
1849-
case -1: /* keep: do nothing */
1850-
break;
1851-
case 0: /* false */
1848+
struct repository *r = the_repository;
1849+
1850+
prepare_repo_settings(r);
1851+
1852+
if (r->settings.core_untracked_cache == UNTRACKED_CACHE_REMOVE) {
18521853
remove_untracked_cache(istate);
1853-
break;
1854-
case 1: /* true */
1855-
add_untracked_cache(istate);
1856-
break;
1857-
default: /* unknown value: do nothing */
1858-
break;
1854+
return;
18591855
}
1856+
1857+
if (r->settings.core_untracked_cache == UNTRACKED_CACHE_WRITE)
1858+
add_untracked_cache(istate);
18601859
}
18611860

18621861
static void tweak_split_index(struct index_state *istate)

repo-settings.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
void prepare_repo_settings(struct repository *r)
88
{
99
int value;
10+
char *strval;
1011

1112
if (r->settings.initialized)
1213
return;
@@ -23,7 +24,25 @@ void prepare_repo_settings(struct repository *r)
2324

2425
if (!repo_config_get_bool(r, "index.version", &value))
2526
r->settings.index_version = value;
27+
if (!repo_config_get_maybe_bool(r, "core.untrackedcache", &value)) {
28+
if (value == 0)
29+
r->settings.core_untracked_cache = UNTRACKED_CACHE_REMOVE;
30+
else
31+
r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE;
32+
} else if (!repo_config_get_string(r, "core.untrackedcache", &strval)) {
33+
if (!strcasecmp(strval, "keep"))
34+
r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
35+
36+
free(strval);
37+
}
38+
2639

2740
if (!repo_config_get_bool(r, "pack.usesparse", &value))
2841
r->settings.pack_use_sparse = value;
42+
43+
/* Hack for test programs like test-dump-untracked-cache */
44+
if (ignore_untracked_cache_config)
45+
r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
46+
else
47+
UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_KEEP);
2948
}

repository.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,21 @@ struct pathspec;
1111
struct raw_object_store;
1212
struct submodule_cache;
1313

14+
enum untracked_cache_setting {
15+
UNTRACKED_CACHE_UNSET = -1,
16+
UNTRACKED_CACHE_REMOVE = 0,
17+
UNTRACKED_CACHE_KEEP = 1,
18+
UNTRACKED_CACHE_WRITE = 2
19+
};
20+
1421
struct repo_settings {
1522
int initialized;
1623

1724
int core_commit_graph;
1825
int gc_write_commit_graph;
1926

2027
int index_version;
28+
enum untracked_cache_setting core_untracked_cache;
2129

2230
int pack_use_sparse;
2331
};

0 commit comments

Comments
 (0)