]> git.ipfire.org Git - thirdparty/git.git/blame - repo-settings.c
Merge branch 'ab/reflog-parse-options'
[thirdparty/git.git] / repo-settings.c
CommitLineData
7211b9e7
DS
1#include "cache.h"
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
7211b9e7
DS
13void prepare_repo_settings(struct repository *r)
14{
3050b6df 15 int experimental;
7211b9e7 16 int value;
ad0fb659 17 char *strval;
3050b6df 18 int manyfiles;
7211b9e7 19
44c7e62e
LD
20 if (!r->gitdir)
21 BUG("Cannot add settings for uninitialized repository");
22
3050b6df 23 if (r->settings.initialized++)
7211b9e7
DS
24 return;
25
26 /* Defaults */
3050b6df
ÆAB
27 r->settings.index_version = -1;
28 r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
714edc62 29 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE;
3050b6df
ÆAB
30
31 /* Booleans config or default, cascades to other settings */
32 repo_cfg_bool(r, "feature.manyfiles", &manyfiles, 0);
33 repo_cfg_bool(r, "feature.experimental", &experimental, 0);
7211b9e7 34
3050b6df
ÆAB
35 /* Defaults modified by feature.* */
36 if (experimental) {
37 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
38 }
39 if (manyfiles) {
40 r->settings.index_version = 4;
41 r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE;
42 }
43
44 /* Boolean config or default, does not cascade (simple) */
45 repo_cfg_bool(r, "core.commitgraph", &r->settings.core_commit_graph, 1);
46 repo_cfg_bool(r, "commitgraph.readchangedpaths", &r->settings.commit_graph_read_changed_paths, 1);
47 repo_cfg_bool(r, "gc.writecommitgraph", &r->settings.gc_write_commit_graph, 1);
48 repo_cfg_bool(r, "fetch.writecommitgraph", &r->settings.fetch_write_commit_graph, 0);
49 repo_cfg_bool(r, "pack.usesparse", &r->settings.pack_use_sparse, 1);
50 repo_cfg_bool(r, "core.multipackindex", &r->settings.core_multi_pack_index, 1);
c21919f1 51 repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 0);
3050b6df
ÆAB
52
53 /*
54 * The GIT_TEST_MULTI_PACK_INDEX variable is special in that
55 * either it *or* the config sets
56 * r->settings.core_multi_pack_index if true. We don't take
57 * the environment variable if it exists (even if false) over
58 * any config, as in most other cases.
59 */
60 if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0))
61 r->settings.core_multi_pack_index = 1;
7211b9e7 62
3050b6df
ÆAB
63 /*
64 * Non-boolean config
65 */
c11e9966 66 if (!repo_config_get_int(r, "index.version", &value))
7211b9e7 67 r->settings.index_version = value;
ad0fb659 68
3050b6df
ÆAB
69 if (!repo_config_get_string(r, "core.untrackedcache", &strval)) {
70 int v = git_parse_maybe_bool(strval);
71
72 /*
73 * If it's set to "keep", or some other non-boolean
74 * value then "v < 0". Then we do nothing and keep it
75 * at the default of UNTRACKED_CACHE_KEEP.
76 */
77 if (v >= 0)
78 r->settings.core_untracked_cache = v ?
79 UNTRACKED_CACHE_WRITE : UNTRACKED_CACHE_REMOVE;
ad0fb659
DS
80 free(strval);
81 }
82
aaf633c2 83 if (!repo_config_get_string(r, "fetch.negotiationalgorithm", &strval)) {
714edc62 84 int fetch_default = r->settings.fetch_negotiation_algorithm;
aaf633c2
DS
85 if (!strcasecmp(strval, "skipping"))
86 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
cbe566a0
JT
87 else if (!strcasecmp(strval, "noop"))
88 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_NOOP;
714edc62
EN
89 else if (!strcasecmp(strval, "consecutive"))
90 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE;
a68c5b9e 91 else if (!strcasecmp(strval, "default"))
714edc62 92 r->settings.fetch_negotiation_algorithm = fetch_default;
a9a136c2
EN
93 else
94 die("unknown fetch negotiation algorithm '%s'", strval);
aaf633c2
DS
95 }
96
3964fc2a
DS
97 /*
98 * This setting guards all index reads to require a full index
99 * over a sparse index. After suitable guards are placed in the
100 * codebase around uses of the index, this setting will be
101 * removed.
102 */
103 r->settings.command_requires_full_index = 1;
7211b9e7 104}