blob: 3dbd3f0e2ec33df0753780f4d84605b16ebdc2b3 [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"
Jeff Hostetler62c73672022-03-25 18:02:51 +00005#include "compat/fsmonitor/fsm-listen.h"
Derrick Stolee7211b9e2019-08-13 11:37:43 -07006
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +02007static void repo_cfg_bool(struct repository *r, const char *key, int *dest,
8 int def)
9{
10 if (repo_config_get_bool(r, key, dest))
11 *dest = def;
12}
Derrick Stolee31b1de62019-08-13 11:37:45 -070013
Taylor Blaua92d8522022-07-14 14:43:06 -070014static void repo_cfg_int(struct repository *r, const char *key, int *dest,
15 int def)
16{
17 if (repo_config_get_int(r, key, dest))
18 *dest = def;
19}
20
Derrick Stolee7211b9e2019-08-13 11:37:43 -070021void prepare_repo_settings(struct repository *r)
22{
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020023 int experimental;
Derrick Stolee7211b9e2019-08-13 11:37:43 -070024 int value;
Jeff King66eede42022-09-08 01:02:50 -040025 const char *strval;
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020026 int manyfiles;
Derrick Stolee7211b9e2019-08-13 11:37:43 -070027
Lessley Dennington44c7e622021-12-06 15:55:58 +000028 if (!r->gitdir)
29 BUG("Cannot add settings for uninitialized repository");
30
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020031 if (r->settings.initialized++)
Derrick Stolee7211b9e2019-08-13 11:37:43 -070032 return;
33
34 /* Defaults */
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020035 r->settings.index_version = -1;
36 r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
Elijah Newren714edc62022-02-02 03:42:40 +000037 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE;
Derrick Stolee7211b9e2019-08-13 11:37:43 -070038
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020039 /* Booleans config or default, cascades to other settings */
40 repo_cfg_bool(r, "feature.manyfiles", &manyfiles, 0);
41 repo_cfg_bool(r, "feature.experimental", &experimental, 0);
Derrick Stolee7211b9e2019-08-13 11:37:43 -070042
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020043 /* Defaults modified by feature.* */
44 if (experimental) {
45 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
Emily Shafferc6955922022-10-26 17:32:45 -040046 r->settings.gc_cruft_packs = 1;
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020047 }
48 if (manyfiles) {
49 r->settings.index_version = 4;
Derrick Stolee17194b12023-01-06 16:31:56 +000050 r->settings.index_skip_hash = 1;
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020051 r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE;
52 }
53
Taylor Blaua92d8522022-07-14 14:43:06 -070054 /* Commit graph config or default, does not cascade (simple) */
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020055 repo_cfg_bool(r, "core.commitgraph", &r->settings.core_commit_graph, 1);
Taylor Blaua92d8522022-07-14 14:43:06 -070056 repo_cfg_int(r, "commitgraph.generationversion", &r->settings.commit_graph_generation_version, 2);
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020057 repo_cfg_bool(r, "commitgraph.readchangedpaths", &r->settings.commit_graph_read_changed_paths, 1);
58 repo_cfg_bool(r, "gc.writecommitgraph", &r->settings.gc_write_commit_graph, 1);
59 repo_cfg_bool(r, "fetch.writecommitgraph", &r->settings.fetch_write_commit_graph, 0);
Taylor Blaua92d8522022-07-14 14:43:06 -070060
61 /* Boolean config or default, does not cascade (simple) */
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020062 repo_cfg_bool(r, "pack.usesparse", &r->settings.pack_use_sparse, 1);
63 repo_cfg_bool(r, "core.multipackindex", &r->settings.core_multi_pack_index, 1);
Ævar Arnfjörð Bjarmasonc21919f2021-09-21 15:13:03 +020064 repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 0);
Derrick Stolee17194b12023-01-06 16:31:56 +000065 repo_cfg_bool(r, "index.skiphash", &r->settings.index_skip_hash, r->settings.index_skip_hash);
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020066
67 /*
68 * The GIT_TEST_MULTI_PACK_INDEX variable is special in that
69 * either it *or* the config sets
70 * r->settings.core_multi_pack_index if true. We don't take
71 * the environment variable if it exists (even if false) over
72 * any config, as in most other cases.
73 */
74 if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0))
75 r->settings.core_multi_pack_index = 1;
76
77 /*
78 * Non-boolean config
79 */
Derrick Stoleec11e9962019-10-23 20:38:57 +000080 if (!repo_config_get_int(r, "index.version", &value))
Derrick Stolee7211b9e2019-08-13 11:37:43 -070081 r->settings.index_version = value;
Derrick Stoleead0fb652019-08-13 11:37:46 -070082
Jeff King66eede42022-09-08 01:02:50 -040083 if (!repo_config_get_string_tmp(r, "core.untrackedcache", &strval)) {
Ævar Arnfjörð Bjarmason3050b6d2021-09-21 15:13:02 +020084 int v = git_parse_maybe_bool(strval);
85
86 /*
87 * If it's set to "keep", or some other non-boolean
88 * value then "v < 0". Then we do nothing and keep it
89 * at the default of UNTRACKED_CACHE_KEEP.
90 */
91 if (v >= 0)
92 r->settings.core_untracked_cache = v ?
93 UNTRACKED_CACHE_WRITE : UNTRACKED_CACHE_REMOVE;
Derrick Stoleead0fb652019-08-13 11:37:46 -070094 }
95
Jeff King66eede42022-09-08 01:02:50 -040096 if (!repo_config_get_string_tmp(r, "fetch.negotiationalgorithm", &strval)) {
Elijah Newren714edc62022-02-02 03:42:40 +000097 int fetch_default = r->settings.fetch_negotiation_algorithm;
Derrick Stoleeaaf633c2019-08-13 11:37:48 -070098 if (!strcasecmp(strval, "skipping"))
99 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
Jonathan Tancbe566a2020-08-17 21:01:31 -0700100 else if (!strcasecmp(strval, "noop"))
101 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_NOOP;
Elijah Newren714edc62022-02-02 03:42:40 +0000102 else if (!strcasecmp(strval, "consecutive"))
103 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE;
Elijah Newrena68c5b92022-02-02 03:42:38 +0000104 else if (!strcasecmp(strval, "default"))
Elijah Newren714edc62022-02-02 03:42:40 +0000105 r->settings.fetch_negotiation_algorithm = fetch_default;
Elijah Newrena9a136c2022-02-02 03:42:39 +0000106 else
107 die("unknown fetch negotiation algorithm '%s'", strval);
Derrick Stoleeaaf633c2019-08-13 11:37:48 -0700108 }
109
Derrick Stolee3964fc22021-03-30 13:10:47 +0000110 /*
111 * This setting guards all index reads to require a full index
112 * over a sparse index. After suitable guards are placed in the
113 * codebase around uses of the index, this setting will be
114 * removed.
115 */
116 r->settings.command_requires_full_index = 1;
Derrick Stolee7211b9e2019-08-13 11:37:43 -0700117}