6
*
7
*/
8
9
-#define USE_THE_REPOSITORY_VARIABLE
9
#define DISABLE_SIGN_COMPARE_WARNINGS
10
11
#include "git-compat-util.h"
12
#include "abspath.h"
14
-#include "advice.h"
13
#include "date.h"
14
#include "branch.h"
15
#include "config.h"
18
#include "environment.h"
19
#include "gettext.h"
20
#include "git-zlib.h"
23
-#include "ident.h"
21
#include "repository.h"
22
#include "lockfile.h"
26
-#include "mailmap.h"
27
-#include "attr.h"
23
#include "exec-cmd.h"
24
#include "strbuf.h"
25
#include "quote.h"
27
#include "string-list.h"
28
#include "object-name.h"
29
#include "odb.h"
35
-#include "pager.h"
30
#include "path.h"
31
#include "utf8.h"
32
#include "color.h"
35
#include "strvec.h"
36
#include "trace2.h"
37
#include "wildmatch.h"
44
-#include "ws.h"
38
#include "write-or-die.h"
39
40
struct config_source {
64
};
65
#define CONFIG_SOURCE_INIT { 0 }
66
74
-static int pack_compression_seen;
75
-static int zlib_compression_seen;
76
-
67
/*
68
* Config that comes from trusted scopes, namely:
69
* - CONFIG_SCOPE_SYSTEM (e.g. /etc/gitconfig)
1252
return ret;
1253
}
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
-
1255
int git_config_bool_or_int(const char *name, const char *value,
1256
const struct key_value_info *kvi, int *is_bool)
1257
{
1309
return 0;
1310
}
1311
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
- return 0;
1821
-}
1822
-
1312
/*
1313
* All source specific fields in the union, die_on_error, name and the callbacks
1314
* fgetc, ungetc, ftell of top need to be initialized before calling