Raw
1 #include "git-compat-util.h"
2 #include "config.h"
3 #include "repo-settings.h"
4 #include "repository.h"
5 #include "midx.h"
6 #include "pack-objects.h"
7 #include "setup.h"
8
9 static void repo_cfg_bool(struct repository *r, const char *key, int *dest,
10 int def)
11 {
12 if (repo_config_get_bool(r, key, dest))
13 *dest = def;
14 }
15
16 static void repo_cfg_int(struct repository *r, const char *key, int *dest,
17 int def)
18 {
19 if (repo_config_get_int(r, key, dest))
20 *dest = def;
21 }
22
23 static void repo_cfg_ulong(struct repository *r, const char *key, unsigned long *dest,
24 unsigned long def)
25 {
26 if (repo_config_get_ulong(r, key, dest))
27 *dest = def;
28 }
29
30 void prepare_repo_settings(struct repository *r)
31 {
32 int experimental;
33 int value;
34 const char *strval;
35 int manyfiles;
36 int read_changed_paths;
37 unsigned long ulongval;
38
39 if (!r->gitdir)
40 BUG("Cannot add settings for uninitialized repository");
41
42 if (r->settings.initialized)
43 return;
44
45 repo_settings_clear(r);
46 r->settings.initialized++;
47
48 /* Booleans config or default, cascades to other settings */
49 repo_cfg_bool(r, "feature.manyfiles", &manyfiles, 0);
50 repo_cfg_bool(r, "feature.experimental", &experimental, 0);
51
52 /* Defaults modified by feature.* */
53 if (experimental) {
54 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
55 r->settings.pack_use_bitmap_boundary_traversal = 1;
56 r->settings.pack_use_multi_pack_reuse = 1;
57 r->settings.pack_use_path_walk = 1;
58 }
59 if (manyfiles) {
60 r->settings.index_version = 4;
61 r->settings.index_skip_hash = 1;
62 r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE;
63 r->settings.pack_use_path_walk = 1;
64 }
65
66 /* Commit graph config or default, does not cascade (simple) */
67 repo_cfg_bool(r, "core.commitgraph", &r->settings.core_commit_graph, 1);
68 repo_cfg_int(r, "commitgraph.generationversion", &r->settings.commit_graph_generation_version, 2);
69 repo_cfg_bool(r, "commitgraph.readchangedpaths", &read_changed_paths, 1);
70 repo_cfg_int(r, "commitgraph.changedpathsversion",
71 &r->settings.commit_graph_changed_paths_version,
72 read_changed_paths ? -1 : 0);
73 repo_cfg_bool(r, "gc.writecommitgraph", &r->settings.gc_write_commit_graph, 1);
74 repo_cfg_bool(r, "fetch.writecommitgraph", &r->settings.fetch_write_commit_graph, 0);
75
76 /* Boolean config or default, does not cascade (simple) */
77 repo_cfg_bool(r, "pack.usesparse", &r->settings.pack_use_sparse, 1);
78 repo_cfg_bool(r, "pack.usepathwalk", &r->settings.pack_use_path_walk, 0);
79 repo_cfg_bool(r, "core.multipackindex", &r->settings.core_multi_pack_index, 1);
80 repo_cfg_bool(r, "core.diffhunks", &r->settings.core_diff_hunks, 1);
81 repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 0);
82 repo_cfg_bool(r, "index.skiphash", &r->settings.index_skip_hash, r->settings.index_skip_hash);
83 repo_cfg_bool(r, "pack.readreverseindex", &r->settings.pack_read_reverse_index, 1);
84 repo_cfg_bool(r, "pack.usebitmapboundarytraversal",
85 &r->settings.pack_use_bitmap_boundary_traversal,
86 r->settings.pack_use_bitmap_boundary_traversal);
87 repo_cfg_bool(r, "core.usereplacerefs", &r->settings.read_replace_refs, 1);
88
89 /*
90 * The GIT_TEST_MULTI_PACK_INDEX variable is special in that
91 * either it *or* the config sets
92 * r->settings.core_multi_pack_index if true. We don't take
93 * the environment variable if it exists (even if false) over
94 * any config, as in most other cases.
95 */
96 if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0))
97 r->settings.core_multi_pack_index = 1;
98
99 /*
100 * Non-boolean config
101 */
102 if (!repo_config_get_int(r, "index.version", &value))
103 r->settings.index_version = value;
104 repo_cfg_int(r, "core.maxtreedepth",
105 &r->settings.max_allowed_tree_depth,
106 DEFAULT_MAX_ALLOWED_TREE_DEPTH);
107
108 if (!repo_config_get_string_tmp(r, "core.untrackedcache", &strval)) {
109 int v = git_parse_maybe_bool(strval);
110
111 /*
112 * If it's set to "keep", or some other non-boolean
113 * value then "v < 0". Then we do nothing and keep it
114 * at the default of UNTRACKED_CACHE_KEEP.
115 */
116 if (v >= 0)
117 r->settings.core_untracked_cache = v ?
118 UNTRACKED_CACHE_WRITE : UNTRACKED_CACHE_REMOVE;
119 }
120
121 if (!repo_config_get_string_tmp(r, "fetch.negotiationalgorithm", &strval)) {
122 int fetch_default = r->settings.fetch_negotiation_algorithm;
123 if (!strcasecmp(strval, "skipping"))
124 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
125 else if (!strcasecmp(strval, "noop"))
126 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_NOOP;
127 else if (!strcasecmp(strval, "consecutive"))
128 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE;
129 else if (!strcasecmp(strval, "default"))
130 r->settings.fetch_negotiation_algorithm = fetch_default;
131 else
132 die("unknown fetch negotiation algorithm '%s'", strval);
133 }
134
135 /*
136 * This setting guards all index reads to require a full index
137 * over a sparse index. After suitable guards are placed in the
138 * codebase around uses of the index, this setting will be
139 * removed.
140 */
141 r->settings.command_requires_full_index = 1;
142
143 if (!repo_config_get_ulong(r, "core.deltabasecachelimit", &ulongval))
144 r->settings.delta_base_cache_limit = ulongval;
145
146 if (!repo_config_get_ulong(r, "core.packedgitwindowsize", &ulongval)) {
147 int pgsz_x2 = getpagesize() * 2;
148
149 /* This value must be multiple of (pagesize * 2) */
150 ulongval /= pgsz_x2;
151 if (ulongval < 1)
152 ulongval = 1;
153 r->settings.packed_git_window_size = ulongval * pgsz_x2;
154 }
155
156 if (!repo_config_get_ulong(r, "core.packedgitlimit", &ulongval))
157 r->settings.packed_git_limit = ulongval;
158 }
159
160 void repo_settings_clear(struct repository *r)
161 {
162 struct repo_settings empty = REPO_SETTINGS_INIT;
163 FREE_AND_NULL(r->settings.fsmonitor);
164 FREE_AND_NULL(r->settings.hooks_path);
165 r->settings = empty;
166 }
167
168 unsigned long repo_settings_get_big_file_threshold(struct repository *repo)
169 {
170 if (!repo->settings.big_file_threshold)
171 repo_cfg_ulong(repo, "core.bigfilethreshold",
172 &repo->settings.big_file_threshold, 512 * 1024 * 1024);
173 return repo->settings.big_file_threshold;
174 }
175
176 void repo_settings_set_big_file_threshold(struct repository *repo, unsigned long value)
177 {
178 repo->settings.big_file_threshold = value;
179 }
180
181 int repo_settings_get_warn_ambiguous_refs(struct repository *repo)
182 {
183 prepare_repo_settings(repo);
184 if (repo->settings.warn_ambiguous_refs < 0)
185 repo_cfg_bool(repo, "core.warnambiguousrefs",
186 &repo->settings.warn_ambiguous_refs, 1);
187 return repo->settings.warn_ambiguous_refs;
188 }
189
190 const char *repo_settings_get_hooks_path(struct repository *repo)
191 {
192 if (!repo->settings.hooks_path)
193 repo_config_get_pathname(repo, "core.hookspath", &repo->settings.hooks_path);
194 return repo->settings.hooks_path;
195 }
196
197 int repo_settings_get_shared_repository(struct repository *repo)
198 {
199 if (!repo->settings.shared_repository_initialized) {
200 const char *var = "core.sharedrepository";
201 const char *value;
202 if (!repo_config_get_value(repo, var, &value))
203 repo->settings.shared_repository = git_config_perm(var, value);
204 else
205 repo->settings.shared_repository = PERM_UMASK;
206 repo->settings.shared_repository_initialized = 1;
207 }
208 return repo->settings.shared_repository;
209 }
210
211 void repo_settings_set_shared_repository(struct repository *repo, int value)
212 {
213 repo->settings.shared_repository = value;
214 repo->settings.shared_repository_initialized = 1;
215 }
216
217 void repo_settings_reset_shared_repository(struct repository *repo)
218 {
219 repo->settings.shared_repository_initialized = 0;
220 }