Merge branch 'nb/rebase-x-shell-docfix' into maint-2.43
[git.git] / repo-settings.c
blob30cd4787627b7cacbc2dbceddc0babee1b72cb3e
1 #include "git-compat-util.h"
2 #include "config.h"
3 #include "repository.h"
4 #include "midx.h"
6 static void repo_cfg_bool(struct repository *r, const char *key, int *dest,
7 int def)
9 if (repo_config_get_bool(r, key, dest))
10 *dest = def;
13 static void repo_cfg_int(struct repository *r, const char *key, int *dest,
14 int def)
16 if (repo_config_get_int(r, key, dest))
17 *dest = def;
20 void prepare_repo_settings(struct repository *r)
22 int experimental;
23 int value;
24 const char *strval;
25 int manyfiles;
27 if (!r->gitdir)
28 BUG("Cannot add settings for uninitialized repository");
30 if (r->settings.initialized++)
31 return;
33 /* Defaults */
34 r->settings.index_version = -1;
35 r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
36 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE;
38 /* Booleans config or default, cascades to other settings */
39 repo_cfg_bool(r, "feature.manyfiles", &manyfiles, 0);
40 repo_cfg_bool(r, "feature.experimental", &experimental, 0);
42 /* Defaults modified by feature.* */
43 if (experimental) {
44 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
45 r->settings.pack_use_bitmap_boundary_traversal = 1;
47 if (manyfiles) {
48 r->settings.index_version = 4;
49 r->settings.index_skip_hash = 1;
50 r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE;
53 /* Commit graph config or default, does not cascade (simple) */
54 repo_cfg_bool(r, "core.commitgraph", &r->settings.core_commit_graph, 1);
55 repo_cfg_int(r, "commitgraph.generationversion", &r->settings.commit_graph_generation_version, 2);
56 repo_cfg_bool(r, "commitgraph.readchangedpaths", &r->settings.commit_graph_read_changed_paths, 1);
57 repo_cfg_bool(r, "gc.writecommitgraph", &r->settings.gc_write_commit_graph, 1);
58 repo_cfg_bool(r, "fetch.writecommitgraph", &r->settings.fetch_write_commit_graph, 0);
60 /* Boolean config or default, does not cascade (simple) */
61 repo_cfg_bool(r, "pack.usesparse", &r->settings.pack_use_sparse, 1);
62 repo_cfg_bool(r, "core.multipackindex", &r->settings.core_multi_pack_index, 1);
63 repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 0);
64 repo_cfg_bool(r, "index.skiphash", &r->settings.index_skip_hash, r->settings.index_skip_hash);
65 repo_cfg_bool(r, "pack.readreverseindex", &r->settings.pack_read_reverse_index, 1);
66 repo_cfg_bool(r, "pack.usebitmapboundarytraversal",
67 &r->settings.pack_use_bitmap_boundary_traversal,
68 r->settings.pack_use_bitmap_boundary_traversal);
69 repo_cfg_bool(r, "core.usereplacerefs", &r->settings.read_replace_refs, 1);
72 * The GIT_TEST_MULTI_PACK_INDEX variable is special in that
73 * either it *or* the config sets
74 * r->settings.core_multi_pack_index if true. We don't take
75 * the environment variable if it exists (even if false) over
76 * any config, as in most other cases.
78 if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0))
79 r->settings.core_multi_pack_index = 1;
82 * Non-boolean config
84 if (!repo_config_get_int(r, "index.version", &value))
85 r->settings.index_version = value;
87 if (!repo_config_get_string_tmp(r, "core.untrackedcache", &strval)) {
88 int v = git_parse_maybe_bool(strval);
91 * If it's set to "keep", or some other non-boolean
92 * value then "v < 0". Then we do nothing and keep it
93 * at the default of UNTRACKED_CACHE_KEEP.
95 if (v >= 0)
96 r->settings.core_untracked_cache = v ?
97 UNTRACKED_CACHE_WRITE : UNTRACKED_CACHE_REMOVE;
100 if (!repo_config_get_string_tmp(r, "fetch.negotiationalgorithm", &strval)) {
101 int fetch_default = r->settings.fetch_negotiation_algorithm;
102 if (!strcasecmp(strval, "skipping"))
103 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
104 else if (!strcasecmp(strval, "noop"))
105 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_NOOP;
106 else if (!strcasecmp(strval, "consecutive"))
107 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE;
108 else if (!strcasecmp(strval, "default"))
109 r->settings.fetch_negotiation_algorithm = fetch_default;
110 else
111 die("unknown fetch negotiation algorithm '%s'", strval);
115 * This setting guards all index reads to require a full index
116 * over a sparse index. After suitable guards are placed in the
117 * codebase around uses of the index, this setting will be
118 * removed.
120 r->settings.command_requires_full_index = 1;