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