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