Line | Count | Source |
1 | | /* |
2 | | * We put all the git config variables in this same object |
3 | | * file, so that programs can link against the config parser |
4 | | * without having to link against all the rest of git. |
5 | | * |
6 | | * In particular, no need to bring in libz etc unless needed, |
7 | | * even if you might want to know where the git directory etc |
8 | | * are. |
9 | | */ |
10 | | |
11 | | #define USE_THE_REPOSITORY_VARIABLE |
12 | | |
13 | | #include "git-compat-util.h" |
14 | | #include "abspath.h" |
15 | | #include "advice.h" |
16 | | #include "attr.h" |
17 | | #include "branch.h" |
18 | | #include "color.h" |
19 | | #include "convert.h" |
20 | | #include "environment.h" |
21 | | #include "gettext.h" |
22 | | #include "git-zlib.h" |
23 | | #include "ident.h" |
24 | | #include "mailmap.h" |
25 | | #include "object-name.h" |
26 | | #include "repository.h" |
27 | | #include "config.h" |
28 | | #include "refs.h" |
29 | | #include "fmt-merge-msg.h" |
30 | | #include "commit.h" |
31 | | #include "strvec.h" |
32 | | #include "pager.h" |
33 | | #include "path.h" |
34 | | #include "quote.h" |
35 | | #include "chdir-notify.h" |
36 | | #include "setup.h" |
37 | | #include "ws.h" |
38 | | #include "write-or-die.h" |
39 | | |
40 | | static int pack_compression_seen; |
41 | | static int zlib_compression_seen; |
42 | | |
43 | | int trust_executable_bit = 1; |
44 | | int trust_ctime = 1; |
45 | | int check_stat = 1; |
46 | | int has_symlinks = 1; |
47 | | int minimum_abbrev = 4, default_abbrev = -1; |
48 | | int ignore_case; |
49 | | int assume_unchanged; |
50 | | int is_bare_repository_cfg = -1; /* unspecified */ |
51 | | int warn_on_object_refname_ambiguity = 1; |
52 | | char *git_commit_encoding; |
53 | | char *git_log_output_encoding; |
54 | | char *apply_default_whitespace; |
55 | | char *apply_default_ignorewhitespace; |
56 | | char *git_attributes_file; |
57 | | int zlib_compression_level = Z_BEST_SPEED; |
58 | | int pack_compression_level = Z_DEFAULT_COMPRESSION; |
59 | | int fsync_object_files = -1; |
60 | | int use_fsync = -1; |
61 | | enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT; |
62 | | enum fsync_component fsync_components = FSYNC_COMPONENTS_DEFAULT; |
63 | | char *editor_program; |
64 | | char *askpass_program; |
65 | | char *excludes_file; |
66 | | enum auto_crlf auto_crlf = AUTO_CRLF_FALSE; |
67 | | enum eol core_eol = EOL_UNSET; |
68 | | int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN; |
69 | | char *check_roundtrip_encoding; |
70 | | enum branch_track git_branch_track = BRANCH_TRACK_REMOTE; |
71 | | enum rebase_setup_type autorebase = AUTOREBASE_NEVER; |
72 | | enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED; |
73 | | #ifndef OBJECT_CREATION_MODE |
74 | | #define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS |
75 | | #endif |
76 | | enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE; |
77 | | int grafts_keep_true_parents; |
78 | | int core_apply_sparse_checkout; |
79 | | int core_sparse_checkout_cone; |
80 | | int sparse_expect_files_outside_of_patterns; |
81 | | int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */ |
82 | | unsigned long pack_size_limit_cfg; |
83 | | int max_allowed_tree_depth = |
84 | | #ifdef _MSC_VER |
85 | | /* |
86 | | * When traversing into too-deep trees, Visual C-compiled Git seems to |
87 | | * run into some internal stack overflow detection in the |
88 | | * `RtlpAllocateHeap()` function that is called from within |
89 | | * `git_inflate_init()`'s call tree. The following value seems to be |
90 | | * low enough to avoid that by letting Git exit with an error before |
91 | | * the stack overflow can occur. |
92 | | */ |
93 | | 512; |
94 | | #elif defined(GIT_WINDOWS_NATIVE) && defined(__clang__) && defined(__aarch64__) |
95 | | /* |
96 | | * Similar to Visual C, it seems that on Windows/ARM64 the clang-based |
97 | | * builds have a smaller stack space available. When running out of |
98 | | * that stack space, a `STATUS_STACK_OVERFLOW` is produced. When the |
99 | | * Git command was run from an MSYS2 Bash, this unfortunately results |
100 | | * in an exit code 127. Let's prevent that by lowering the maximal |
101 | | * tree depth; This value seems to be low enough. |
102 | | */ |
103 | | 1280; |
104 | | #else |
105 | | 2048; |
106 | | #endif |
107 | | |
108 | | #ifndef PROTECT_HFS_DEFAULT |
109 | | #define PROTECT_HFS_DEFAULT 0 |
110 | | #endif |
111 | | int protect_hfs = PROTECT_HFS_DEFAULT; |
112 | | |
113 | | #ifndef PROTECT_NTFS_DEFAULT |
114 | | #define PROTECT_NTFS_DEFAULT 1 |
115 | | #endif |
116 | | int protect_ntfs = PROTECT_NTFS_DEFAULT; |
117 | | |
118 | | /* |
119 | | * The character that begins a commented line in user-editable file |
120 | | * that is subject to stripspace. |
121 | | */ |
122 | | const char *comment_line_str = "#"; |
123 | | char *comment_line_str_to_free; |
124 | | #ifndef WITH_BREAKING_CHANGES |
125 | | int auto_comment_line_char; |
126 | | bool warn_on_auto_comment_char; |
127 | | #endif /* !WITH_BREAKING_CHANGES */ |
128 | | |
129 | | /* This is set by setup_git_directory_gently() and/or git_default_config() */ |
130 | | char *git_work_tree_cfg; |
131 | | |
132 | | /* |
133 | | * Repository-local GIT_* environment variables; see environment.h for details. |
134 | | */ |
135 | | const char * const local_repo_env[] = { |
136 | | ALTERNATE_DB_ENVIRONMENT, |
137 | | CONFIG_ENVIRONMENT, |
138 | | CONFIG_DATA_ENVIRONMENT, |
139 | | CONFIG_COUNT_ENVIRONMENT, |
140 | | DB_ENVIRONMENT, |
141 | | GIT_DIR_ENVIRONMENT, |
142 | | GIT_WORK_TREE_ENVIRONMENT, |
143 | | GIT_IMPLICIT_WORK_TREE_ENVIRONMENT, |
144 | | GRAFT_ENVIRONMENT, |
145 | | INDEX_ENVIRONMENT, |
146 | | NO_REPLACE_OBJECTS_ENVIRONMENT, |
147 | | GIT_REPLACE_REF_BASE_ENVIRONMENT, |
148 | | GIT_PREFIX_ENVIRONMENT, |
149 | | GIT_SHALLOW_FILE_ENVIRONMENT, |
150 | | GIT_COMMON_DIR_ENVIRONMENT, |
151 | | NULL |
152 | | }; |
153 | | |
154 | | const char *getenv_safe(struct strvec *argv, const char *name) |
155 | 0 | { |
156 | 0 | const char *value = getenv(name); |
157 | |
|
158 | 0 | if (!value) |
159 | 0 | return NULL; |
160 | | |
161 | 0 | strvec_push(argv, value); |
162 | 0 | return argv->v[argv->nr - 1]; |
163 | 0 | } |
164 | | |
165 | | int is_bare_repository(void) |
166 | 0 | { |
167 | | /* if core.bare is not 'false', let's see if there is a work tree */ |
168 | 0 | return is_bare_repository_cfg && !repo_get_work_tree(the_repository); |
169 | 0 | } |
170 | | |
171 | | int have_git_dir(void) |
172 | 0 | { |
173 | 0 | return startup_info->have_repository |
174 | 0 | || the_repository->gitdir; |
175 | 0 | } |
176 | | |
177 | | const char *get_git_namespace(void) |
178 | 0 | { |
179 | 0 | static const char *namespace; |
180 | 0 | struct strbuf buf = STRBUF_INIT; |
181 | 0 | const char *raw_namespace; |
182 | 0 | struct string_list components = STRING_LIST_INIT_DUP; |
183 | 0 | struct string_list_item *item; |
184 | |
|
185 | 0 | if (namespace) |
186 | 0 | return namespace; |
187 | | |
188 | 0 | raw_namespace = getenv(GIT_NAMESPACE_ENVIRONMENT); |
189 | 0 | if (!raw_namespace || !*raw_namespace) { |
190 | 0 | namespace = ""; |
191 | 0 | return namespace; |
192 | 0 | } |
193 | | |
194 | 0 | strbuf_addstr(&buf, raw_namespace); |
195 | |
|
196 | 0 | string_list_split(&components, buf.buf, "/", -1); |
197 | 0 | strbuf_reset(&buf); |
198 | |
|
199 | 0 | for_each_string_list_item(item, &components) { |
200 | 0 | if (item->string[0]) |
201 | 0 | strbuf_addf(&buf, "refs/namespaces/%s/", item->string); |
202 | 0 | } |
203 | 0 | string_list_clear(&components, 0); |
204 | |
|
205 | 0 | strbuf_trim_trailing_dir_sep(&buf); |
206 | 0 | if (check_refname_format(buf.buf, 0)) |
207 | 0 | die(_("bad git namespace path \"%s\""), raw_namespace); |
208 | 0 | strbuf_addch(&buf, '/'); |
209 | |
|
210 | 0 | namespace = strbuf_detach(&buf, NULL); |
211 | |
|
212 | 0 | return namespace; |
213 | 0 | } |
214 | | |
215 | | const char *strip_namespace(const char *namespaced_ref) |
216 | 0 | { |
217 | 0 | const char *out; |
218 | 0 | if (skip_prefix(namespaced_ref, get_git_namespace(), &out)) |
219 | 0 | return out; |
220 | 0 | return NULL; |
221 | 0 | } |
222 | | |
223 | | const char *get_log_output_encoding(void) |
224 | 0 | { |
225 | 0 | return git_log_output_encoding ? git_log_output_encoding |
226 | 0 | : get_commit_output_encoding(); |
227 | 0 | } |
228 | | |
229 | | const char *get_commit_output_encoding(void) |
230 | 0 | { |
231 | 0 | return git_commit_encoding ? git_commit_encoding : "UTF-8"; |
232 | 0 | } |
233 | | |
234 | | int use_optional_locks(void) |
235 | 0 | { |
236 | 0 | return git_env_bool(GIT_OPTIONAL_LOCKS_ENVIRONMENT, 1); |
237 | 0 | } |
238 | | |
239 | | int print_sha1_ellipsis(void) |
240 | 0 | { |
241 | | /* |
242 | | * Determine if the calling environment contains the variable |
243 | | * GIT_PRINT_SHA1_ELLIPSIS set to "yes". |
244 | | */ |
245 | 0 | static int cached_result = -1; /* unknown */ |
246 | |
|
247 | 0 | if (cached_result < 0) { |
248 | 0 | const char *v = getenv("GIT_PRINT_SHA1_ELLIPSIS"); |
249 | 0 | cached_result = (v && !strcasecmp(v, "yes")); |
250 | 0 | } |
251 | 0 | return cached_result; |
252 | 0 | } |
253 | | |
254 | | static const struct fsync_component_name { |
255 | | const char *name; |
256 | | enum fsync_component component_bits; |
257 | | } fsync_component_names[] = { |
258 | | { "loose-object", FSYNC_COMPONENT_LOOSE_OBJECT }, |
259 | | { "pack", FSYNC_COMPONENT_PACK }, |
260 | | { "pack-metadata", FSYNC_COMPONENT_PACK_METADATA }, |
261 | | { "commit-graph", FSYNC_COMPONENT_COMMIT_GRAPH }, |
262 | | { "index", FSYNC_COMPONENT_INDEX }, |
263 | | { "objects", FSYNC_COMPONENTS_OBJECTS }, |
264 | | { "reference", FSYNC_COMPONENT_REFERENCE }, |
265 | | { "derived-metadata", FSYNC_COMPONENTS_DERIVED_METADATA }, |
266 | | { "committed", FSYNC_COMPONENTS_COMMITTED }, |
267 | | { "added", FSYNC_COMPONENTS_ADDED }, |
268 | | { "all", FSYNC_COMPONENTS_ALL }, |
269 | | }; |
270 | | |
271 | | static enum fsync_component parse_fsync_components(const char *var, const char *string) |
272 | 0 | { |
273 | 0 | enum fsync_component current = FSYNC_COMPONENTS_PLATFORM_DEFAULT; |
274 | 0 | enum fsync_component positive = 0, negative = 0; |
275 | |
|
276 | 0 | while (string) { |
277 | 0 | size_t len; |
278 | 0 | const char *ep; |
279 | 0 | int negated = 0; |
280 | 0 | int found = 0; |
281 | |
|
282 | 0 | string = string + strspn(string, ", \t\n\r"); |
283 | 0 | ep = strchrnul(string, ','); |
284 | 0 | len = ep - string; |
285 | 0 | if (!strcmp(string, "none")) { |
286 | 0 | current = FSYNC_COMPONENT_NONE; |
287 | 0 | goto next_name; |
288 | 0 | } |
289 | | |
290 | 0 | if (*string == '-') { |
291 | 0 | negated = 1; |
292 | 0 | string++; |
293 | 0 | len--; |
294 | 0 | if (!len) |
295 | 0 | warning(_("invalid value for variable %s"), var); |
296 | 0 | } |
297 | |
|
298 | 0 | if (!len) |
299 | 0 | break; |
300 | | |
301 | 0 | for (size_t i = 0; i < ARRAY_SIZE(fsync_component_names); ++i) { |
302 | 0 | const struct fsync_component_name *n = &fsync_component_names[i]; |
303 | |
|
304 | 0 | if (strncmp(n->name, string, len)) |
305 | 0 | continue; |
306 | | |
307 | 0 | found = 1; |
308 | 0 | if (negated) |
309 | 0 | negative |= n->component_bits; |
310 | 0 | else |
311 | 0 | positive |= n->component_bits; |
312 | 0 | } |
313 | |
|
314 | 0 | if (!found) { |
315 | 0 | char *component = xstrndup(string, len); |
316 | 0 | warning(_("ignoring unknown core.fsync component '%s'"), component); |
317 | 0 | free(component); |
318 | 0 | } |
319 | |
|
320 | 0 | next_name: |
321 | 0 | string = ep; |
322 | 0 | } |
323 | | |
324 | 0 | return (current & ~negative) | positive; |
325 | 0 | } |
326 | | |
327 | | static int git_default_core_config(const char *var, const char *value, |
328 | | const struct config_context *ctx, void *cb) |
329 | 0 | { |
330 | | /* This needs a better name */ |
331 | 0 | if (!strcmp(var, "core.filemode")) { |
332 | 0 | trust_executable_bit = git_config_bool(var, value); |
333 | 0 | return 0; |
334 | 0 | } |
335 | 0 | if (!strcmp(var, "core.trustctime")) { |
336 | 0 | trust_ctime = git_config_bool(var, value); |
337 | 0 | return 0; |
338 | 0 | } |
339 | 0 | if (!strcmp(var, "core.checkstat")) { |
340 | 0 | if (!value) |
341 | 0 | return config_error_nonbool(var); |
342 | 0 | if (!strcasecmp(value, "default")) |
343 | 0 | check_stat = 1; |
344 | 0 | else if (!strcasecmp(value, "minimal")) |
345 | 0 | check_stat = 0; |
346 | 0 | else |
347 | 0 | return error(_("invalid value for '%s': '%s'"), |
348 | 0 | var, value); |
349 | 0 | } |
350 | | |
351 | 0 | if (!strcmp(var, "core.quotepath")) { |
352 | 0 | quote_path_fully = git_config_bool(var, value); |
353 | 0 | return 0; |
354 | 0 | } |
355 | | |
356 | 0 | if (!strcmp(var, "core.symlinks")) { |
357 | 0 | has_symlinks = git_config_bool(var, value); |
358 | 0 | return 0; |
359 | 0 | } |
360 | | |
361 | 0 | if (!strcmp(var, "core.ignorecase")) { |
362 | 0 | ignore_case = git_config_bool(var, value); |
363 | 0 | return 0; |
364 | 0 | } |
365 | | |
366 | 0 | if (!strcmp(var, "core.attributesfile")) { |
367 | 0 | FREE_AND_NULL(git_attributes_file); |
368 | 0 | return git_config_pathname(&git_attributes_file, var, value); |
369 | 0 | } |
370 | | |
371 | 0 | if (!strcmp(var, "core.bare")) { |
372 | 0 | is_bare_repository_cfg = git_config_bool(var, value); |
373 | 0 | return 0; |
374 | 0 | } |
375 | | |
376 | 0 | if (!strcmp(var, "core.ignorestat")) { |
377 | 0 | assume_unchanged = git_config_bool(var, value); |
378 | 0 | return 0; |
379 | 0 | } |
380 | | |
381 | 0 | if (!strcmp(var, "core.abbrev")) { |
382 | 0 | if (!value) |
383 | 0 | return config_error_nonbool(var); |
384 | 0 | if (!strcasecmp(value, "auto")) |
385 | 0 | default_abbrev = -1; |
386 | 0 | else if (!git_parse_maybe_bool_text(value)) |
387 | 0 | default_abbrev = GIT_MAX_HEXSZ; |
388 | 0 | else { |
389 | 0 | int abbrev = git_config_int(var, value, ctx->kvi); |
390 | 0 | if (abbrev < minimum_abbrev) |
391 | 0 | return error(_("abbrev length out of range: %d"), abbrev); |
392 | 0 | default_abbrev = abbrev; |
393 | 0 | } |
394 | 0 | return 0; |
395 | 0 | } |
396 | | |
397 | 0 | if (!strcmp(var, "core.disambiguate")) |
398 | 0 | return set_disambiguate_hint_config(var, value); |
399 | | |
400 | 0 | if (!strcmp(var, "core.loosecompression")) { |
401 | 0 | int level = git_config_int(var, value, ctx->kvi); |
402 | 0 | if (level == -1) |
403 | 0 | level = Z_DEFAULT_COMPRESSION; |
404 | 0 | else if (level < 0 || level > Z_BEST_COMPRESSION) |
405 | 0 | die(_("bad zlib compression level %d"), level); |
406 | 0 | zlib_compression_level = level; |
407 | 0 | zlib_compression_seen = 1; |
408 | 0 | return 0; |
409 | 0 | } |
410 | | |
411 | 0 | if (!strcmp(var, "core.compression")) { |
412 | 0 | int level = git_config_int(var, value, ctx->kvi); |
413 | 0 | if (level == -1) |
414 | 0 | level = Z_DEFAULT_COMPRESSION; |
415 | 0 | else if (level < 0 || level > Z_BEST_COMPRESSION) |
416 | 0 | die(_("bad zlib compression level %d"), level); |
417 | 0 | if (!zlib_compression_seen) |
418 | 0 | zlib_compression_level = level; |
419 | 0 | if (!pack_compression_seen) |
420 | 0 | pack_compression_level = level; |
421 | 0 | return 0; |
422 | 0 | } |
423 | | |
424 | 0 | if (!strcmp(var, "core.autocrlf")) { |
425 | 0 | if (value && !strcasecmp(value, "input")) { |
426 | 0 | auto_crlf = AUTO_CRLF_INPUT; |
427 | 0 | return 0; |
428 | 0 | } |
429 | 0 | auto_crlf = git_config_bool(var, value); |
430 | 0 | return 0; |
431 | 0 | } |
432 | | |
433 | 0 | if (!strcmp(var, "core.safecrlf")) { |
434 | 0 | int eol_rndtrp_die; |
435 | 0 | if (value && !strcasecmp(value, "warn")) { |
436 | 0 | global_conv_flags_eol = CONV_EOL_RNDTRP_WARN; |
437 | 0 | return 0; |
438 | 0 | } |
439 | 0 | eol_rndtrp_die = git_config_bool(var, value); |
440 | 0 | global_conv_flags_eol = eol_rndtrp_die ? |
441 | 0 | CONV_EOL_RNDTRP_DIE : 0; |
442 | 0 | return 0; |
443 | 0 | } |
444 | | |
445 | 0 | if (!strcmp(var, "core.eol")) { |
446 | 0 | if (value && !strcasecmp(value, "lf")) |
447 | 0 | core_eol = EOL_LF; |
448 | 0 | else if (value && !strcasecmp(value, "crlf")) |
449 | 0 | core_eol = EOL_CRLF; |
450 | 0 | else if (value && !strcasecmp(value, "native")) |
451 | 0 | core_eol = EOL_NATIVE; |
452 | 0 | else |
453 | 0 | core_eol = EOL_UNSET; |
454 | 0 | return 0; |
455 | 0 | } |
456 | | |
457 | 0 | if (!strcmp(var, "core.checkroundtripencoding")) { |
458 | 0 | FREE_AND_NULL(check_roundtrip_encoding); |
459 | 0 | return git_config_string(&check_roundtrip_encoding, var, value); |
460 | 0 | } |
461 | | |
462 | 0 | if (!strcmp(var, "core.editor")) { |
463 | 0 | FREE_AND_NULL(editor_program); |
464 | 0 | return git_config_string(&editor_program, var, value); |
465 | 0 | } |
466 | | |
467 | 0 | if (!strcmp(var, "core.commentchar") || |
468 | 0 | !strcmp(var, "core.commentstring")) { |
469 | 0 | if (!value) { |
470 | 0 | return config_error_nonbool(var); |
471 | 0 | #ifndef WITH_BREAKING_CHANGES |
472 | 0 | } else if (!strcasecmp(value, "auto")) { |
473 | 0 | auto_comment_line_char = 1; |
474 | 0 | FREE_AND_NULL(comment_line_str_to_free); |
475 | 0 | comment_line_str = "#"; |
476 | 0 | #endif /* !WITH_BREAKING_CHANGES */ |
477 | 0 | } else if (value[0]) { |
478 | 0 | if (strchr(value, '\n')) |
479 | 0 | return error(_("%s cannot contain newline"), var); |
480 | 0 | comment_line_str = value; |
481 | 0 | FREE_AND_NULL(comment_line_str_to_free); |
482 | 0 | #ifndef WITH_BREAKING_CHANGES |
483 | 0 | auto_comment_line_char = 0; |
484 | 0 | #endif /* !WITH_BREAKING_CHANGES */ |
485 | 0 | } else |
486 | 0 | return error(_("%s must have at least one character"), var); |
487 | 0 | return 0; |
488 | 0 | } |
489 | | |
490 | 0 | if (!strcmp(var, "core.askpass")) { |
491 | 0 | FREE_AND_NULL(askpass_program); |
492 | 0 | return git_config_string(&askpass_program, var, value); |
493 | 0 | } |
494 | | |
495 | 0 | if (!strcmp(var, "core.excludesfile")) { |
496 | 0 | FREE_AND_NULL(excludes_file); |
497 | 0 | return git_config_pathname(&excludes_file, var, value); |
498 | 0 | } |
499 | | |
500 | 0 | if (!strcmp(var, "core.whitespace")) { |
501 | 0 | if (!value) |
502 | 0 | return config_error_nonbool(var); |
503 | 0 | whitespace_rule_cfg = parse_whitespace_rule(value); |
504 | 0 | return 0; |
505 | 0 | } |
506 | | |
507 | 0 | if (!strcmp(var, "core.fsync")) { |
508 | 0 | if (!value) |
509 | 0 | return config_error_nonbool(var); |
510 | 0 | fsync_components = parse_fsync_components(var, value); |
511 | 0 | return 0; |
512 | 0 | } |
513 | | |
514 | 0 | if (!strcmp(var, "core.fsyncmethod")) { |
515 | 0 | if (!value) |
516 | 0 | return config_error_nonbool(var); |
517 | 0 | if (!strcmp(value, "fsync")) |
518 | 0 | fsync_method = FSYNC_METHOD_FSYNC; |
519 | 0 | else if (!strcmp(value, "writeout-only")) |
520 | 0 | fsync_method = FSYNC_METHOD_WRITEOUT_ONLY; |
521 | 0 | else if (!strcmp(value, "batch")) |
522 | 0 | fsync_method = FSYNC_METHOD_BATCH; |
523 | 0 | else |
524 | 0 | warning(_("ignoring unknown core.fsyncMethod value '%s'"), value); |
525 | |
|
526 | 0 | } |
527 | | |
528 | 0 | if (!strcmp(var, "core.fsyncobjectfiles")) { |
529 | 0 | if (fsync_object_files < 0) |
530 | 0 | warning(_("core.fsyncObjectFiles is deprecated; use core.fsync instead")); |
531 | 0 | fsync_object_files = git_config_bool(var, value); |
532 | 0 | return 0; |
533 | 0 | } |
534 | | |
535 | 0 | if (!strcmp(var, "core.createobject")) { |
536 | 0 | if (!value) |
537 | 0 | return config_error_nonbool(var); |
538 | 0 | if (!strcmp(value, "rename")) |
539 | 0 | object_creation_mode = OBJECT_CREATION_USES_RENAMES; |
540 | 0 | else if (!strcmp(value, "link")) |
541 | 0 | object_creation_mode = OBJECT_CREATION_USES_HARDLINKS; |
542 | 0 | else |
543 | 0 | die(_("invalid mode for object creation: %s"), value); |
544 | 0 | return 0; |
545 | 0 | } |
546 | | |
547 | 0 | if (!strcmp(var, "core.sparsecheckout")) { |
548 | 0 | core_apply_sparse_checkout = git_config_bool(var, value); |
549 | 0 | return 0; |
550 | 0 | } |
551 | | |
552 | 0 | if (!strcmp(var, "core.sparsecheckoutcone")) { |
553 | 0 | core_sparse_checkout_cone = git_config_bool(var, value); |
554 | 0 | return 0; |
555 | 0 | } |
556 | | |
557 | 0 | if (!strcmp(var, "core.precomposeunicode")) { |
558 | 0 | precomposed_unicode = git_config_bool(var, value); |
559 | 0 | return 0; |
560 | 0 | } |
561 | | |
562 | 0 | if (!strcmp(var, "core.protecthfs")) { |
563 | 0 | protect_hfs = git_config_bool(var, value); |
564 | 0 | return 0; |
565 | 0 | } |
566 | | |
567 | 0 | if (!strcmp(var, "core.protectntfs")) { |
568 | 0 | protect_ntfs = git_config_bool(var, value); |
569 | 0 | return 0; |
570 | 0 | } |
571 | | |
572 | 0 | if (!strcmp(var, "core.maxtreedepth")) { |
573 | 0 | max_allowed_tree_depth = git_config_int(var, value, ctx->kvi); |
574 | 0 | return 0; |
575 | 0 | } |
576 | | |
577 | | /* Add other config variables here and to Documentation/config.adoc. */ |
578 | 0 | return platform_core_config(var, value, ctx, cb); |
579 | 0 | } |
580 | | |
581 | | static int git_default_sparse_config(const char *var, const char *value) |
582 | 0 | { |
583 | 0 | if (!strcmp(var, "sparse.expectfilesoutsideofpatterns")) { |
584 | 0 | sparse_expect_files_outside_of_patterns = git_config_bool(var, value); |
585 | 0 | return 0; |
586 | 0 | } |
587 | | |
588 | | /* Add other config variables here and to Documentation/config/sparse.adoc. */ |
589 | 0 | return 0; |
590 | 0 | } |
591 | | |
592 | | static int git_default_i18n_config(const char *var, const char *value) |
593 | 0 | { |
594 | 0 | if (!strcmp(var, "i18n.commitencoding")) { |
595 | 0 | FREE_AND_NULL(git_commit_encoding); |
596 | 0 | return git_config_string(&git_commit_encoding, var, value); |
597 | 0 | } |
598 | | |
599 | 0 | if (!strcmp(var, "i18n.logoutputencoding")) { |
600 | 0 | FREE_AND_NULL(git_log_output_encoding); |
601 | 0 | return git_config_string(&git_log_output_encoding, var, value); |
602 | 0 | } |
603 | | |
604 | | /* Add other config variables here and to Documentation/config.adoc. */ |
605 | 0 | return 0; |
606 | 0 | } |
607 | | |
608 | | static int git_default_branch_config(const char *var, const char *value) |
609 | 0 | { |
610 | 0 | if (!strcmp(var, "branch.autosetupmerge")) { |
611 | 0 | if (value && !strcmp(value, "always")) { |
612 | 0 | git_branch_track = BRANCH_TRACK_ALWAYS; |
613 | 0 | return 0; |
614 | 0 | } else if (value && !strcmp(value, "inherit")) { |
615 | 0 | git_branch_track = BRANCH_TRACK_INHERIT; |
616 | 0 | return 0; |
617 | 0 | } else if (value && !strcmp(value, "simple")) { |
618 | 0 | git_branch_track = BRANCH_TRACK_SIMPLE; |
619 | 0 | return 0; |
620 | 0 | } |
621 | 0 | git_branch_track = git_config_bool(var, value); |
622 | 0 | return 0; |
623 | 0 | } |
624 | 0 | if (!strcmp(var, "branch.autosetuprebase")) { |
625 | 0 | if (!value) |
626 | 0 | return config_error_nonbool(var); |
627 | 0 | else if (!strcmp(value, "never")) |
628 | 0 | autorebase = AUTOREBASE_NEVER; |
629 | 0 | else if (!strcmp(value, "local")) |
630 | 0 | autorebase = AUTOREBASE_LOCAL; |
631 | 0 | else if (!strcmp(value, "remote")) |
632 | 0 | autorebase = AUTOREBASE_REMOTE; |
633 | 0 | else if (!strcmp(value, "always")) |
634 | 0 | autorebase = AUTOREBASE_ALWAYS; |
635 | 0 | else |
636 | 0 | return error(_("malformed value for %s"), var); |
637 | 0 | return 0; |
638 | 0 | } |
639 | | |
640 | | /* Add other config variables here and to Documentation/config.adoc. */ |
641 | 0 | return 0; |
642 | 0 | } |
643 | | |
644 | | static int git_default_push_config(const char *var, const char *value) |
645 | 0 | { |
646 | 0 | if (!strcmp(var, "push.default")) { |
647 | 0 | if (!value) |
648 | 0 | return config_error_nonbool(var); |
649 | 0 | else if (!strcmp(value, "nothing")) |
650 | 0 | push_default = PUSH_DEFAULT_NOTHING; |
651 | 0 | else if (!strcmp(value, "matching")) |
652 | 0 | push_default = PUSH_DEFAULT_MATCHING; |
653 | 0 | else if (!strcmp(value, "simple")) |
654 | 0 | push_default = PUSH_DEFAULT_SIMPLE; |
655 | 0 | else if (!strcmp(value, "upstream")) |
656 | 0 | push_default = PUSH_DEFAULT_UPSTREAM; |
657 | 0 | else if (!strcmp(value, "tracking")) /* deprecated */ |
658 | 0 | push_default = PUSH_DEFAULT_UPSTREAM; |
659 | 0 | else if (!strcmp(value, "current")) |
660 | 0 | push_default = PUSH_DEFAULT_CURRENT; |
661 | 0 | else { |
662 | 0 | error(_("malformed value for %s: %s"), var, value); |
663 | 0 | return error(_("must be one of nothing, matching, simple, " |
664 | 0 | "upstream or current")); |
665 | 0 | } |
666 | 0 | return 0; |
667 | 0 | } |
668 | | |
669 | | /* Add other config variables here and to Documentation/config.adoc. */ |
670 | 0 | return 0; |
671 | 0 | } |
672 | | |
673 | | static int git_default_mailmap_config(const char *var, const char *value) |
674 | 0 | { |
675 | 0 | if (!strcmp(var, "mailmap.file")) { |
676 | 0 | FREE_AND_NULL(git_mailmap_file); |
677 | 0 | return git_config_pathname(&git_mailmap_file, var, value); |
678 | 0 | } |
679 | | |
680 | 0 | if (!strcmp(var, "mailmap.blob")) { |
681 | 0 | FREE_AND_NULL(git_mailmap_blob); |
682 | 0 | return git_config_string(&git_mailmap_blob, var, value); |
683 | 0 | } |
684 | | |
685 | | /* Add other config variables here and to Documentation/config.adoc. */ |
686 | 0 | return 0; |
687 | 0 | } |
688 | | |
689 | | static int git_default_attr_config(const char *var, const char *value) |
690 | 0 | { |
691 | 0 | if (!strcmp(var, "attr.tree")) { |
692 | 0 | FREE_AND_NULL(git_attr_tree); |
693 | 0 | return git_config_string(&git_attr_tree, var, value); |
694 | 0 | } |
695 | | |
696 | | /* |
697 | | * Add other attribute related config variables here and to |
698 | | * Documentation/config/attr.adoc. |
699 | | */ |
700 | 0 | return 0; |
701 | 0 | } |
702 | | |
703 | | int git_default_config(const char *var, const char *value, |
704 | | const struct config_context *ctx, void *cb) |
705 | 0 | { |
706 | 0 | if (starts_with(var, "core.")) |
707 | 0 | return git_default_core_config(var, value, ctx, cb); |
708 | | |
709 | 0 | if (starts_with(var, "user.") || |
710 | 0 | starts_with(var, "author.") || |
711 | 0 | starts_with(var, "committer.")) |
712 | 0 | return git_ident_config(var, value, ctx, cb); |
713 | | |
714 | 0 | if (starts_with(var, "i18n.")) |
715 | 0 | return git_default_i18n_config(var, value); |
716 | | |
717 | 0 | if (starts_with(var, "branch.")) |
718 | 0 | return git_default_branch_config(var, value); |
719 | | |
720 | 0 | if (starts_with(var, "push.")) |
721 | 0 | return git_default_push_config(var, value); |
722 | | |
723 | 0 | if (starts_with(var, "mailmap.")) |
724 | 0 | return git_default_mailmap_config(var, value); |
725 | | |
726 | 0 | if (starts_with(var, "attr.")) |
727 | 0 | return git_default_attr_config(var, value); |
728 | | |
729 | 0 | if (starts_with(var, "advice.") || starts_with(var, "color.advice")) |
730 | 0 | return git_default_advice_config(var, value); |
731 | | |
732 | 0 | if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) { |
733 | 0 | pager_use_color = git_config_bool(var,value); |
734 | 0 | return 0; |
735 | 0 | } |
736 | | |
737 | 0 | if (!strcmp(var, "pack.packsizelimit")) { |
738 | 0 | pack_size_limit_cfg = git_config_ulong(var, value, ctx->kvi); |
739 | 0 | return 0; |
740 | 0 | } |
741 | | |
742 | 0 | if (!strcmp(var, "pack.compression")) { |
743 | 0 | int level = git_config_int(var, value, ctx->kvi); |
744 | 0 | if (level == -1) |
745 | 0 | level = Z_DEFAULT_COMPRESSION; |
746 | 0 | else if (level < 0 || level > Z_BEST_COMPRESSION) |
747 | 0 | die(_("bad pack compression level %d"), level); |
748 | 0 | pack_compression_level = level; |
749 | 0 | pack_compression_seen = 1; |
750 | 0 | return 0; |
751 | 0 | } |
752 | | |
753 | 0 | if (starts_with(var, "sparse.")) |
754 | 0 | return git_default_sparse_config(var, value); |
755 | | |
756 | | /* Add other config variables here and to Documentation/config.adoc. */ |
757 | 0 | return 0; |
758 | 0 | } |