Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/environment.c # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / environment.c` 808 lines ยท 21502 bytes Raw Blame History 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 #ifndef NO_NSEC 575 if (!strcmp(var, "core.usenanosec")) { 576 cfg->use_nanosec = git_config_bool(var, value); 577 return 0; 578 } 579 #endif 580 581 /* Add other config variables here and to Documentation/config.adoc. */ 582 return platform_core_config(var, value, ctx, cb); 583 } 584 585 static int git_default_sparse_config(const char *var, const char *value) 586 { 587 struct repo_config_values *cfg = repo_config_values(the_repository); 588 589 if (!strcmp(var, "sparse.expectfilesoutsideofpatterns")) { 590 cfg->sparse_expect_files_outside_of_patterns = git_config_bool(var, value); 591 return 0; 592 } 593 594 /* Add other config variables here and to Documentation/config/sparse.adoc. */ 595 return 0; 596 } 597 598 static int git_default_i18n_config(const char *var, const char *value) 599 { 600 if (!strcmp(var, "i18n.commitencoding")) { 601 FREE_AND_NULL(git_commit_encoding); 602 return git_config_string(&git_commit_encoding, var, value); 603 } 604 605 if (!strcmp(var, "i18n.logoutputencoding")) { 606 FREE_AND_NULL(git_log_output_encoding); 607 return git_config_string(&git_log_output_encoding, var, value); 608 } 609 610 /* Add other config variables here and to Documentation/config.adoc. */ 611 return 0; 612 } 613 614 static int git_default_branch_config(const char *var, const char *value) 615 { 616 struct repo_config_values *cfg = repo_config_values(the_repository); 617 618 if (!strcmp(var, "branch.autosetupmerge")) { 619 if (value && !strcmp(value, "always")) { 620 cfg->branch_track = BRANCH_TRACK_ALWAYS; 621 return 0; 622 } else if (value && !strcmp(value, "inherit")) { 623 cfg->branch_track = BRANCH_TRACK_INHERIT; 624 return 0; 625 } else if (value && !strcmp(value, "simple")) { 626 cfg->branch_track = BRANCH_TRACK_SIMPLE; 627 return 0; 628 } 629 cfg->branch_track = git_config_bool(var, value); 630 return 0; 631 } 632 if (!strcmp(var, "branch.autosetuprebase")) { 633 if (!value) 634 return config_error_nonbool(var); 635 else if (!strcmp(value, "never")) 636 cfg->autorebase = AUTOREBASE_NEVER; 637 else if (!strcmp(value, "local")) 638 cfg->autorebase = AUTOREBASE_LOCAL; 639 else if (!strcmp(value, "remote")) 640 cfg->autorebase = AUTOREBASE_REMOTE; 641 else if (!strcmp(value, "always")) 642 cfg->autorebase = AUTOREBASE_ALWAYS; 643 else 644 return error(_("malformed value for %s"), var); 645 return 0; 646 } 647 648 /* Add other config variables here and to Documentation/config.adoc. */ 649 return 0; 650 } 651 652 static int git_default_push_config(const char *var, const char *value) 653 { 654 struct repo_config_values *cfg = repo_config_values(the_repository); 655 656 if (!strcmp(var, "push.default")) { 657 if (!value) 658 return config_error_nonbool(var); 659 else if (!strcmp(value, "nothing")) 660 cfg->push_default = PUSH_DEFAULT_NOTHING; 661 else if (!strcmp(value, "matching")) 662 cfg->push_default = PUSH_DEFAULT_MATCHING; 663 else if (!strcmp(value, "simple")) 664 cfg->push_default = PUSH_DEFAULT_SIMPLE; 665 else if (!strcmp(value, "upstream")) 666 cfg->push_default = PUSH_DEFAULT_UPSTREAM; 667 else if (!strcmp(value, "tracking")) /* deprecated */ 668 cfg->push_default = PUSH_DEFAULT_UPSTREAM; 669 else if (!strcmp(value, "current")) 670 cfg->push_default = PUSH_DEFAULT_CURRENT; 671 else { 672 error(_("malformed value for %s: %s"), var, value); 673 return error(_("must be one of nothing, matching, simple, " 674 "upstream or current")); 675 } 676 return 0; 677 } 678 679 /* Add other config variables here and to Documentation/config.adoc. */ 680 return 0; 681 } 682 683 static int git_default_attr_config(const char *var, const char *value) 684 { 685 if (!strcmp(var, "attr.tree")) { 686 FREE_AND_NULL(git_attr_tree); 687 return git_config_string(&git_attr_tree, var, value); 688 } 689 690 /* 691 * Add other attribute related config variables here and to 692 * Documentation/config/attr.adoc. 693 */ 694 return 0; 695 } 696 697 int git_default_config(const char *var, const char *value, 698 const struct config_context *ctx, void *cb) 699 { 700 struct repo_config_values *cfg = repo_config_values(the_repository); 701 702 if (starts_with(var, "core.")) 703 return git_default_core_config(var, value, ctx, cb); 704 705 if (starts_with(var, "user.") || 706 starts_with(var, "author.") || 707 starts_with(var, "committer.")) 708 return git_ident_config(var, value, ctx, cb); 709 710 if (starts_with(var, "i18n.")) 711 return git_default_i18n_config(var, value); 712 713 if (starts_with(var, "branch.")) 714 return git_default_branch_config(var, value); 715 716 if (starts_with(var, "push.")) 717 return git_default_push_config(var, value); 718 719 if (starts_with(var, "attr.")) 720 return git_default_attr_config(var, value); 721 722 if (starts_with(var, "advice.") || starts_with(var, "color.advice")) 723 return git_default_advice_config(var, value); 724 725 if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) { 726 pager_use_color = git_config_bool(var,value); 727 return 0; 728 } 729 730 if (!strcmp(var, "pack.packsizelimit")) { 731 pack_size_limit_cfg = git_config_ulong(var, value, ctx->kvi); 732 return 0; 733 } 734 735 if (!strcmp(var, "pack.compression")) { 736 int level = git_config_int(var, value, ctx->kvi); 737 if (level == -1) 738 level = Z_DEFAULT_COMPRESSION; 739 else if (level < 0 || level > Z_BEST_COMPRESSION) 740 die(_("bad pack compression level %d"), level); 741 cfg->pack_compression_level = level; 742 pack_compression_seen = 1; 743 return 0; 744 } 745 746 if (starts_with(var, "sparse.")) 747 return git_default_sparse_config(var, value); 748 749 if (!strcmp(var, "index.maxpathlen")) { 750 unsigned long maxlen = git_config_ulong(var, value, ctx->kvi); 751 752 if (maxlen > INT_MAX) 753 return error(_("value for '%s' exceeds maximum of %d"), 754 var, INT_MAX); 755 cfg->max_ce_namelen = maxlen; 756 return 0; 757 } 758 759 /* Add other config variables here and to Documentation/config.adoc. */ 760 return 0; 761 } 762 763 void repo_config_values_init(struct repo_config_values *cfg) 764 { 765 /* section "core" config values */ 766 cfg->attributes_file = NULL; 767 cfg->excludes_file = NULL; 768 cfg->editor_program = NULL; 769 cfg->pager_program = NULL; 770 cfg->askpass_program = NULL; 771 cfg->apply_default_whitespace = NULL; 772 cfg->apply_default_ignorewhitespace = NULL; 773 cfg->push_default = PUSH_DEFAULT_UNSPECIFIED; 774 cfg->autorebase = AUTOREBASE_NEVER; 775 cfg->object_creation_mode = OBJECT_CREATION_MODE; 776 cfg->apply_sparse_checkout = 0; 777 cfg->max_ce_namelen = INT_MAX / 2 - 1024; 778 cfg->trust_ctime = 1; 779 cfg->check_stat = 1; 780 cfg->zlib_compression_level = Z_BEST_SPEED; 781 cfg->pack_compression_level = Z_DEFAULT_COMPRESSION; 782 cfg->precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */ 783 cfg->core_sparse_checkout_cone = 0; 784 cfg->warn_on_object_refname_ambiguity = 1; 785 cfg->protect_hfs = PROTECT_HFS_DEFAULT; 786 cfg->protect_ntfs = PROTECT_NTFS_DEFAULT; 787 cfg->ignore_case = 0; 788 cfg->trust_executable_bit = 1; 789 cfg->has_symlinks = platform_has_symlinks(); 790 cfg->use_nanosec = 0; 791 792 /* section "sparse" config values */ 793 cfg->sparse_expect_files_outside_of_patterns = 0; 794 795 /* section "branch" config values */ 796 cfg->branch_track = BRANCH_TRACK_REMOTE; 797 } 798 799 void repo_config_values_clear(struct repo_config_values *cfg) 800 { 801 FREE_AND_NULL(cfg->attributes_file); 802 FREE_AND_NULL(cfg->excludes_file); 803 FREE_AND_NULL(cfg->editor_program); 804 FREE_AND_NULL(cfg->pager_program); 805 FREE_AND_NULL(cfg->askpass_program); 806 FREE_AND_NULL(cfg->apply_default_whitespace); 807 FREE_AND_NULL(cfg->apply_default_ignorewhitespace); 808 }