sparse-checkout: fill in some options boilerplate
[git/debian.git] / repo-settings.c
blob88ccce2036b611f7ea1e6d8ac538f9ee4e155395
1 #include "cache.h"
2 #include "config.h"
3 #include "repository.h"
5 #define UPDATE_DEFAULT_BOOL(s,v) do { if (s == -1) { s = v; } } while(0)
7 void prepare_repo_settings(struct repository *r)
9 int value;
10 char *strval;
12 if (r->settings.initialized)
13 return;
15 /* Defaults */
16 memset(&r->settings, -1, sizeof(r->settings));
18 if (!repo_config_get_bool(r, "core.commitgraph", &value))
19 r->settings.core_commit_graph = value;
20 if (!repo_config_get_bool(r, "commitgraph.readchangedpaths", &value))
21 r->settings.commit_graph_read_changed_paths = value;
22 if (!repo_config_get_bool(r, "gc.writecommitgraph", &value))
23 r->settings.gc_write_commit_graph = value;
24 UPDATE_DEFAULT_BOOL(r->settings.core_commit_graph, 1);
25 UPDATE_DEFAULT_BOOL(r->settings.commit_graph_read_changed_paths, 1);
26 UPDATE_DEFAULT_BOOL(r->settings.gc_write_commit_graph, 1);
28 if (!repo_config_get_int(r, "index.version", &value))
29 r->settings.index_version = value;
30 if (!repo_config_get_maybe_bool(r, "core.untrackedcache", &value)) {
31 if (value == 0)
32 r->settings.core_untracked_cache = UNTRACKED_CACHE_REMOVE;
33 else
34 r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE;
35 } else if (!repo_config_get_string(r, "core.untrackedcache", &strval)) {
36 if (!strcasecmp(strval, "keep"))
37 r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
39 free(strval);
42 if (!repo_config_get_string(r, "fetch.negotiationalgorithm", &strval)) {
43 if (!strcasecmp(strval, "skipping"))
44 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
45 else if (!strcasecmp(strval, "noop"))
46 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_NOOP;
47 else
48 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_DEFAULT;
51 if (!repo_config_get_bool(r, "pack.usesparse", &value))
52 r->settings.pack_use_sparse = value;
53 UPDATE_DEFAULT_BOOL(r->settings.pack_use_sparse, 1);
55 if (!repo_config_get_bool(r, "feature.manyfiles", &value) && value) {
56 UPDATE_DEFAULT_BOOL(r->settings.index_version, 4);
57 UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_WRITE);
60 if (!repo_config_get_bool(r, "fetch.writecommitgraph", &value))
61 r->settings.fetch_write_commit_graph = value;
62 UPDATE_DEFAULT_BOOL(r->settings.fetch_write_commit_graph, 0);
64 if (!repo_config_get_bool(r, "feature.experimental", &value) && value)
65 UPDATE_DEFAULT_BOOL(r->settings.fetch_negotiation_algorithm, FETCH_NEGOTIATION_SKIPPING);
67 /* Hack for test programs like test-dump-untracked-cache */
68 if (ignore_untracked_cache_config)
69 r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
70 else
71 UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_KEEP);
73 UPDATE_DEFAULT_BOOL(r->settings.fetch_negotiation_algorithm, FETCH_NEGOTIATION_DEFAULT);