]> git.ipfire.org Git - thirdparty/git.git/blame - repo-settings.c
Documentation/RelNotes/2.45.0.txt: fix typo
[thirdparty/git.git] / repo-settings.c
CommitLineData
15db4e7f 1#include "git-compat-util.h"
7211b9e7
DS
2#include "config.h"
3#include "repository.h"
18e449f8 4#include "midx.h"
7211b9e7 5
3050b6df
ÆAB
6static 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}
31b1de6a 12
a92d8523
TB
13static void repo_cfg_int(struct repository *r, const char *key, int *dest,
14 int def)
15{
16 if (repo_config_get_int(r, key, dest))
17 *dest = def;
18}
19
7211b9e7
DS
20void prepare_repo_settings(struct repository *r)
21{
3050b6df 22 int experimental;
7211b9e7 23 int value;
66eede4a 24 const char *strval;
3050b6df 25 int manyfiles;
7211b9e7 26
44c7e62e
LD
27 if (!r->gitdir)
28 BUG("Cannot add settings for uninitialized repository");
29
3050b6df 30 if (r->settings.initialized++)
7211b9e7
DS
31 return;
32
33 /* Defaults */
3050b6df
ÆAB
34 r->settings.index_version = -1;
35 r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
714edc62 36 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE;
3050b6df
ÆAB
37
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);
7211b9e7 41
3050b6df 42 /* Defaults modified by feature.* */
b0afdce5 43 if (experimental) {
3050b6df 44 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
b0afdce5 45 r->settings.pack_use_bitmap_boundary_traversal = 1;
23c1e713 46 r->settings.pack_use_multi_pack_reuse = 1;
b0afdce5 47 }
3050b6df
ÆAB
48 if (manyfiles) {
49 r->settings.index_version = 4;
17194b19 50 r->settings.index_skip_hash = 1;
3050b6df
ÆAB
51 r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE;
52 }
53
a92d8523 54 /* Commit graph config or default, does not cascade (simple) */
3050b6df 55 repo_cfg_bool(r, "core.commitgraph", &r->settings.core_commit_graph, 1);
a92d8523 56 repo_cfg_int(r, "commitgraph.generationversion", &r->settings.commit_graph_generation_version, 2);
3050b6df
ÆAB
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);
a92d8523
TB
60
61 /* Boolean config or default, does not cascade (simple) */
3050b6df
ÆAB
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);
c21919f1 64 repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 0);
17194b19 65 repo_cfg_bool(r, "index.skiphash", &r->settings.index_skip_hash, r->settings.index_skip_hash);
dbcf6116 66 repo_cfg_bool(r, "pack.readreverseindex", &r->settings.pack_read_reverse_index, 1);
b0afdce5
TB
67 repo_cfg_bool(r, "pack.usebitmapboundarytraversal",
68 &r->settings.pack_use_bitmap_boundary_traversal,
69 r->settings.pack_use_bitmap_boundary_traversal);
9c7d1b05 70 repo_cfg_bool(r, "core.usereplacerefs", &r->settings.read_replace_refs, 1);
3050b6df
ÆAB
71
72 /*
73 * The GIT_TEST_MULTI_PACK_INDEX variable is special in that
74 * either it *or* the config sets
75 * r->settings.core_multi_pack_index if true. We don't take
76 * the environment variable if it exists (even if false) over
77 * any config, as in most other cases.
78 */
79 if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0))
80 r->settings.core_multi_pack_index = 1;
7211b9e7 81
3050b6df
ÆAB
82 /*
83 * Non-boolean config
84 */
c11e9966 85 if (!repo_config_get_int(r, "index.version", &value))
7211b9e7 86 r->settings.index_version = value;
ad0fb659 87
66eede4a 88 if (!repo_config_get_string_tmp(r, "core.untrackedcache", &strval)) {
3050b6df
ÆAB
89 int v = git_parse_maybe_bool(strval);
90
91 /*
92 * If it's set to "keep", or some other non-boolean
93 * value then "v < 0". Then we do nothing and keep it
94 * at the default of UNTRACKED_CACHE_KEEP.
95 */
96 if (v >= 0)
97 r->settings.core_untracked_cache = v ?
98 UNTRACKED_CACHE_WRITE : UNTRACKED_CACHE_REMOVE;
ad0fb659
DS
99 }
100
66eede4a 101 if (!repo_config_get_string_tmp(r, "fetch.negotiationalgorithm", &strval)) {
714edc62 102 int fetch_default = r->settings.fetch_negotiation_algorithm;
aaf633c2
DS
103 if (!strcasecmp(strval, "skipping"))
104 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
cbe566a0
JT
105 else if (!strcasecmp(strval, "noop"))
106 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_NOOP;
714edc62
EN
107 else if (!strcasecmp(strval, "consecutive"))
108 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE;
a68c5b9e 109 else if (!strcasecmp(strval, "default"))
714edc62 110 r->settings.fetch_negotiation_algorithm = fetch_default;
a9a136c2
EN
111 else
112 die("unknown fetch negotiation algorithm '%s'", strval);
aaf633c2
DS
113 }
114
3964fc2a
DS
115 /*
116 * This setting guards all index reads to require a full index
117 * over a sparse index. After suitable guards are placed in the
118 * codebase around uses of the index, this setting will be
119 * removed.
120 */
121 r->settings.command_requires_full_index = 1;
7211b9e7 122}