scalar: teach 'clone' to support the --single-branch option
[git/debian.git] / repo-settings.c
blobb93e91a212eb98aae494acc544edcd71b77a4761
1 #include "cache.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 void prepare_repo_settings(struct repository *r)
15 int experimental;
16 int value;
17 char *strval;
18 int manyfiles;
20 if (r->settings.initialized++)
21 return;
23 /* Defaults */
24 r->settings.index_version = -1;
25 r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
26 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_DEFAULT;
28 /* Booleans config or default, cascades to other settings */
29 repo_cfg_bool(r, "feature.manyfiles", &manyfiles, 0);
30 repo_cfg_bool(r, "feature.experimental", &experimental, 0);
32 /* Defaults modified by feature.* */
33 if (experimental) {
34 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
36 if (manyfiles) {
37 r->settings.index_version = 4;
38 r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE;
41 /* Boolean config or default, does not cascade (simple) */
42 repo_cfg_bool(r, "core.commitgraph", &r->settings.core_commit_graph, 1);
43 repo_cfg_bool(r, "commitgraph.readchangedpaths", &r->settings.commit_graph_read_changed_paths, 1);
44 repo_cfg_bool(r, "gc.writecommitgraph", &r->settings.gc_write_commit_graph, 1);
45 repo_cfg_bool(r, "fetch.writecommitgraph", &r->settings.fetch_write_commit_graph, 0);
46 repo_cfg_bool(r, "pack.usesparse", &r->settings.pack_use_sparse, 1);
47 repo_cfg_bool(r, "core.multipackindex", &r->settings.core_multi_pack_index, 1);
48 repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 0);
51 * The GIT_TEST_MULTI_PACK_INDEX variable is special in that
52 * either it *or* the config sets
53 * r->settings.core_multi_pack_index if true. We don't take
54 * the environment variable if it exists (even if false) over
55 * any config, as in most other cases.
57 if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0))
58 r->settings.core_multi_pack_index = 1;
61 * Non-boolean config
63 if (!repo_config_get_int(r, "index.version", &value))
64 r->settings.index_version = value;
66 if (!repo_config_get_string(r, "core.untrackedcache", &strval)) {
67 int v = git_parse_maybe_bool(strval);
70 * If it's set to "keep", or some other non-boolean
71 * value then "v < 0". Then we do nothing and keep it
72 * at the default of UNTRACKED_CACHE_KEEP.
74 if (v >= 0)
75 r->settings.core_untracked_cache = v ?
76 UNTRACKED_CACHE_WRITE : UNTRACKED_CACHE_REMOVE;
77 free(strval);
80 if (!repo_config_get_string(r, "fetch.negotiationalgorithm", &strval)) {
81 if (!strcasecmp(strval, "skipping"))
82 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
83 else if (!strcasecmp(strval, "noop"))
84 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_NOOP;
88 * This setting guards all index reads to require a full index
89 * over a sparse index. After suitable guards are placed in the
90 * codebase around uses of the index, this setting will be
91 * removed.
93 r->settings.command_requires_full_index = 1;