blob: b93e91a212eb98aae494acc544edcd71b77a4761 [file] [log] [blame]
Derrick Stolee7211b9e2019-08-13 11:37:43 -07001#include "cache.h"
2#include "config.h"
3#include "repository.h"
Derrick Stolee18e449f2020-09-25 12:33:34 +00004#include "midx.h"
Derrick Stolee7211b9e2019-08-13 11:37:43 -07005
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +02006static void repo_cfg_bool(struct repository *r, const char *key, int *dest,
7 int def)
8{
9 if (repo_config_get_bool(r, key, dest))
10 *dest = def;
11}
Derrick Stolee31b1de62019-08-13 11:37:45 -070012
Derrick Stolee7211b9e2019-08-13 11:37:43 -070013void prepare_repo_settings(struct repository *r)
14{
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020015 int experimental;
Derrick Stolee7211b9e2019-08-13 11:37:43 -070016 int value;
Derrick Stoleead0fb652019-08-13 11:37:46 -070017 char *strval;
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020018 int manyfiles;
Derrick Stolee7211b9e2019-08-13 11:37:43 -070019
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020020 if (r->settings.initialized++)
Derrick Stolee7211b9e2019-08-13 11:37:43 -070021 return;
22
23 /* Defaults */
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020024 r->settings.index_version = -1;
25 r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
26 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_DEFAULT;
Derrick Stolee7211b9e2019-08-13 11:37:43 -070027
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020028 /* Booleans config or default, cascades to other settings */
29 repo_cfg_bool(r, "feature.manyfiles", &manyfiles, 0);
30 repo_cfg_bool(r, "feature.experimental", &experimental, 0);
Derrick Stolee7211b9e2019-08-13 11:37:43 -070031
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020032 /* Defaults modified by feature.* */
33 if (experimental) {
34 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
35 }
36 if (manyfiles) {
37 r->settings.index_version = 4;
38 r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE;
39 }
40
41 /* Boolean config or default, does not cascade (simple) */
42 repo_cfg_bool(r, "core.commitgraph", &r->settings.core_commit_graph, 1);
43 repo_cfg_bool(r, "commitgraph.readchangedpaths", &r->settings.commit_graph_read_changed_paths, 1);
44 repo_cfg_bool(r, "gc.writecommitgraph", &r->settings.gc_write_commit_graph, 1);
45 repo_cfg_bool(r, "fetch.writecommitgraph", &r->settings.fetch_write_commit_graph, 0);
46 repo_cfg_bool(r, "pack.usesparse", &r->settings.pack_use_sparse, 1);
47 repo_cfg_bool(r, "core.multipackindex", &r->settings.core_multi_pack_index, 1);
Ævar Arnfjörð Bjarmasonc21919f2021-09-21 15:13:03 +020048 repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 0);
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020049
50 /*
51 * The GIT_TEST_MULTI_PACK_INDEX variable is special in that
52 * either it *or* the config sets
53 * r->settings.core_multi_pack_index if true. We don't take
54 * the environment variable if it exists (even if false) over
55 * any config, as in most other cases.
56 */
57 if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0))
58 r->settings.core_multi_pack_index = 1;
59
60 /*
61 * Non-boolean config
62 */
Derrick Stoleec11e9962019-10-23 20:38:57 +000063 if (!repo_config_get_int(r, "index.version", &value))
Derrick Stolee7211b9e2019-08-13 11:37:43 -070064 r->settings.index_version = value;
Derrick Stoleead0fb652019-08-13 11:37:46 -070065
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020066 if (!repo_config_get_string(r, "core.untrackedcache", &strval)) {
67 int v = git_parse_maybe_bool(strval);
68
69 /*
70 * If it's set to "keep", or some other non-boolean
71 * value then "v < 0". Then we do nothing and keep it
72 * at the default of UNTRACKED_CACHE_KEEP.
73 */
74 if (v >= 0)
75 r->settings.core_untracked_cache = v ?
76 UNTRACKED_CACHE_WRITE : UNTRACKED_CACHE_REMOVE;
Derrick Stoleead0fb652019-08-13 11:37:46 -070077 free(strval);
78 }
79
Derrick Stoleeaaf633c2019-08-13 11:37:48 -070080 if (!repo_config_get_string(r, "fetch.negotiationalgorithm", &strval)) {
81 if (!strcasecmp(strval, "skipping"))
82 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
Jonathan Tancbe566a2020-08-17 21:01:31 -070083 else if (!strcasecmp(strval, "noop"))
84 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_NOOP;
Derrick Stoleeaaf633c2019-08-13 11:37:48 -070085 }
86
Derrick Stolee3964fc22021-03-30 13:10:47 +000087 /*
88 * This setting guards all index reads to require a full index
89 * over a sparse index. After suitable guards are placed in the
90 * codebase around uses of the index, this setting will be
91 * removed.
92 */
93 r->settings.command_requires_full_index = 1;
Derrick Stolee7211b9e2019-08-13 11:37:43 -070094}