Git fork

config: move Git config parsing into "environment.c"

In "config.c" we host both the business logic to read and write config
files as well as the logic to parse specific Git-related variables. On
the one hand this is mixing concerns, but even more importantly it means
that we cannot easily remove the dependency on `the_repository` in our
config parsing logic.

Move the logic into "environment.c". This file is a grab bag of all
kinds of global state already, so it is quite a good fit. Furthermore,
it also hosts most of the global variables that we're parsing the config
values into, making this an even better fit.

Note that there is one hidden change: in `parse_fsync_components()` we
use an `int` to iterate through `ARRAY_SIZE(fsync_component_names)`. But
as -Wsign-compare warnings are enabled in this file this causes a
compiler warning. The issue is fixed by using a `size_t` instead.

This change allows us to drop the `USE_THE_REPOSITORY_VARIABLE`
declaration.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
08b77586 00271bb3

+566 -514
+1
builtin/add.c
··· 7 7 #include "builtin.h" 8 8 #include "advice.h" 9 9 #include "config.h" 10 + #include "environment.h" 10 11 #include "lockfile.h" 11 12 #include "editor.h" 12 13 #include "dir.h"
+1
builtin/check-ignore.c
··· 2 2 #include "builtin.h" 3 3 #include "config.h" 4 4 #include "dir.h" 5 + #include "environment.h" 5 6 #include "gettext.h" 6 7 #include "quote.h" 7 8 #include "pathspec.h"
+1
builtin/check-mailmap.c
··· 1 1 #define USE_THE_REPOSITORY_VARIABLE 2 2 #include "builtin.h" 3 3 #include "config.h" 4 + #include "environment.h" 4 5 #include "gettext.h" 5 6 #include "ident.h" 6 7 #include "mailmap.h"
+1
builtin/checkout--worker.c
··· 4 4 #include "builtin.h" 5 5 #include "config.h" 6 6 #include "entry.h" 7 + #include "environment.h" 7 8 #include "gettext.h" 8 9 #include "parallel-checkout.h" 9 10 #include "parse-options.h"
+1
builtin/checkout-index.c
··· 9 9 10 10 #include "builtin.h" 11 11 #include "config.h" 12 + #include "environment.h" 12 13 #include "gettext.h" 13 14 #include "lockfile.h" 14 15 #include "quote.h"
+1
builtin/clean.c
··· 13 13 #include "abspath.h" 14 14 #include "config.h" 15 15 #include "dir.h" 16 + #include "environment.h" 16 17 #include "gettext.h" 17 18 #include "parse-options.h" 18 19 #include "path.h"
+1
builtin/commit-graph.c
··· 2 2 #include "builtin.h" 3 3 #include "commit.h" 4 4 #include "config.h" 5 + #include "environment.h" 5 6 #include "gettext.h" 6 7 #include "hex.h" 7 8 #include "parse-options.h"
+1
builtin/commit-tree.c
··· 6 6 #define USE_THE_REPOSITORY_VARIABLE 7 7 #include "builtin.h" 8 8 #include "config.h" 9 + #include "environment.h" 9 10 #include "gettext.h" 10 11 #include "hex.h" 11 12 #include "object-name.h"
+1
builtin/count-objects.c
··· 7 7 #include "builtin.h" 8 8 #include "config.h" 9 9 #include "dir.h" 10 + #include "environment.h" 10 11 #include "gettext.h" 11 12 #include "path.h" 12 13 #include "parse-options.h"
+1
builtin/credential.c
··· 3 3 #include "git-compat-util.h" 4 4 #include "credential.h" 5 5 #include "builtin.h" 6 + #include "environment.h" 6 7 #include "config.h" 7 8 8 9 static const char usage_msg[] =
+1
builtin/fast-export.c
··· 9 9 10 10 #include "builtin.h" 11 11 #include "config.h" 12 + #include "environment.h" 12 13 #include "gettext.h" 13 14 #include "hex.h" 14 15 #include "refs.h"
+1
builtin/for-each-ref.c
··· 1 1 #include "builtin.h" 2 2 #include "commit.h" 3 3 #include "config.h" 4 + #include "environment.h" 4 5 #include "gettext.h" 5 6 #include "object.h" 6 7 #include "parse-options.h"
+1
builtin/fsmonitor--daemon.c
··· 5 5 #include "abspath.h" 6 6 #include "config.h" 7 7 #include "dir.h" 8 + #include "environment.h" 8 9 #include "gettext.h" 9 10 #include "parse-options.h" 10 11 #include "fsmonitor-ll.h"
+1
builtin/grep.c
··· 9 9 10 10 #include "builtin.h" 11 11 #include "abspath.h" 12 + #include "environment.h" 12 13 #include "gettext.h" 13 14 #include "hex.h" 14 15 #include "config.h"
+1
builtin/hash-object.c
··· 8 8 #include "builtin.h" 9 9 #include "abspath.h" 10 10 #include "config.h" 11 + #include "environment.h" 11 12 #include "gettext.h" 12 13 #include "hex.h" 13 14 #include "object-file.h"
+1
builtin/help.c
··· 6 6 7 7 #include "builtin.h" 8 8 #include "config.h" 9 + #include "environment.h" 9 10 #include "exec-cmd.h" 10 11 #include "gettext.h" 11 12 #include "pager.h"
+1
builtin/hook.c
··· 1 1 #define USE_THE_REPOSITORY_VARIABLE 2 2 #include "builtin.h" 3 3 #include "config.h" 4 + #include "environment.h" 4 5 #include "gettext.h" 5 6 #include "hook.h" 6 7 #include "parse-options.h"
+1
builtin/interpret-trailers.c
··· 6 6 */ 7 7 #define USE_THE_REPOSITORY_VARIABLE 8 8 #include "builtin.h" 9 + #include "environment.h" 9 10 #include "gettext.h" 10 11 #include "parse-options.h" 11 12 #include "string-list.h"
+1
builtin/ls-files.c
··· 11 11 #include "builtin.h" 12 12 #include "config.h" 13 13 #include "convert.h" 14 + #include "environment.h" 14 15 #include "quote.h" 15 16 #include "dir.h" 16 17 #include "gettext.h"
+1
builtin/ls-tree.c
··· 7 7 #include "builtin.h" 8 8 9 9 #include "config.h" 10 + #include "environment.h" 10 11 #include "gettext.h" 11 12 #include "hex.h" 12 13 #include "object-name.h"
+1
builtin/merge-base.c
··· 2 2 #include "builtin.h" 3 3 #include "config.h" 4 4 #include "commit.h" 5 + #include "environment.h" 5 6 #include "gettext.h" 6 7 #include "hex.h" 7 8 #include "object-name.h"
+1
builtin/merge-tree.c
··· 1 1 #define USE_THE_REPOSITORY_VARIABLE 2 2 3 3 #include "builtin.h" 4 + #include "environment.h" 4 5 #include "tree-walk.h" 5 6 #include "xdiff-interface.h" 6 7 #include "help.h"
+1
builtin/multi-pack-index.c
··· 2 2 #include "builtin.h" 3 3 #include "abspath.h" 4 4 #include "config.h" 5 + #include "environment.h" 5 6 #include "gettext.h" 6 7 #include "parse-options.h" 7 8 #include "midx.h"
+1
builtin/pack-refs.c
··· 1 1 #include "builtin.h" 2 2 #include "config.h" 3 + #include "environment.h" 3 4 #include "gettext.h" 4 5 #include "parse-options.h" 5 6 #include "refs.h"
+1
builtin/patch-id.c
··· 3 3 #include "builtin.h" 4 4 #include "config.h" 5 5 #include "diff.h" 6 + #include "environment.h" 6 7 #include "gettext.h" 7 8 #include "hash.h" 8 9 #include "hex.h"
+1
builtin/pull.c
··· 11 11 #include "builtin.h" 12 12 #include "advice.h" 13 13 #include "config.h" 14 + #include "environment.h" 14 15 #include "gettext.h" 15 16 #include "hex.h" 16 17 #include "merge.h"
+1
builtin/read-tree.c
··· 6 6 #define USE_THE_REPOSITORY_VARIABLE 7 7 #include "builtin.h" 8 8 #include "config.h" 9 + #include "environment.h" 9 10 #include "gettext.h" 10 11 #include "hex.h" 11 12 #include "lockfile.h"
+1
builtin/replace.c
··· 11 11 #include "builtin.h" 12 12 #include "config.h" 13 13 #include "editor.h" 14 + #include "environment.h" 14 15 #include "gettext.h" 15 16 #include "hex.h" 16 17 #include "refs.h"
+1
builtin/rm.c
··· 9 9 #include "builtin.h" 10 10 #include "advice.h" 11 11 #include "config.h" 12 + #include "environment.h" 12 13 #include "lockfile.h" 13 14 #include "dir.h" 14 15 #include "gettext.h"
+1
builtin/send-pack.c
··· 1 1 #include "builtin.h" 2 2 #include "config.h" 3 + #include "environment.h" 3 4 #include "hex.h" 4 5 #include "pkt-line.h" 5 6 #include "run-command.h"
+1
builtin/show-ref.c
··· 1 1 #define USE_THE_REPOSITORY_VARIABLE 2 2 #include "builtin.h" 3 3 #include "config.h" 4 + #include "environment.h" 4 5 #include "gettext.h" 5 6 #include "hex.h" 6 7 #include "refs/refs-internal.h"
+1
builtin/symbolic-ref.c
··· 1 1 #define USE_THE_REPOSITORY_VARIABLE 2 2 #include "builtin.h" 3 3 #include "config.h" 4 + #include "environment.h" 4 5 #include "gettext.h" 5 6 #include "refs.h" 6 7 #include "parse-options.h"
+1
builtin/unpack-file.c
··· 1 1 #define USE_THE_REPOSITORY_VARIABLE 2 2 #include "builtin.h" 3 3 #include "config.h" 4 + #include "environment.h" 4 5 #include "hex.h" 5 6 #include "object-file.h" 6 7 #include "object-name.h"
+1
builtin/update-ref.c
··· 3 3 4 4 #include "builtin.h" 5 5 #include "config.h" 6 + #include "environment.h" 6 7 #include "gettext.h" 7 8 #include "hash.h" 8 9 #include "hex.h"
+1
builtin/update-server-info.c
··· 1 1 #include "builtin.h" 2 2 #include "config.h" 3 + #include "environment.h" 3 4 #include "gettext.h" 4 5 #include "parse-options.h" 5 6 #include "server-info.h"
+1
builtin/var.c
··· 11 11 #include "attr.h" 12 12 #include "config.h" 13 13 #include "editor.h" 14 + #include "environment.h" 14 15 #include "ident.h" 15 16 #include "pager.h" 16 17 #include "refs.h"
+1
builtin/verify-commit.c
··· 7 7 */ 8 8 #include "builtin.h" 9 9 #include "config.h" 10 + #include "environment.h" 10 11 #include "gettext.h" 11 12 #include "object-name.h" 12 13 #include "commit.h"
+1
builtin/verify-pack.c
··· 1 1 #define USE_THE_REPOSITORY_VARIABLE 2 2 #include "builtin.h" 3 3 #include "config.h" 4 + #include "environment.h" 4 5 #include "gettext.h" 5 6 #include "run-command.h" 6 7 #include "parse-options.h"
+1
builtin/verify-tag.c
··· 7 7 */ 8 8 #include "builtin.h" 9 9 #include "config.h" 10 + #include "environment.h" 10 11 #include "gettext.h" 11 12 #include "tag.h" 12 13 #include "object-name.h"
+1
builtin/write-tree.c
··· 6 6 #define USE_THE_REPOSITORY_VARIABLE 7 7 #include "builtin.h" 8 8 #include "config.h" 9 + #include "environment.h" 9 10 #include "gettext.h" 10 11 #include "hex.h" 11 12 #include "tree.h"
+1
commit-graph.c
··· 4 4 #include "git-compat-util.h" 5 5 #include "config.h" 6 6 #include "csum-file.h" 7 + #include "environment.h" 7 8 #include "gettext.h" 8 9 #include "hex.h" 9 10 #include "lockfile.h"
-511
config.c
··· 6 6 * 7 7 */ 8 8 9 - #define USE_THE_REPOSITORY_VARIABLE 10 9 #define DISABLE_SIGN_COMPARE_WARNINGS 11 10 12 11 #include "git-compat-util.h" 13 12 #include "abspath.h" 14 - #include "advice.h" 15 13 #include "date.h" 16 14 #include "branch.h" 17 15 #include "config.h" ··· 20 18 #include "environment.h" 21 19 #include "gettext.h" 22 20 #include "git-zlib.h" 23 - #include "ident.h" 24 21 #include "repository.h" 25 22 #include "lockfile.h" 26 - #include "mailmap.h" 27 - #include "attr.h" 28 23 #include "exec-cmd.h" 29 24 #include "strbuf.h" 30 25 #include "quote.h" ··· 32 27 #include "string-list.h" 33 28 #include "object-name.h" 34 29 #include "odb.h" 35 - #include "pager.h" 36 30 #include "path.h" 37 31 #include "utf8.h" 38 32 #include "color.h" ··· 41 35 #include "strvec.h" 42 36 #include "trace2.h" 43 37 #include "wildmatch.h" 44 - #include "ws.h" 45 38 #include "write-or-die.h" 46 39 47 40 struct config_source { ··· 70 63 long (*do_ftell)(struct config_source *c); 71 64 }; 72 65 #define CONFIG_SOURCE_INIT { 0 } 73 - 74 - static int pack_compression_seen; 75 - static int zlib_compression_seen; 76 66 77 67 /* 78 68 * Config that comes from trusted scopes, namely: ··· 1262 1252 return ret; 1263 1253 } 1264 1254 1265 - static const struct fsync_component_name { 1266 - const char *name; 1267 - enum fsync_component component_bits; 1268 - } fsync_component_names[] = { 1269 - { "loose-object", FSYNC_COMPONENT_LOOSE_OBJECT }, 1270 - { "pack", FSYNC_COMPONENT_PACK }, 1271 - { "pack-metadata", FSYNC_COMPONENT_PACK_METADATA }, 1272 - { "commit-graph", FSYNC_COMPONENT_COMMIT_GRAPH }, 1273 - { "index", FSYNC_COMPONENT_INDEX }, 1274 - { "objects", FSYNC_COMPONENTS_OBJECTS }, 1275 - { "reference", FSYNC_COMPONENT_REFERENCE }, 1276 - { "derived-metadata", FSYNC_COMPONENTS_DERIVED_METADATA }, 1277 - { "committed", FSYNC_COMPONENTS_COMMITTED }, 1278 - { "added", FSYNC_COMPONENTS_ADDED }, 1279 - { "all", FSYNC_COMPONENTS_ALL }, 1280 - }; 1281 - 1282 - static enum fsync_component parse_fsync_components(const char *var, const char *string) 1283 - { 1284 - enum fsync_component current = FSYNC_COMPONENTS_PLATFORM_DEFAULT; 1285 - enum fsync_component positive = 0, negative = 0; 1286 - 1287 - while (string) { 1288 - int i; 1289 - size_t len; 1290 - const char *ep; 1291 - int negated = 0; 1292 - int found = 0; 1293 - 1294 - string = string + strspn(string, ", \t\n\r"); 1295 - ep = strchrnul(string, ','); 1296 - len = ep - string; 1297 - if (!strcmp(string, "none")) { 1298 - current = FSYNC_COMPONENT_NONE; 1299 - goto next_name; 1300 - } 1301 - 1302 - if (*string == '-') { 1303 - negated = 1; 1304 - string++; 1305 - len--; 1306 - if (!len) 1307 - warning(_("invalid value for variable %s"), var); 1308 - } 1309 - 1310 - if (!len) 1311 - break; 1312 - 1313 - for (i = 0; i < ARRAY_SIZE(fsync_component_names); ++i) { 1314 - const struct fsync_component_name *n = &fsync_component_names[i]; 1315 - 1316 - if (strncmp(n->name, string, len)) 1317 - continue; 1318 - 1319 - found = 1; 1320 - if (negated) 1321 - negative |= n->component_bits; 1322 - else 1323 - positive |= n->component_bits; 1324 - } 1325 - 1326 - if (!found) { 1327 - char *component = xstrndup(string, len); 1328 - warning(_("ignoring unknown core.fsync component '%s'"), component); 1329 - free(component); 1330 - } 1331 - 1332 - next_name: 1333 - string = ep; 1334 - } 1335 - 1336 - return (current & ~negative) | positive; 1337 - } 1338 - 1339 1255 int git_config_bool_or_int(const char *name, const char *value, 1340 1256 const struct key_value_info *kvi, int *is_bool) 1341 1257 { ··· 1390 1306 return config_error_nonbool(var); 1391 1307 if (color_parse(value, dest) < 0) 1392 1308 return -1; 1393 - return 0; 1394 - } 1395 - 1396 - static int git_default_core_config(const char *var, const char *value, 1397 - const struct config_context *ctx, void *cb) 1398 - { 1399 - /* This needs a better name */ 1400 - if (!strcmp(var, "core.filemode")) { 1401 - trust_executable_bit = git_config_bool(var, value); 1402 - return 0; 1403 - } 1404 - if (!strcmp(var, "core.trustctime")) { 1405 - trust_ctime = git_config_bool(var, value); 1406 - return 0; 1407 - } 1408 - if (!strcmp(var, "core.checkstat")) { 1409 - if (!value) 1410 - return config_error_nonbool(var); 1411 - if (!strcasecmp(value, "default")) 1412 - check_stat = 1; 1413 - else if (!strcasecmp(value, "minimal")) 1414 - check_stat = 0; 1415 - else 1416 - return error(_("invalid value for '%s': '%s'"), 1417 - var, value); 1418 - } 1419 - 1420 - if (!strcmp(var, "core.quotepath")) { 1421 - quote_path_fully = git_config_bool(var, value); 1422 - return 0; 1423 - } 1424 - 1425 - if (!strcmp(var, "core.symlinks")) { 1426 - has_symlinks = git_config_bool(var, value); 1427 - return 0; 1428 - } 1429 - 1430 - if (!strcmp(var, "core.ignorecase")) { 1431 - ignore_case = git_config_bool(var, value); 1432 - return 0; 1433 - } 1434 - 1435 - if (!strcmp(var, "core.attributesfile")) { 1436 - FREE_AND_NULL(git_attributes_file); 1437 - return git_config_pathname(&git_attributes_file, var, value); 1438 - } 1439 - 1440 - if (!strcmp(var, "core.bare")) { 1441 - is_bare_repository_cfg = git_config_bool(var, value); 1442 - return 0; 1443 - } 1444 - 1445 - if (!strcmp(var, "core.ignorestat")) { 1446 - assume_unchanged = git_config_bool(var, value); 1447 - return 0; 1448 - } 1449 - 1450 - if (!strcmp(var, "core.abbrev")) { 1451 - if (!value) 1452 - return config_error_nonbool(var); 1453 - if (!strcasecmp(value, "auto")) 1454 - default_abbrev = -1; 1455 - else if (!git_parse_maybe_bool_text(value)) 1456 - default_abbrev = GIT_MAX_HEXSZ; 1457 - else { 1458 - int abbrev = git_config_int(var, value, ctx->kvi); 1459 - if (abbrev < minimum_abbrev) 1460 - return error(_("abbrev length out of range: %d"), abbrev); 1461 - default_abbrev = abbrev; 1462 - } 1463 - return 0; 1464 - } 1465 - 1466 - if (!strcmp(var, "core.disambiguate")) 1467 - return set_disambiguate_hint_config(var, value); 1468 - 1469 - if (!strcmp(var, "core.loosecompression")) { 1470 - int level = git_config_int(var, value, ctx->kvi); 1471 - if (level == -1) 1472 - level = Z_DEFAULT_COMPRESSION; 1473 - else if (level < 0 || level > Z_BEST_COMPRESSION) 1474 - die(_("bad zlib compression level %d"), level); 1475 - zlib_compression_level = level; 1476 - zlib_compression_seen = 1; 1477 - return 0; 1478 - } 1479 - 1480 - if (!strcmp(var, "core.compression")) { 1481 - int level = git_config_int(var, value, ctx->kvi); 1482 - if (level == -1) 1483 - level = Z_DEFAULT_COMPRESSION; 1484 - else if (level < 0 || level > Z_BEST_COMPRESSION) 1485 - die(_("bad zlib compression level %d"), level); 1486 - if (!zlib_compression_seen) 1487 - zlib_compression_level = level; 1488 - if (!pack_compression_seen) 1489 - pack_compression_level = level; 1490 - return 0; 1491 - } 1492 - 1493 - if (!strcmp(var, "core.autocrlf")) { 1494 - if (value && !strcasecmp(value, "input")) { 1495 - auto_crlf = AUTO_CRLF_INPUT; 1496 - return 0; 1497 - } 1498 - auto_crlf = git_config_bool(var, value); 1499 - return 0; 1500 - } 1501 - 1502 - if (!strcmp(var, "core.safecrlf")) { 1503 - int eol_rndtrp_die; 1504 - if (value && !strcasecmp(value, "warn")) { 1505 - global_conv_flags_eol = CONV_EOL_RNDTRP_WARN; 1506 - return 0; 1507 - } 1508 - eol_rndtrp_die = git_config_bool(var, value); 1509 - global_conv_flags_eol = eol_rndtrp_die ? 1510 - CONV_EOL_RNDTRP_DIE : 0; 1511 - return 0; 1512 - } 1513 - 1514 - if (!strcmp(var, "core.eol")) { 1515 - if (value && !strcasecmp(value, "lf")) 1516 - core_eol = EOL_LF; 1517 - else if (value && !strcasecmp(value, "crlf")) 1518 - core_eol = EOL_CRLF; 1519 - else if (value && !strcasecmp(value, "native")) 1520 - core_eol = EOL_NATIVE; 1521 - else 1522 - core_eol = EOL_UNSET; 1523 - return 0; 1524 - } 1525 - 1526 - if (!strcmp(var, "core.checkroundtripencoding")) { 1527 - FREE_AND_NULL(check_roundtrip_encoding); 1528 - return git_config_string(&check_roundtrip_encoding, var, value); 1529 - } 1530 - 1531 - if (!strcmp(var, "core.editor")) { 1532 - FREE_AND_NULL(editor_program); 1533 - return git_config_string(&editor_program, var, value); 1534 - } 1535 - 1536 - if (!strcmp(var, "core.commentchar") || 1537 - !strcmp(var, "core.commentstring")) { 1538 - if (!value) 1539 - return config_error_nonbool(var); 1540 - else if (!strcasecmp(value, "auto")) 1541 - auto_comment_line_char = 1; 1542 - else if (value[0]) { 1543 - if (strchr(value, '\n')) 1544 - return error(_("%s cannot contain newline"), var); 1545 - comment_line_str = value; 1546 - FREE_AND_NULL(comment_line_str_to_free); 1547 - auto_comment_line_char = 0; 1548 - } else 1549 - return error(_("%s must have at least one character"), var); 1550 - return 0; 1551 - } 1552 - 1553 - if (!strcmp(var, "core.askpass")) { 1554 - FREE_AND_NULL(askpass_program); 1555 - return git_config_string(&askpass_program, var, value); 1556 - } 1557 - 1558 - if (!strcmp(var, "core.excludesfile")) { 1559 - FREE_AND_NULL(excludes_file); 1560 - return git_config_pathname(&excludes_file, var, value); 1561 - } 1562 - 1563 - if (!strcmp(var, "core.whitespace")) { 1564 - if (!value) 1565 - return config_error_nonbool(var); 1566 - whitespace_rule_cfg = parse_whitespace_rule(value); 1567 - return 0; 1568 - } 1569 - 1570 - if (!strcmp(var, "core.fsync")) { 1571 - if (!value) 1572 - return config_error_nonbool(var); 1573 - fsync_components = parse_fsync_components(var, value); 1574 - return 0; 1575 - } 1576 - 1577 - if (!strcmp(var, "core.fsyncmethod")) { 1578 - if (!value) 1579 - return config_error_nonbool(var); 1580 - if (!strcmp(value, "fsync")) 1581 - fsync_method = FSYNC_METHOD_FSYNC; 1582 - else if (!strcmp(value, "writeout-only")) 1583 - fsync_method = FSYNC_METHOD_WRITEOUT_ONLY; 1584 - else if (!strcmp(value, "batch")) 1585 - fsync_method = FSYNC_METHOD_BATCH; 1586 - else 1587 - warning(_("ignoring unknown core.fsyncMethod value '%s'"), value); 1588 - 1589 - } 1590 - 1591 - if (!strcmp(var, "core.fsyncobjectfiles")) { 1592 - if (fsync_object_files < 0) 1593 - warning(_("core.fsyncObjectFiles is deprecated; use core.fsync instead")); 1594 - fsync_object_files = git_config_bool(var, value); 1595 - return 0; 1596 - } 1597 - 1598 - if (!strcmp(var, "core.createobject")) { 1599 - if (!value) 1600 - return config_error_nonbool(var); 1601 - if (!strcmp(value, "rename")) 1602 - object_creation_mode = OBJECT_CREATION_USES_RENAMES; 1603 - else if (!strcmp(value, "link")) 1604 - object_creation_mode = OBJECT_CREATION_USES_HARDLINKS; 1605 - else 1606 - die(_("invalid mode for object creation: %s"), value); 1607 - return 0; 1608 - } 1609 - 1610 - if (!strcmp(var, "core.sparsecheckout")) { 1611 - core_apply_sparse_checkout = git_config_bool(var, value); 1612 - return 0; 1613 - } 1614 - 1615 - if (!strcmp(var, "core.sparsecheckoutcone")) { 1616 - core_sparse_checkout_cone = git_config_bool(var, value); 1617 - return 0; 1618 - } 1619 - 1620 - if (!strcmp(var, "core.precomposeunicode")) { 1621 - precomposed_unicode = git_config_bool(var, value); 1622 - return 0; 1623 - } 1624 - 1625 - if (!strcmp(var, "core.protecthfs")) { 1626 - protect_hfs = git_config_bool(var, value); 1627 - return 0; 1628 - } 1629 - 1630 - if (!strcmp(var, "core.protectntfs")) { 1631 - protect_ntfs = git_config_bool(var, value); 1632 - return 0; 1633 - } 1634 - 1635 - if (!strcmp(var, "core.maxtreedepth")) { 1636 - max_allowed_tree_depth = git_config_int(var, value, ctx->kvi); 1637 - return 0; 1638 - } 1639 - 1640 - /* Add other config variables here and to Documentation/config.adoc. */ 1641 - return platform_core_config(var, value, ctx, cb); 1642 - } 1643 - 1644 - static int git_default_sparse_config(const char *var, const char *value) 1645 - { 1646 - if (!strcmp(var, "sparse.expectfilesoutsideofpatterns")) { 1647 - sparse_expect_files_outside_of_patterns = git_config_bool(var, value); 1648 - return 0; 1649 - } 1650 - 1651 - /* Add other config variables here and to Documentation/config/sparse.adoc. */ 1652 - return 0; 1653 - } 1654 - 1655 - static int git_default_i18n_config(const char *var, const char *value) 1656 - { 1657 - if (!strcmp(var, "i18n.commitencoding")) { 1658 - FREE_AND_NULL(git_commit_encoding); 1659 - return git_config_string(&git_commit_encoding, var, value); 1660 - } 1661 - 1662 - if (!strcmp(var, "i18n.logoutputencoding")) { 1663 - FREE_AND_NULL(git_log_output_encoding); 1664 - return git_config_string(&git_log_output_encoding, var, value); 1665 - } 1666 - 1667 - /* Add other config variables here and to Documentation/config.adoc. */ 1668 - return 0; 1669 - } 1670 - 1671 - static int git_default_branch_config(const char *var, const char *value) 1672 - { 1673 - if (!strcmp(var, "branch.autosetupmerge")) { 1674 - if (value && !strcmp(value, "always")) { 1675 - git_branch_track = BRANCH_TRACK_ALWAYS; 1676 - return 0; 1677 - } else if (value && !strcmp(value, "inherit")) { 1678 - git_branch_track = BRANCH_TRACK_INHERIT; 1679 - return 0; 1680 - } else if (value && !strcmp(value, "simple")) { 1681 - git_branch_track = BRANCH_TRACK_SIMPLE; 1682 - return 0; 1683 - } 1684 - git_branch_track = git_config_bool(var, value); 1685 - return 0; 1686 - } 1687 - if (!strcmp(var, "branch.autosetuprebase")) { 1688 - if (!value) 1689 - return config_error_nonbool(var); 1690 - else if (!strcmp(value, "never")) 1691 - autorebase = AUTOREBASE_NEVER; 1692 - else if (!strcmp(value, "local")) 1693 - autorebase = AUTOREBASE_LOCAL; 1694 - else if (!strcmp(value, "remote")) 1695 - autorebase = AUTOREBASE_REMOTE; 1696 - else if (!strcmp(value, "always")) 1697 - autorebase = AUTOREBASE_ALWAYS; 1698 - else 1699 - return error(_("malformed value for %s"), var); 1700 - return 0; 1701 - } 1702 - 1703 - /* Add other config variables here and to Documentation/config.adoc. */ 1704 - return 0; 1705 - } 1706 - 1707 - static int git_default_push_config(const char *var, const char *value) 1708 - { 1709 - if (!strcmp(var, "push.default")) { 1710 - if (!value) 1711 - return config_error_nonbool(var); 1712 - else if (!strcmp(value, "nothing")) 1713 - push_default = PUSH_DEFAULT_NOTHING; 1714 - else if (!strcmp(value, "matching")) 1715 - push_default = PUSH_DEFAULT_MATCHING; 1716 - else if (!strcmp(value, "simple")) 1717 - push_default = PUSH_DEFAULT_SIMPLE; 1718 - else if (!strcmp(value, "upstream")) 1719 - push_default = PUSH_DEFAULT_UPSTREAM; 1720 - else if (!strcmp(value, "tracking")) /* deprecated */ 1721 - push_default = PUSH_DEFAULT_UPSTREAM; 1722 - else if (!strcmp(value, "current")) 1723 - push_default = PUSH_DEFAULT_CURRENT; 1724 - else { 1725 - error(_("malformed value for %s: %s"), var, value); 1726 - return error(_("must be one of nothing, matching, simple, " 1727 - "upstream or current")); 1728 - } 1729 - return 0; 1730 - } 1731 - 1732 - /* Add other config variables here and to Documentation/config.adoc. */ 1733 - return 0; 1734 - } 1735 - 1736 - static int git_default_mailmap_config(const char *var, const char *value) 1737 - { 1738 - if (!strcmp(var, "mailmap.file")) { 1739 - FREE_AND_NULL(git_mailmap_file); 1740 - return git_config_pathname(&git_mailmap_file, var, value); 1741 - } 1742 - 1743 - if (!strcmp(var, "mailmap.blob")) { 1744 - FREE_AND_NULL(git_mailmap_blob); 1745 - return git_config_string(&git_mailmap_blob, var, value); 1746 - } 1747 - 1748 - /* Add other config variables here and to Documentation/config.adoc. */ 1749 - return 0; 1750 - } 1751 - 1752 - static int git_default_attr_config(const char *var, const char *value) 1753 - { 1754 - if (!strcmp(var, "attr.tree")) { 1755 - FREE_AND_NULL(git_attr_tree); 1756 - return git_config_string(&git_attr_tree, var, value); 1757 - } 1758 - 1759 - /* 1760 - * Add other attribute related config variables here and to 1761 - * Documentation/config/attr.adoc. 1762 - */ 1763 - return 0; 1764 - } 1765 - 1766 - int git_default_config(const char *var, const char *value, 1767 - const struct config_context *ctx, void *cb) 1768 - { 1769 - if (starts_with(var, "core.")) 1770 - return git_default_core_config(var, value, ctx, cb); 1771 - 1772 - if (starts_with(var, "user.") || 1773 - starts_with(var, "author.") || 1774 - starts_with(var, "committer.")) 1775 - return git_ident_config(var, value, ctx, cb); 1776 - 1777 - if (starts_with(var, "i18n.")) 1778 - return git_default_i18n_config(var, value); 1779 - 1780 - if (starts_with(var, "branch.")) 1781 - return git_default_branch_config(var, value); 1782 - 1783 - if (starts_with(var, "push.")) 1784 - return git_default_push_config(var, value); 1785 - 1786 - if (starts_with(var, "mailmap.")) 1787 - return git_default_mailmap_config(var, value); 1788 - 1789 - if (starts_with(var, "attr.")) 1790 - return git_default_attr_config(var, value); 1791 - 1792 - if (starts_with(var, "advice.") || starts_with(var, "color.advice")) 1793 - return git_default_advice_config(var, value); 1794 - 1795 - if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) { 1796 - pager_use_color = git_config_bool(var,value); 1797 - return 0; 1798 - } 1799 - 1800 - if (!strcmp(var, "pack.packsizelimit")) { 1801 - pack_size_limit_cfg = git_config_ulong(var, value, ctx->kvi); 1802 - return 0; 1803 - } 1804 - 1805 - if (!strcmp(var, "pack.compression")) { 1806 - int level = git_config_int(var, value, ctx->kvi); 1807 - if (level == -1) 1808 - level = Z_DEFAULT_COMPRESSION; 1809 - else if (level < 0 || level > Z_BEST_COMPRESSION) 1810 - die(_("bad pack compression level %d"), level); 1811 - pack_compression_level = level; 1812 - pack_compression_seen = 1; 1813 - return 0; 1814 - } 1815 - 1816 - if (starts_with(var, "sparse.")) 1817 - return git_default_sparse_config(var, value); 1818 - 1819 - /* Add other config variables here and to Documentation/config.adoc. */ 1820 1309 return 0; 1821 1310 } 1822 1311
-3
config.h
··· 165 165 typedef int (*config_fn_t)(const char *, const char *, 166 166 const struct config_context *, void *); 167 167 168 - int git_default_config(const char *, const char *, 169 - const struct config_context *, void *); 170 - 171 168 /** 172 169 * Read a specific file in git-config format. 173 170 * This function takes the same callback and data parameters as `repo_config`.
+512
environment.c
··· 12 12 13 13 #include "git-compat-util.h" 14 14 #include "abspath.h" 15 + #include "advice.h" 16 + #include "attr.h" 15 17 #include "branch.h" 18 + #include "color.h" 16 19 #include "convert.h" 17 20 #include "environment.h" 18 21 #include "gettext.h" 19 22 #include "git-zlib.h" 23 + #include "ident.h" 24 + #include "mailmap.h" 25 + #include "object-name.h" 20 26 #include "repository.h" 21 27 #include "config.h" 22 28 #include "refs.h" 23 29 #include "fmt-merge-msg.h" 24 30 #include "commit.h" 25 31 #include "strvec.h" 32 + #include "pager.h" 26 33 #include "path.h" 34 + #include "quote.h" 27 35 #include "chdir-notify.h" 28 36 #include "setup.h" 37 + #include "ws.h" 29 38 #include "write-or-die.h" 39 + 40 + static int pack_compression_seen; 41 + static int zlib_compression_seen; 30 42 31 43 int trust_executable_bit = 1; 32 44 int trust_ctime = 1; ··· 231 243 } 232 244 return cached_result; 233 245 } 246 + 247 + static const struct fsync_component_name { 248 + const char *name; 249 + enum fsync_component component_bits; 250 + } fsync_component_names[] = { 251 + { "loose-object", FSYNC_COMPONENT_LOOSE_OBJECT }, 252 + { "pack", FSYNC_COMPONENT_PACK }, 253 + { "pack-metadata", FSYNC_COMPONENT_PACK_METADATA }, 254 + { "commit-graph", FSYNC_COMPONENT_COMMIT_GRAPH }, 255 + { "index", FSYNC_COMPONENT_INDEX }, 256 + { "objects", FSYNC_COMPONENTS_OBJECTS }, 257 + { "reference", FSYNC_COMPONENT_REFERENCE }, 258 + { "derived-metadata", FSYNC_COMPONENTS_DERIVED_METADATA }, 259 + { "committed", FSYNC_COMPONENTS_COMMITTED }, 260 + { "added", FSYNC_COMPONENTS_ADDED }, 261 + { "all", FSYNC_COMPONENTS_ALL }, 262 + }; 263 + 264 + static enum fsync_component parse_fsync_components(const char *var, const char *string) 265 + { 266 + enum fsync_component current = FSYNC_COMPONENTS_PLATFORM_DEFAULT; 267 + enum fsync_component positive = 0, negative = 0; 268 + 269 + while (string) { 270 + size_t len; 271 + const char *ep; 272 + int negated = 0; 273 + int found = 0; 274 + 275 + string = string + strspn(string, ", \t\n\r"); 276 + ep = strchrnul(string, ','); 277 + len = ep - string; 278 + if (!strcmp(string, "none")) { 279 + current = FSYNC_COMPONENT_NONE; 280 + goto next_name; 281 + } 282 + 283 + if (*string == '-') { 284 + negated = 1; 285 + string++; 286 + len--; 287 + if (!len) 288 + warning(_("invalid value for variable %s"), var); 289 + } 290 + 291 + if (!len) 292 + break; 293 + 294 + for (size_t i = 0; i < ARRAY_SIZE(fsync_component_names); ++i) { 295 + const struct fsync_component_name *n = &fsync_component_names[i]; 296 + 297 + if (strncmp(n->name, string, len)) 298 + continue; 299 + 300 + found = 1; 301 + if (negated) 302 + negative |= n->component_bits; 303 + else 304 + positive |= n->component_bits; 305 + } 306 + 307 + if (!found) { 308 + char *component = xstrndup(string, len); 309 + warning(_("ignoring unknown core.fsync component '%s'"), component); 310 + free(component); 311 + } 312 + 313 + next_name: 314 + string = ep; 315 + } 316 + 317 + return (current & ~negative) | positive; 318 + } 319 + 320 + static int git_default_core_config(const char *var, const char *value, 321 + const struct config_context *ctx, void *cb) 322 + { 323 + /* This needs a better name */ 324 + if (!strcmp(var, "core.filemode")) { 325 + trust_executable_bit = git_config_bool(var, value); 326 + return 0; 327 + } 328 + if (!strcmp(var, "core.trustctime")) { 329 + trust_ctime = git_config_bool(var, value); 330 + return 0; 331 + } 332 + if (!strcmp(var, "core.checkstat")) { 333 + if (!value) 334 + return config_error_nonbool(var); 335 + if (!strcasecmp(value, "default")) 336 + check_stat = 1; 337 + else if (!strcasecmp(value, "minimal")) 338 + check_stat = 0; 339 + else 340 + return error(_("invalid value for '%s': '%s'"), 341 + var, value); 342 + } 343 + 344 + if (!strcmp(var, "core.quotepath")) { 345 + quote_path_fully = git_config_bool(var, value); 346 + return 0; 347 + } 348 + 349 + if (!strcmp(var, "core.symlinks")) { 350 + has_symlinks = git_config_bool(var, value); 351 + return 0; 352 + } 353 + 354 + if (!strcmp(var, "core.ignorecase")) { 355 + ignore_case = git_config_bool(var, value); 356 + return 0; 357 + } 358 + 359 + if (!strcmp(var, "core.attributesfile")) { 360 + FREE_AND_NULL(git_attributes_file); 361 + return git_config_pathname(&git_attributes_file, var, value); 362 + } 363 + 364 + if (!strcmp(var, "core.bare")) { 365 + is_bare_repository_cfg = git_config_bool(var, value); 366 + return 0; 367 + } 368 + 369 + if (!strcmp(var, "core.ignorestat")) { 370 + assume_unchanged = git_config_bool(var, value); 371 + return 0; 372 + } 373 + 374 + if (!strcmp(var, "core.abbrev")) { 375 + if (!value) 376 + return config_error_nonbool(var); 377 + if (!strcasecmp(value, "auto")) 378 + default_abbrev = -1; 379 + else if (!git_parse_maybe_bool_text(value)) 380 + default_abbrev = GIT_MAX_HEXSZ; 381 + else { 382 + int abbrev = git_config_int(var, value, ctx->kvi); 383 + if (abbrev < minimum_abbrev) 384 + return error(_("abbrev length out of range: %d"), abbrev); 385 + default_abbrev = abbrev; 386 + } 387 + return 0; 388 + } 389 + 390 + if (!strcmp(var, "core.disambiguate")) 391 + return set_disambiguate_hint_config(var, value); 392 + 393 + if (!strcmp(var, "core.loosecompression")) { 394 + int level = git_config_int(var, value, ctx->kvi); 395 + if (level == -1) 396 + level = Z_DEFAULT_COMPRESSION; 397 + else if (level < 0 || level > Z_BEST_COMPRESSION) 398 + die(_("bad zlib compression level %d"), level); 399 + zlib_compression_level = level; 400 + zlib_compression_seen = 1; 401 + return 0; 402 + } 403 + 404 + if (!strcmp(var, "core.compression")) { 405 + int level = git_config_int(var, value, ctx->kvi); 406 + if (level == -1) 407 + level = Z_DEFAULT_COMPRESSION; 408 + else if (level < 0 || level > Z_BEST_COMPRESSION) 409 + die(_("bad zlib compression level %d"), level); 410 + if (!zlib_compression_seen) 411 + zlib_compression_level = level; 412 + if (!pack_compression_seen) 413 + pack_compression_level = level; 414 + return 0; 415 + } 416 + 417 + if (!strcmp(var, "core.autocrlf")) { 418 + if (value && !strcasecmp(value, "input")) { 419 + auto_crlf = AUTO_CRLF_INPUT; 420 + return 0; 421 + } 422 + auto_crlf = git_config_bool(var, value); 423 + return 0; 424 + } 425 + 426 + if (!strcmp(var, "core.safecrlf")) { 427 + int eol_rndtrp_die; 428 + if (value && !strcasecmp(value, "warn")) { 429 + global_conv_flags_eol = CONV_EOL_RNDTRP_WARN; 430 + return 0; 431 + } 432 + eol_rndtrp_die = git_config_bool(var, value); 433 + global_conv_flags_eol = eol_rndtrp_die ? 434 + CONV_EOL_RNDTRP_DIE : 0; 435 + return 0; 436 + } 437 + 438 + if (!strcmp(var, "core.eol")) { 439 + if (value && !strcasecmp(value, "lf")) 440 + core_eol = EOL_LF; 441 + else if (value && !strcasecmp(value, "crlf")) 442 + core_eol = EOL_CRLF; 443 + else if (value && !strcasecmp(value, "native")) 444 + core_eol = EOL_NATIVE; 445 + else 446 + core_eol = EOL_UNSET; 447 + return 0; 448 + } 449 + 450 + if (!strcmp(var, "core.checkroundtripencoding")) { 451 + FREE_AND_NULL(check_roundtrip_encoding); 452 + return git_config_string(&check_roundtrip_encoding, var, value); 453 + } 454 + 455 + if (!strcmp(var, "core.editor")) { 456 + FREE_AND_NULL(editor_program); 457 + return git_config_string(&editor_program, var, value); 458 + } 459 + 460 + if (!strcmp(var, "core.commentchar") || 461 + !strcmp(var, "core.commentstring")) { 462 + if (!value) 463 + return config_error_nonbool(var); 464 + else if (!strcasecmp(value, "auto")) 465 + auto_comment_line_char = 1; 466 + else if (value[0]) { 467 + if (strchr(value, '\n')) 468 + return error(_("%s cannot contain newline"), var); 469 + comment_line_str = value; 470 + FREE_AND_NULL(comment_line_str_to_free); 471 + auto_comment_line_char = 0; 472 + } else 473 + return error(_("%s must have at least one character"), var); 474 + return 0; 475 + } 476 + 477 + if (!strcmp(var, "core.askpass")) { 478 + FREE_AND_NULL(askpass_program); 479 + return git_config_string(&askpass_program, var, value); 480 + } 481 + 482 + if (!strcmp(var, "core.excludesfile")) { 483 + FREE_AND_NULL(excludes_file); 484 + return git_config_pathname(&excludes_file, var, value); 485 + } 486 + 487 + if (!strcmp(var, "core.whitespace")) { 488 + if (!value) 489 + return config_error_nonbool(var); 490 + whitespace_rule_cfg = parse_whitespace_rule(value); 491 + return 0; 492 + } 493 + 494 + if (!strcmp(var, "core.fsync")) { 495 + if (!value) 496 + return config_error_nonbool(var); 497 + fsync_components = parse_fsync_components(var, value); 498 + return 0; 499 + } 500 + 501 + if (!strcmp(var, "core.fsyncmethod")) { 502 + if (!value) 503 + return config_error_nonbool(var); 504 + if (!strcmp(value, "fsync")) 505 + fsync_method = FSYNC_METHOD_FSYNC; 506 + else if (!strcmp(value, "writeout-only")) 507 + fsync_method = FSYNC_METHOD_WRITEOUT_ONLY; 508 + else if (!strcmp(value, "batch")) 509 + fsync_method = FSYNC_METHOD_BATCH; 510 + else 511 + warning(_("ignoring unknown core.fsyncMethod value '%s'"), value); 512 + 513 + } 514 + 515 + if (!strcmp(var, "core.fsyncobjectfiles")) { 516 + if (fsync_object_files < 0) 517 + warning(_("core.fsyncObjectFiles is deprecated; use core.fsync instead")); 518 + fsync_object_files = git_config_bool(var, value); 519 + return 0; 520 + } 521 + 522 + if (!strcmp(var, "core.createobject")) { 523 + if (!value) 524 + return config_error_nonbool(var); 525 + if (!strcmp(value, "rename")) 526 + object_creation_mode = OBJECT_CREATION_USES_RENAMES; 527 + else if (!strcmp(value, "link")) 528 + object_creation_mode = OBJECT_CREATION_USES_HARDLINKS; 529 + else 530 + die(_("invalid mode for object creation: %s"), value); 531 + return 0; 532 + } 533 + 534 + if (!strcmp(var, "core.sparsecheckout")) { 535 + core_apply_sparse_checkout = git_config_bool(var, value); 536 + return 0; 537 + } 538 + 539 + if (!strcmp(var, "core.sparsecheckoutcone")) { 540 + core_sparse_checkout_cone = git_config_bool(var, value); 541 + return 0; 542 + } 543 + 544 + if (!strcmp(var, "core.precomposeunicode")) { 545 + precomposed_unicode = git_config_bool(var, value); 546 + return 0; 547 + } 548 + 549 + if (!strcmp(var, "core.protecthfs")) { 550 + protect_hfs = git_config_bool(var, value); 551 + return 0; 552 + } 553 + 554 + if (!strcmp(var, "core.protectntfs")) { 555 + protect_ntfs = git_config_bool(var, value); 556 + return 0; 557 + } 558 + 559 + if (!strcmp(var, "core.maxtreedepth")) { 560 + max_allowed_tree_depth = git_config_int(var, value, ctx->kvi); 561 + return 0; 562 + } 563 + 564 + /* Add other config variables here and to Documentation/config.adoc. */ 565 + return platform_core_config(var, value, ctx, cb); 566 + } 567 + 568 + static int git_default_sparse_config(const char *var, const char *value) 569 + { 570 + if (!strcmp(var, "sparse.expectfilesoutsideofpatterns")) { 571 + sparse_expect_files_outside_of_patterns = git_config_bool(var, value); 572 + return 0; 573 + } 574 + 575 + /* Add other config variables here and to Documentation/config/sparse.adoc. */ 576 + return 0; 577 + } 578 + 579 + static int git_default_i18n_config(const char *var, const char *value) 580 + { 581 + if (!strcmp(var, "i18n.commitencoding")) { 582 + FREE_AND_NULL(git_commit_encoding); 583 + return git_config_string(&git_commit_encoding, var, value); 584 + } 585 + 586 + if (!strcmp(var, "i18n.logoutputencoding")) { 587 + FREE_AND_NULL(git_log_output_encoding); 588 + return git_config_string(&git_log_output_encoding, var, value); 589 + } 590 + 591 + /* Add other config variables here and to Documentation/config.adoc. */ 592 + return 0; 593 + } 594 + 595 + static int git_default_branch_config(const char *var, const char *value) 596 + { 597 + if (!strcmp(var, "branch.autosetupmerge")) { 598 + if (value && !strcmp(value, "always")) { 599 + git_branch_track = BRANCH_TRACK_ALWAYS; 600 + return 0; 601 + } else if (value && !strcmp(value, "inherit")) { 602 + git_branch_track = BRANCH_TRACK_INHERIT; 603 + return 0; 604 + } else if (value && !strcmp(value, "simple")) { 605 + git_branch_track = BRANCH_TRACK_SIMPLE; 606 + return 0; 607 + } 608 + git_branch_track = git_config_bool(var, value); 609 + return 0; 610 + } 611 + if (!strcmp(var, "branch.autosetuprebase")) { 612 + if (!value) 613 + return config_error_nonbool(var); 614 + else if (!strcmp(value, "never")) 615 + autorebase = AUTOREBASE_NEVER; 616 + else if (!strcmp(value, "local")) 617 + autorebase = AUTOREBASE_LOCAL; 618 + else if (!strcmp(value, "remote")) 619 + autorebase = AUTOREBASE_REMOTE; 620 + else if (!strcmp(value, "always")) 621 + autorebase = AUTOREBASE_ALWAYS; 622 + else 623 + return error(_("malformed value for %s"), var); 624 + return 0; 625 + } 626 + 627 + /* Add other config variables here and to Documentation/config.adoc. */ 628 + return 0; 629 + } 630 + 631 + static int git_default_push_config(const char *var, const char *value) 632 + { 633 + if (!strcmp(var, "push.default")) { 634 + if (!value) 635 + return config_error_nonbool(var); 636 + else if (!strcmp(value, "nothing")) 637 + push_default = PUSH_DEFAULT_NOTHING; 638 + else if (!strcmp(value, "matching")) 639 + push_default = PUSH_DEFAULT_MATCHING; 640 + else if (!strcmp(value, "simple")) 641 + push_default = PUSH_DEFAULT_SIMPLE; 642 + else if (!strcmp(value, "upstream")) 643 + push_default = PUSH_DEFAULT_UPSTREAM; 644 + else if (!strcmp(value, "tracking")) /* deprecated */ 645 + push_default = PUSH_DEFAULT_UPSTREAM; 646 + else if (!strcmp(value, "current")) 647 + push_default = PUSH_DEFAULT_CURRENT; 648 + else { 649 + error(_("malformed value for %s: %s"), var, value); 650 + return error(_("must be one of nothing, matching, simple, " 651 + "upstream or current")); 652 + } 653 + return 0; 654 + } 655 + 656 + /* Add other config variables here and to Documentation/config.adoc. */ 657 + return 0; 658 + } 659 + 660 + static int git_default_mailmap_config(const char *var, const char *value) 661 + { 662 + if (!strcmp(var, "mailmap.file")) { 663 + FREE_AND_NULL(git_mailmap_file); 664 + return git_config_pathname(&git_mailmap_file, var, value); 665 + } 666 + 667 + if (!strcmp(var, "mailmap.blob")) { 668 + FREE_AND_NULL(git_mailmap_blob); 669 + return git_config_string(&git_mailmap_blob, var, value); 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 + if (starts_with(var, "core.")) 694 + return git_default_core_config(var, value, ctx, cb); 695 + 696 + if (starts_with(var, "user.") || 697 + starts_with(var, "author.") || 698 + starts_with(var, "committer.")) 699 + return git_ident_config(var, value, ctx, cb); 700 + 701 + if (starts_with(var, "i18n.")) 702 + return git_default_i18n_config(var, value); 703 + 704 + if (starts_with(var, "branch.")) 705 + return git_default_branch_config(var, value); 706 + 707 + if (starts_with(var, "push.")) 708 + return git_default_push_config(var, value); 709 + 710 + if (starts_with(var, "mailmap.")) 711 + return git_default_mailmap_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 + 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 + }
+3
environment.h
··· 104 104 const char *get_git_namespace(void); 105 105 const char *strip_namespace(const char *namespaced_ref); 106 106 107 + int git_default_config(const char *, const char *, 108 + const struct config_context *, void *); 109 + 107 110 /* 108 111 * TODO: All the below state either explicitly or implicitly relies on 109 112 * `the_repository`. We should eventually get rid of these and make the
+1
fsck.c
··· 3 3 #include "git-compat-util.h" 4 4 #include "date.h" 5 5 #include "dir.h" 6 + #include "environment.h" 6 7 #include "hex.h" 7 8 #include "odb.h" 8 9 #include "path.h"
+1
http-fetch.c
··· 2 2 3 3 #include "git-compat-util.h" 4 4 #include "config.h" 5 + #include "environment.h" 5 6 #include "gettext.h" 6 7 #include "hex.h" 7 8 #include "http.h"
+1
http.c
··· 3 3 4 4 #include "git-compat-util.h" 5 5 #include "git-curl-compat.h" 6 + #include "environment.h" 6 7 #include "hex.h" 7 8 #include "http.h" 8 9 #include "config.h"
+1
imap-send.c
··· 28 28 #include "advice.h" 29 29 #include "config.h" 30 30 #include "credential.h" 31 + #include "environment.h" 31 32 #include "gettext.h" 32 33 #include "run-command.h" 33 34 #include "parse-options.h"
+1
mailinfo.c
··· 2 2 3 3 #include "git-compat-util.h" 4 4 #include "config.h" 5 + #include "environment.h" 5 6 #include "gettext.h" 6 7 #include "hex-ll.h" 7 8 #include "utf8.h"
+1
reflog.c
··· 3 3 4 4 #include "git-compat-util.h" 5 5 #include "config.h" 6 + #include "environment.h" 6 7 #include "gettext.h" 7 8 #include "parse-options.h" 8 9 #include "odb.h"
+1
rerere.c
··· 5 5 #include "abspath.h" 6 6 #include "config.h" 7 7 #include "copy.h" 8 + #include "environment.h" 8 9 #include "gettext.h" 9 10 #include "hex.h" 10 11 #include "lockfile.h"
+1
t/helper/test-advise.c
··· 3 3 #include "test-tool.h" 4 4 #include "advice.h" 5 5 #include "config.h" 6 + #include "environment.h" 6 7 #include "setup.h" 7 8 8 9 int cmd__advise_if_enabled(int argc, const char **argv)
+1
t/helper/test-read-cache.c
··· 2 2 3 3 #include "test-tool.h" 4 4 #include "config.h" 5 + #include "environment.h" 5 6 #include "read-cache-ll.h" 6 7 #include "repository.h" 7 8 #include "setup.h"
+1
xdiff-interface.c
··· 2 2 #define DISABLE_SIGN_COMPARE_WARNINGS 3 3 4 4 #include "git-compat-util.h" 5 + #include "environment.h" 5 6 #include "gettext.h" 6 7 #include "config.h" 7 8 #include "hex.h"