treewide: be explicit about dependence on oid-array.h
[alt-git.git] / repo-settings.c
blob0a6c0b381fe13b50fb14b5b6e31ca06c0d44f695
1 #include "git-compat-util.h"
2 #include "config.h"
3 #include "repository.h"
4 #include "midx.h"
5 #include "compat/fsmonitor/fsm-listen.h"
7 static void repo_cfg_bool(struct repository *r, const char *key, int *dest,
8 int def)
10 if (repo_config_get_bool(r, key, dest))
11 *dest = def;
14 static void repo_cfg_int(struct repository *r, const char *key, int *dest,
15 int def)
17 if (repo_config_get_int(r, key, dest))
18 *dest = def;
21 void prepare_repo_settings(struct repository *r)
23 int experimental;
24 int value;
25 const char *strval;
26 int manyfiles;
28 if (!r->gitdir)
29 BUG("Cannot add settings for uninitialized repository");
31 if (r->settings.initialized++)
32 return;
34 /* Defaults */
35 r->settings.index_version = -1;
36 r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
37 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE;
39 /* 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);
43 /* Defaults modified by feature.* */
44 if (experimental) {
45 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
46 r->settings.gc_cruft_packs = 1;
48 if (manyfiles) {
49 r->settings.index_version = 4;
50 r->settings.index_skip_hash = 1;
51 r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE;
54 /* Commit graph config or default, does not cascade (simple) */
55 repo_cfg_bool(r, "core.commitgraph", &r->settings.core_commit_graph, 1);
56 repo_cfg_int(r, "commitgraph.generationversion", &r->settings.commit_graph_generation_version, 2);
57 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);
61 /* Boolean config or default, does not cascade (simple) */
62 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);
64 repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 0);
65 repo_cfg_bool(r, "index.skiphash", &r->settings.index_skip_hash, r->settings.index_skip_hash);
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.
74 if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0))
75 r->settings.core_multi_pack_index = 1;
78 * Non-boolean config
80 if (!repo_config_get_int(r, "index.version", &value))
81 r->settings.index_version = value;
83 if (!repo_config_get_string_tmp(r, "core.untrackedcache", &strval)) {
84 int v = git_parse_maybe_bool(strval);
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.
91 if (v >= 0)
92 r->settings.core_untracked_cache = v ?
93 UNTRACKED_CACHE_WRITE : UNTRACKED_CACHE_REMOVE;
96 if (!repo_config_get_string_tmp(r, "fetch.negotiationalgorithm", &strval)) {
97 int fetch_default = r->settings.fetch_negotiation_algorithm;
98 if (!strcasecmp(strval, "skipping"))
99 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
100 else if (!strcasecmp(strval, "noop"))
101 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_NOOP;
102 else if (!strcasecmp(strval, "consecutive"))
103 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE;
104 else if (!strcasecmp(strval, "default"))
105 r->settings.fetch_negotiation_algorithm = fetch_default;
106 else
107 die("unknown fetch negotiation algorithm '%s'", strval);
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.
116 r->settings.command_requires_full_index = 1;