| 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 | { "diff-hunks", FSYNC_COMPONENT_DIFF_HUNKS }, |
| 257 | { "index", FSYNC_COMPONENT_INDEX }, |
| 258 | { "objects", FSYNC_COMPONENTS_OBJECTS }, |
| 259 | { "reference", FSYNC_COMPONENT_REFERENCE }, |
| 260 | { "derived-metadata", FSYNC_COMPONENTS_DERIVED_METADATA }, |
| 261 | { "committed", FSYNC_COMPONENTS_COMMITTED }, |
| 262 | { "added", FSYNC_COMPONENTS_ADDED }, |
| 263 | { "all", FSYNC_COMPONENTS_ALL }, |
| 264 | }; |
| 265 | |
| 266 | static enum fsync_component parse_fsync_components(const char *var, const char *string) |
| 267 | { |
| 268 | enum fsync_component current = FSYNC_COMPONENTS_PLATFORM_DEFAULT; |
| 269 | enum fsync_component positive = 0, negative = 0; |
| 270 | |
| 271 | while (string) { |
| 272 | size_t len; |
| 273 | const char *ep; |
| 274 | int negated = 0; |
| 275 | int found = 0; |
| 276 | |
| 277 | string = string + strspn(string, ", \t\n\r"); |
| 278 | ep = strchrnul(string, ','); |
| 279 | len = ep - string; |
| 280 | if (!strcmp(string, "none")) { |
| 281 | current = FSYNC_COMPONENT_NONE; |
| 282 | goto next_name; |
| 283 | } |
| 284 | |
| 285 | if (*string == '-') { |
| 286 | negated = 1; |
| 287 | string++; |
| 288 | len--; |
| 289 | if (!len) |
| 290 | warning(_("invalid value for variable %s"), var); |
| 291 | } |
| 292 | |
| 293 | if (!len) |
| 294 | break; |
| 295 | |
| 296 | for (size_t i = 0; i < ARRAY_SIZE(fsync_component_names); ++i) { |
| 297 | const struct fsync_component_name *n = &fsync_component_names[i]; |
| 298 | |
| 299 | if (strncmp(n->name, string, len)) |
| 300 | continue; |
| 301 | |
| 302 | found = 1; |
| 303 | if (negated) |
| 304 | negative |= n->component_bits; |
| 305 | else |
| 306 | positive |= n->component_bits; |
| 307 | } |
| 308 | |
| 309 | if (!found) { |
| 310 | char *component = xstrndup(string, len); |
| 311 | warning(_("ignoring unknown core.fsync component '%s'"), component); |
| 312 | free(component); |
| 313 | } |
| 314 | |
| 315 | next_name: |
| 316 | string = ep; |
| 317 | } |
| 318 | |
| 319 | return (current & ~negative) | positive; |
| 320 | } |
| 321 | |
| 322 | int git_default_core_config(const char *var, const char *value, |
| 323 | const struct config_context *ctx, void *cb) |
| 324 | { |
| 325 | struct repo_config_values *cfg = repo_config_values(the_repository); |
| 326 | |
| 327 | /* This needs a better name */ |
| 328 | if (!strcmp(var, "core.filemode")) { |
| 329 | cfg->trust_executable_bit = git_config_bool(var, value); |
| 330 | return 0; |
| 331 | } |
| 332 | if (!strcmp(var, "core.trustctime")) { |
| 333 | cfg->trust_ctime = git_config_bool(var, value); |
| 334 | return 0; |
| 335 | } |
| 336 | if (!strcmp(var, "core.checkstat")) { |
| 337 | if (!value) |
| 338 | return config_error_nonbool(var); |
| 339 | if (!strcasecmp(value, "default")) |
| 340 | cfg->check_stat = 1; |
| 341 | else if (!strcasecmp(value, "minimal")) |
| 342 | cfg->check_stat = 0; |
| 343 | else |
| 344 | return error(_("invalid value for '%s': '%s'"), |
| 345 | var, value); |
| 346 | } |
| 347 | |
| 348 | if (!strcmp(var, "core.quotepath")) { |
| 349 | quote_path_fully = git_config_bool(var, value); |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | if (!strcmp(var, "core.symlinks")) { |
| 354 | struct repo_config_values *cfg = repo_config_values(the_repository); |
| 355 | cfg->has_symlinks = git_config_bool(var, value); |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | if (!strcmp(var, "core.ignorecase")) { |
| 360 | cfg->ignore_case = git_config_bool(var, value); |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | if (!strcmp(var, "core.attributesfile")) { |
| 365 | FREE_AND_NULL(cfg->attributes_file); |
| 366 | return git_config_pathname(&cfg->attributes_file, var, value); |
| 367 | } |
| 368 | |
| 369 | if (!strcmp(var, "core.bare")) { |
| 370 | the_repository->bare_cfg = git_config_bool(var, value); |
| 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | if (!strcmp(var, "core.ignorestat")) { |
| 375 | assume_unchanged = git_config_bool(var, value); |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | if (!strcmp(var, "core.abbrev")) { |
| 380 | if (!value) |
| 381 | return config_error_nonbool(var); |
| 382 | if (!strcasecmp(value, "auto")) |
| 383 | default_abbrev = -1; |
| 384 | else if (!git_parse_maybe_bool_text(value)) |
| 385 | default_abbrev = GIT_MAX_HEXSZ; |
| 386 | else { |
| 387 | int abbrev = git_config_int(var, value, ctx->kvi); |
| 388 | if (abbrev < minimum_abbrev) |
| 389 | return error(_("abbrev length out of range: %d"), abbrev); |
| 390 | default_abbrev = abbrev; |
| 391 | } |
| 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | if (!strcmp(var, "core.disambiguate")) |
| 396 | return set_disambiguate_hint_config(var, value); |
| 397 | |
| 398 | if (!strcmp(var, "core.loosecompression")) { |
| 399 | int level = git_config_int(var, value, ctx->kvi); |
| 400 | if (level == -1) |
| 401 | level = Z_DEFAULT_COMPRESSION; |
| 402 | else if (level < 0 || level > Z_BEST_COMPRESSION) |
| 403 | die(_("bad zlib compression level %d"), level); |
| 404 | cfg->zlib_compression_level = level; |
| 405 | zlib_compression_seen = 1; |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | if (!strcmp(var, "core.compression")) { |
| 410 | int level = git_config_int(var, value, ctx->kvi); |
| 411 | if (level == -1) |
| 412 | level = Z_DEFAULT_COMPRESSION; |
| 413 | else if (level < 0 || level > Z_BEST_COMPRESSION) |
| 414 | die(_("bad zlib compression level %d"), level); |
| 415 | if (!zlib_compression_seen) |
| 416 | cfg->zlib_compression_level = level; |
| 417 | if (!pack_compression_seen) |
| 418 | cfg->pack_compression_level = level; |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | if (!strcmp(var, "core.autocrlf")) { |
| 423 | if (value && !strcasecmp(value, "input")) { |
| 424 | auto_crlf = AUTO_CRLF_INPUT; |
| 425 | return 0; |
| 426 | } |
| 427 | auto_crlf = git_config_bool(var, value); |
| 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | if (!strcmp(var, "core.safecrlf")) { |
| 432 | int eol_rndtrp_die; |
| 433 | if (value && !strcasecmp(value, "warn")) { |
| 434 | global_conv_flags_eol = CONV_EOL_RNDTRP_WARN; |
| 435 | return 0; |
| 436 | } |
| 437 | eol_rndtrp_die = git_config_bool(var, value); |
| 438 | global_conv_flags_eol = eol_rndtrp_die ? |
| 439 | CONV_EOL_RNDTRP_DIE : 0; |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | if (!strcmp(var, "core.eol")) { |
| 444 | if (value && !strcasecmp(value, "lf")) |
| 445 | core_eol = EOL_LF; |
| 446 | else if (value && !strcasecmp(value, "crlf")) |
| 447 | core_eol = EOL_CRLF; |
| 448 | else if (value && !strcasecmp(value, "native")) |
| 449 | core_eol = EOL_NATIVE; |
| 450 | else |
| 451 | core_eol = EOL_UNSET; |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | if (!strcmp(var, "core.checkroundtripencoding")) { |
| 456 | FREE_AND_NULL(check_roundtrip_encoding); |
| 457 | return git_config_string(&check_roundtrip_encoding, var, value); |
| 458 | } |
| 459 | |
| 460 | if (!strcmp(var, "core.editor")) { |
| 461 | FREE_AND_NULL(cfg->editor_program); |
| 462 | return git_config_string(&cfg->editor_program, var, value); |
| 463 | } |
| 464 | |
| 465 | if (!strcmp(var, "core.commentchar") || |
| 466 | !strcmp(var, "core.commentstring")) { |
| 467 | if (!value) { |
| 468 | return config_error_nonbool(var); |
| 469 | #ifndef WITH_BREAKING_CHANGES |
| 470 | } else if (!strcasecmp(value, "auto")) { |
| 471 | auto_comment_line_char = 1; |
| 472 | FREE_AND_NULL(comment_line_str_to_free); |
| 473 | comment_line_str = "#"; |
| 474 | #endif /* !WITH_BREAKING_CHANGES */ |
| 475 | } else if (value[0]) { |
| 476 | if (strchr(value, '\n')) |
| 477 | return error(_("%s cannot contain newline"), var); |
| 478 | comment_line_str = value; |
| 479 | FREE_AND_NULL(comment_line_str_to_free); |
| 480 | #ifndef WITH_BREAKING_CHANGES |
| 481 | auto_comment_line_char = 0; |
| 482 | #endif /* !WITH_BREAKING_CHANGES */ |
| 483 | } else |
| 484 | return error(_("%s must have at least one character"), var); |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | if (!strcmp(var, "core.askpass")) { |
| 489 | FREE_AND_NULL(cfg->askpass_program); |
| 490 | return git_config_string(&cfg->askpass_program, var, value); |
| 491 | } |
| 492 | |
| 493 | if (!strcmp(var, "core.excludesfile")) { |
| 494 | FREE_AND_NULL(cfg->excludes_file); |
| 495 | return git_config_pathname(&cfg->excludes_file, var, value); |
| 496 | } |
| 497 | |
| 498 | if (!strcmp(var, "core.whitespace")) { |
| 499 | if (!value) |
| 500 | return config_error_nonbool(var); |
| 501 | whitespace_rule_cfg = parse_whitespace_rule(value); |
| 502 | return 0; |
| 503 | } |
| 504 | |
| 505 | if (!strcmp(var, "core.fsync")) { |
| 506 | if (!value) |
| 507 | return config_error_nonbool(var); |
| 508 | fsync_components = parse_fsync_components(var, value); |
| 509 | return 0; |
| 510 | } |
| 511 | |
| 512 | if (!strcmp(var, "core.fsyncmethod")) { |
| 513 | if (!value) |
| 514 | return config_error_nonbool(var); |
| 515 | if (!strcmp(value, "fsync")) |
| 516 | fsync_method = FSYNC_METHOD_FSYNC; |
| 517 | else if (!strcmp(value, "writeout-only")) |
| 518 | fsync_method = FSYNC_METHOD_WRITEOUT_ONLY; |
| 519 | else if (!strcmp(value, "batch")) |
| 520 | fsync_method = FSYNC_METHOD_BATCH; |
| 521 | else |
| 522 | warning(_("ignoring unknown core.fsyncMethod value '%s'"), value); |
| 523 | |
| 524 | } |
| 525 | |
| 526 | if (!strcmp(var, "core.fsyncobjectfiles")) { |
| 527 | if (fsync_object_files < 0) |
| 528 | warning(_("core.fsyncObjectFiles is deprecated; use core.fsync instead")); |
| 529 | fsync_object_files = git_config_bool(var, value); |
| 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | if (!strcmp(var, "core.lockfilepid")) { |
| 534 | lockfile_pid_enabled = git_config_bool(var, value); |
| 535 | return 0; |
| 536 | } |
| 537 | |
| 538 | if (!strcmp(var, "core.createobject")) { |
| 539 | if (!value) |
| 540 | return config_error_nonbool(var); |
| 541 | if (!strcmp(value, "rename")) |
| 542 | cfg->object_creation_mode = OBJECT_CREATION_USES_RENAMES; |
| 543 | else if (!strcmp(value, "link")) |
| 544 | cfg->object_creation_mode = OBJECT_CREATION_USES_HARDLINKS; |
| 545 | else |
| 546 | die(_("invalid mode for object creation: %s"), value); |
| 547 | return 0; |
| 548 | } |
| 549 | |
| 550 | if (!strcmp(var, "core.sparsecheckout")) { |
| 551 | cfg->apply_sparse_checkout = git_config_bool(var, value); |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | if (!strcmp(var, "core.sparsecheckoutcone")) { |
| 556 | cfg->core_sparse_checkout_cone = git_config_bool(var, value); |
| 557 | return 0; |
| 558 | } |
| 559 | |
| 560 | if (!strcmp(var, "core.precomposeunicode")) { |
| 561 | cfg->precomposed_unicode = git_config_bool(var, value); |
| 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | if (!strcmp(var, "core.protecthfs")) { |
| 566 | cfg->protect_hfs = git_config_bool(var, value); |
| 567 | return 0; |
| 568 | } |
| 569 | |
| 570 | if (!strcmp(var, "core.protectntfs")) { |
| 571 | cfg->protect_ntfs = git_config_bool(var, value); |
| 572 | return 0; |
| 573 | } |
| 574 | |
| 575 | /* Add other config variables here and to Documentation/config.adoc. */ |
| 576 | return platform_core_config(var, value, ctx, cb); |
| 577 | } |
| 578 | |
| 579 | static int git_default_sparse_config(const char *var, const char *value) |
| 580 | { |
| 581 | struct repo_config_values *cfg = repo_config_values(the_repository); |
| 582 | |
| 583 | if (!strcmp(var, "sparse.expectfilesoutsideofpatterns")) { |
| 584 | cfg->sparse_expect_files_outside_of_patterns = git_config_bool(var, value); |
| 585 | return 0; |
| 586 | } |
| 587 | |
| 588 | /* Add other config variables here and to Documentation/config/sparse.adoc. */ |
| 589 | return 0; |
| 590 | } |
| 591 | |
| 592 | static int git_default_i18n_config(const char *var, const char *value) |
| 593 | { |
| 594 | if (!strcmp(var, "i18n.commitencoding")) { |
| 595 | FREE_AND_NULL(git_commit_encoding); |
| 596 | return git_config_string(&git_commit_encoding, var, value); |
| 597 | } |
| 598 | |
| 599 | if (!strcmp(var, "i18n.logoutputencoding")) { |
| 600 | FREE_AND_NULL(git_log_output_encoding); |
| 601 | return git_config_string(&git_log_output_encoding, var, value); |
| 602 | } |
| 603 | |
| 604 | /* Add other config variables here and to Documentation/config.adoc. */ |
| 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | static int git_default_branch_config(const char *var, const char *value) |
| 609 | { |
| 610 | struct repo_config_values *cfg = repo_config_values(the_repository); |
| 611 | |
| 612 | if (!strcmp(var, "branch.autosetupmerge")) { |
| 613 | if (value && !strcmp(value, "always")) { |
| 614 | cfg->branch_track = BRANCH_TRACK_ALWAYS; |
| 615 | return 0; |
| 616 | } else if (value && !strcmp(value, "inherit")) { |
| 617 | cfg->branch_track = BRANCH_TRACK_INHERIT; |
| 618 | return 0; |
| 619 | } else if (value && !strcmp(value, "simple")) { |
| 620 | cfg->branch_track = BRANCH_TRACK_SIMPLE; |
| 621 | return 0; |
| 622 | } |
| 623 | cfg->branch_track = git_config_bool(var, value); |
| 624 | return 0; |
| 625 | } |
| 626 | if (!strcmp(var, "branch.autosetuprebase")) { |
| 627 | if (!value) |
| 628 | return config_error_nonbool(var); |
| 629 | else if (!strcmp(value, "never")) |
| 630 | cfg->autorebase = AUTOREBASE_NEVER; |
| 631 | else if (!strcmp(value, "local")) |
| 632 | cfg->autorebase = AUTOREBASE_LOCAL; |
| 633 | else if (!strcmp(value, "remote")) |
| 634 | cfg->autorebase = AUTOREBASE_REMOTE; |
| 635 | else if (!strcmp(value, "always")) |
| 636 | cfg->autorebase = AUTOREBASE_ALWAYS; |
| 637 | else |
| 638 | return error(_("malformed value for %s"), var); |
| 639 | return 0; |
| 640 | } |
| 641 | |
| 642 | /* Add other config variables here and to Documentation/config.adoc. */ |
| 643 | return 0; |
| 644 | } |
| 645 | |
| 646 | static int git_default_push_config(const char *var, const char *value) |
| 647 | { |
| 648 | struct repo_config_values *cfg = repo_config_values(the_repository); |
| 649 | |
| 650 | if (!strcmp(var, "push.default")) { |
| 651 | if (!value) |
| 652 | return config_error_nonbool(var); |
| 653 | else if (!strcmp(value, "nothing")) |
| 654 | cfg->push_default = PUSH_DEFAULT_NOTHING; |
| 655 | else if (!strcmp(value, "matching")) |
| 656 | cfg->push_default = PUSH_DEFAULT_MATCHING; |
| 657 | else if (!strcmp(value, "simple")) |
| 658 | cfg->push_default = PUSH_DEFAULT_SIMPLE; |
| 659 | else if (!strcmp(value, "upstream")) |
| 660 | cfg->push_default = PUSH_DEFAULT_UPSTREAM; |
| 661 | else if (!strcmp(value, "tracking")) /* deprecated */ |
| 662 | cfg->push_default = PUSH_DEFAULT_UPSTREAM; |
| 663 | else if (!strcmp(value, "current")) |
| 664 | cfg->push_default = PUSH_DEFAULT_CURRENT; |
| 665 | else { |
| 666 | error(_("malformed value for %s: %s"), var, value); |
| 667 | return error(_("must be one of nothing, matching, simple, " |
| 668 | "upstream or current")); |
| 669 | } |
| 670 | return 0; |
| 671 | } |
| 672 | |
| 673 | /* Add other config variables here and to Documentation/config.adoc. */ |
| 674 | return 0; |
| 675 | } |
| 676 | |
| 677 | static int git_default_attr_config(const char *var, const char *value) |
| 678 | { |
| 679 | if (!strcmp(var, "attr.tree")) { |
| 680 | FREE_AND_NULL(git_attr_tree); |
| 681 | return git_config_string(&git_attr_tree, var, value); |
| 682 | } |
| 683 | |
| 684 | /* |
| 685 | * Add other attribute related config variables here and to |
| 686 | * Documentation/config/attr.adoc. |
| 687 | */ |
| 688 | return 0; |
| 689 | } |
| 690 | |
| 691 | int git_default_config(const char *var, const char *value, |
| 692 | const struct config_context *ctx, void *cb) |
| 693 | { |
| 694 | struct repo_config_values *cfg = repo_config_values(the_repository); |
| 695 | |
| 696 | if (starts_with(var, "core.")) |
| 697 | return git_default_core_config(var, value, ctx, cb); |
| 698 | |
| 699 | if (starts_with(var, "user.") || |
| 700 | starts_with(var, "author.") || |
| 701 | starts_with(var, "committer.")) |
| 702 | return git_ident_config(var, value, ctx, cb); |
| 703 | |
| 704 | if (starts_with(var, "i18n.")) |
| 705 | return git_default_i18n_config(var, value); |
| 706 | |
| 707 | if (starts_with(var, "branch.")) |
| 708 | return git_default_branch_config(var, value); |
| 709 | |
| 710 | if (starts_with(var, "push.")) |
| 711 | return git_default_push_config(var, value); |
| 712 | |
| 713 | if (starts_with(var, "attr.")) |
| 714 | return git_default_attr_config(var, value); |
| 715 | |
| 716 | if (starts_with(var, "advice.") || starts_with(var, "color.advice")) |
| 717 | return git_default_advice_config(var, value); |
| 718 | |
| 719 | if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) { |
| 720 | pager_use_color = git_config_bool(var,value); |
| 721 | return 0; |
| 722 | } |
| 723 | |
| 724 | if (!strcmp(var, "pack.packsizelimit")) { |
| 725 | pack_size_limit_cfg = git_config_ulong(var, value, ctx->kvi); |
| 726 | return 0; |
| 727 | } |
| 728 | |
| 729 | if (!strcmp(var, "pack.compression")) { |
| 730 | int level = git_config_int(var, value, ctx->kvi); |
| 731 | if (level == -1) |
| 732 | level = Z_DEFAULT_COMPRESSION; |
| 733 | else if (level < 0 || level > Z_BEST_COMPRESSION) |
| 734 | die(_("bad pack compression level %d"), level); |
| 735 | cfg->pack_compression_level = level; |
| 736 | pack_compression_seen = 1; |
| 737 | return 0; |
| 738 | } |
| 739 | |
| 740 | if (starts_with(var, "sparse.")) |
| 741 | return git_default_sparse_config(var, value); |
| 742 | |
| 743 | /* Add other config variables here and to Documentation/config.adoc. */ |
| 744 | return 0; |
| 745 | } |
| 746 | |
| 747 | void repo_config_values_init(struct repo_config_values *cfg) |
| 748 | { |
| 749 | cfg->attributes_file = NULL; |
| 750 | cfg->excludes_file = NULL; |
| 751 | cfg->editor_program = NULL; |
| 752 | cfg->pager_program = NULL; |
| 753 | cfg->askpass_program = NULL; |
| 754 | cfg->apply_default_whitespace = NULL; |
| 755 | cfg->apply_default_ignorewhitespace = NULL; |
| 756 | cfg->push_default = PUSH_DEFAULT_UNSPECIFIED; |
| 757 | cfg->autorebase = AUTOREBASE_NEVER; |
| 758 | cfg->object_creation_mode = OBJECT_CREATION_MODE; |
| 759 | cfg->apply_sparse_checkout = 0; |
| 760 | cfg->protect_hfs = PROTECT_HFS_DEFAULT; |
| 761 | cfg->protect_ntfs = PROTECT_NTFS_DEFAULT; |
| 762 | cfg->ignore_case = 0; |
| 763 | cfg->trust_executable_bit = 1; |
| 764 | cfg->has_symlinks = platform_has_symlinks(); |
| 765 | cfg->branch_track = BRANCH_TRACK_REMOTE; |
| 766 | cfg->trust_ctime = 1; |
| 767 | cfg->check_stat = 1; |
| 768 | cfg->zlib_compression_level = Z_BEST_SPEED; |
| 769 | cfg->pack_compression_level = Z_DEFAULT_COMPRESSION; |
| 770 | cfg->precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */ |
| 771 | cfg->core_sparse_checkout_cone = 0; |
| 772 | cfg->sparse_expect_files_outside_of_patterns = 0; |
| 773 | cfg->warn_on_object_refname_ambiguity = 1; |
| 774 | } |
| 775 | |
| 776 | void repo_config_values_clear(struct repo_config_values *cfg) |
| 777 | { |
| 778 | FREE_AND_NULL(cfg->attributes_file); |
| 779 | FREE_AND_NULL(cfg->excludes_file); |
| 780 | FREE_AND_NULL(cfg->editor_program); |
| 781 | FREE_AND_NULL(cfg->pager_program); |
| 782 | FREE_AND_NULL(cfg->askpass_program); |
| 783 | FREE_AND_NULL(cfg->apply_default_whitespace); |
| 784 | FREE_AND_NULL(cfg->apply_default_ignorewhitespace); |
| 785 | } |