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