73
*
74
* The "source" variable will be non-NULL only when we are actually
75
* parsing a real config source (file, blob, cmdline, etc).
76
- *
77
- * The "config_kvi" variable will be non-NULL only when we are feeding
78
- * cached config from a configset into a callback.
79
- *
80
- * They cannot be non-NULL at the same time. If they are both NULL, then
81
- * we aren't parsing anything (and depending on the function looking at
82
- * the variables, it's either a bug for it to be called in the first
83
- * place, or it's a function which can be reused for non-config
84
- * purposes, and should fall back to some sane behavior).
76
*/
77
struct config_source *source;
87
- struct key_value_info *config_kvi;
78
};
79
/*
80
* Where possible, prefer to accept "struct config_reader" as an arg than to use
86
static inline void config_reader_push_source(struct config_reader *reader,
87
struct config_source *top)
88
{
99
- if (reader->config_kvi)
100
- BUG("source should not be set while iterating a config set");
89
top->prev = reader->source;
90
reader->source = top;
91
}
100
return ret;
101
}
102
115
-static inline void config_reader_set_kvi(struct config_reader *reader,
116
- struct key_value_info *kvi)
117
-{
118
- reader->config_kvi = kvi;
119
-}
120
-
103
static int pack_compression_seen;
104
static int zlib_compression_seen;
105
1328
return 1;
1329
}
1330
1349
-static int reader_config_name(struct config_reader *reader, const char **out);
1350
-static int reader_origin_type(struct config_reader *reader,
1351
- enum config_origin_type *type);
1331
NORETURN
1353
-static void die_bad_number(struct config_reader *reader, const char *name,
1354
- const char *value)
1332
+static void die_bad_number(const char *name, const char *value,
1333
+ const struct key_value_info *kvi)
1334
{
1335
const char *error_type = (errno == ERANGE) ?
1336
N_("out of range") : N_("invalid unit");
1337
const char *bad_numeric = N_("bad numeric config value '%s' for '%s': %s");
1359
- const char *config_name = NULL;
1360
- enum config_origin_type config_origin = CONFIG_ORIGIN_UNKNOWN;
1338
+
1339
+ if (!kvi)
1340
+ BUG("kvi should not be NULL");
1341
1342
if (!value)
1343
value = "";
1344
1365
- /* Ignoring the return value is okay since we handle missing values. */
1366
- reader_config_name(reader, &config_name);
1367
- reader_origin_type(reader, &config_origin);
1368
-
1369
- if (!config_name)
1345
+ if (!kvi->filename)
1346
die(_(bad_numeric), value, name, _(error_type));
1347
1372
- switch (config_origin) {
1348
+ switch (kvi->origin_type) {
1349
case CONFIG_ORIGIN_BLOB:
1350
die(_("bad numeric config value '%s' for '%s' in blob %s: %s"),
1375
- value, name, config_name, _(error_type));
1351
+ value, name, kvi->filename, _(error_type));
1352
case CONFIG_ORIGIN_FILE:
1353
die(_("bad numeric config value '%s' for '%s' in file %s: %s"),
1378
- value, name, config_name, _(error_type));
1354
+ value, name, kvi->filename, _(error_type));
1355
case CONFIG_ORIGIN_STDIN:
1356
die(_("bad numeric config value '%s' for '%s' in standard input: %s"),
1357
value, name, _(error_type));
1358
case CONFIG_ORIGIN_SUBMODULE_BLOB:
1359
die(_("bad numeric config value '%s' for '%s' in submodule-blob %s: %s"),
1384
- value, name, config_name, _(error_type));
1360
+ value, name, kvi->filename, _(error_type));
1361
case CONFIG_ORIGIN_CMDLINE:
1362
die(_("bad numeric config value '%s' for '%s' in command line %s: %s"),
1387
- value, name, config_name, _(error_type));
1363
+ value, name, kvi->filename, _(error_type));
1364
default:
1365
die(_("bad numeric config value '%s' for '%s' in %s: %s"),
1390
- value, name, config_name, _(error_type));
1366
+ value, name, kvi->filename, _(error_type));
1367
}
1368
}
1369
1394
-int git_config_int(const char *name, const char *value)
1370
+int git_config_int(const char *name, const char *value,
1371
+ const struct key_value_info *kvi)
1372
{
1373
int ret;
1374
if (!git_parse_int(value, &ret))
1398
- die_bad_number(&the_reader, name, value);
1375
+ die_bad_number(name, value, kvi);
1376
return ret;
1377
}
1378
1402
-int64_t git_config_int64(const char *name, const char *value)
1379
+int64_t git_config_int64(const char *name, const char *value,
1380
+ const struct key_value_info *kvi)
1381
{
1382
int64_t ret;
1383
if (!git_parse_int64(value, &ret))
1406
- die_bad_number(&the_reader, name, value);
1384
+ die_bad_number(name, value, kvi);
1385
return ret;
1386
}
1387
1410
-unsigned long git_config_ulong(const char *name, const char *value)
1388
+unsigned long git_config_ulong(const char *name, const char *value,
1389
+ const struct key_value_info *kvi)
1390
{
1391
unsigned long ret;
1392
if (!git_parse_ulong(value, &ret))
1414
- die_bad_number(&the_reader, name, value);
1393
+ die_bad_number(name, value, kvi);
1394
return ret;
1395
}
1396
1418
-ssize_t git_config_ssize_t(const char *name, const char *value)
1397
+ssize_t git_config_ssize_t(const char *name, const char *value,
1398
+ const struct key_value_info *kvi)
1399
{
1400
ssize_t ret;
1401
if (!git_parse_ssize_t(value, &ret))
1422
- die_bad_number(&the_reader, name, value);
1402
+ die_bad_number(name, value, kvi);
1403
return ret;
1404
}
1405
1504
return -1;
1505
}
1506
1527
-int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
1507
+int git_config_bool_or_int(const char *name, const char *value,
1508
+ const struct key_value_info *kvi, int *is_bool)
1509
{
1510
int v = git_parse_maybe_bool_text(value);
1511
if (0 <= v) {
1513
return v;
1514
}
1515
*is_bool = 0;
1535
- return git_config_int(name, value);
1516
+ return git_config_int(name, value, kvi);
1517
}
1518
1519
int git_config_bool(const char *name, const char *value)
1639
else if (!git_parse_maybe_bool_text(value))
1640
default_abbrev = the_hash_algo->hexsz;
1641
else {
1661
- int abbrev = git_config_int(var, value);
1642
+ int abbrev = git_config_int(var, value, ctx->kvi);
1643
if (abbrev < minimum_abbrev || abbrev > the_hash_algo->hexsz)
1644
return error(_("abbrev length out of range: %d"), abbrev);
1645
default_abbrev = abbrev;
1651
return set_disambiguate_hint_config(var, value);
1652
1653
if (!strcmp(var, "core.loosecompression")) {
1673
- int level = git_config_int(var, value);
1654
+ int level = git_config_int(var, value, ctx->kvi);
1655
if (level == -1)
1656
level = Z_DEFAULT_COMPRESSION;
1657
else if (level < 0 || level > Z_BEST_COMPRESSION)
1662
}
1663
1664
if (!strcmp(var, "core.compression")) {
1684
- int level = git_config_int(var, value);
1665
+ int level = git_config_int(var, value, ctx->kvi);
1666
if (level == -1)
1667
level = Z_DEFAULT_COMPRESSION;
1668
else if (level < 0 || level > Z_BEST_COMPRESSION)
1676
1677
if (!strcmp(var, "core.packedgitwindowsize")) {
1678
int pgsz_x2 = getpagesize() * 2;
1698
- packed_git_window_size = git_config_ulong(var, value);
1679
+ packed_git_window_size = git_config_ulong(var, value, ctx->kvi);
1680
1681
/* This value must be multiple of (pagesize * 2) */
1682
packed_git_window_size /= pgsz_x2;
1687
}
1688
1689
if (!strcmp(var, "core.bigfilethreshold")) {
1709
- big_file_threshold = git_config_ulong(var, value);
1690
+ big_file_threshold = git_config_ulong(var, value, ctx->kvi);
1691
return 0;
1692
}
1693
1694
if (!strcmp(var, "core.packedgitlimit")) {
1714
- packed_git_limit = git_config_ulong(var, value);
1695
+ packed_git_limit = git_config_ulong(var, value, ctx->kvi);
1696
return 0;
1697
}
1698
1699
if (!strcmp(var, "core.deltabasecachelimit")) {
1719
- delta_base_cache_limit = git_config_ulong(var, value);
1700
+ delta_base_cache_limit = git_config_ulong(var, value, ctx->kvi);
1701
return 0;
1702
}
1703
1976
}
1977
1978
if (!strcmp(var, "pack.packsizelimit")) {
1998
- pack_size_limit_cfg = git_config_ulong(var, value);
1979
+ pack_size_limit_cfg = git_config_ulong(var, value, ctx->kvi);
1980
return 0;
1981
}
1982
1983
if (!strcmp(var, "pack.compression")) {
2003
- int level = git_config_int(var, value);
1984
+ int level = git_config_int(var, value, ctx->kvi);
1985
if (level == -1)
1986
level = Z_DEFAULT_COMPRESSION;
1987
else if (level < 0 || level > Z_BEST_COMPRESSION)
2325
value_index = list->items[i].value_index;
2326
values = &entry->value_list;
2327
2347
- config_reader_set_kvi(reader, values->items[value_index].util);
2328
ctx.kvi = values->items[value_index].util;
2329
if (fn(entry->key, values->items[value_index].string, &ctx, data) < 0)
2330
git_die_config_linenr(entry->key,
2331
ctx.kvi->filename,
2332
ctx.kvi->linenr);
2353
- config_reader_set_kvi(reader, NULL);
2333
}
2334
}
2335
2515
return git_config_from_file(config_set_callback, filename, &data);
2516
}
2517
2539
-int git_configset_get_value(struct config_set *set, const char *key, const char **value)
2518
+int git_configset_get_value(struct config_set *set, const char *key,
2519
+ const char **value, struct key_value_info *kvi)
2520
{
2521
const struct string_list *values = NULL;
2522
int ret;
2543
-
2523
+ struct string_list_item item;
2524
/*
2525
* Follows "last one wins" semantic, i.e., if there are multiple matches for the
2526
* queried key in the files of the configset, the value returned will be the last
2530
return ret;
2531
2532
assert(values->nr > 0);
2553
- *value = values->items[values->nr - 1].string;
2533
+ item = values->items[values->nr - 1];
2534
+ *value = item.string;
2535
+ if (kvi)
2536
+ *kvi = *((struct key_value_info *)item.util);
2537
return 0;
2538
}
2539
2586
int git_configset_get_string(struct config_set *set, const char *key, char **dest)
2587
{
2588
const char *value;
2606
- if (!git_configset_get_value(set, key, &value))
2589
+ if (!git_configset_get_value(set, key, &value, NULL))
2590
return git_config_string((const char **)dest, key, value);
2591
else
2592
return 1;
2596
const char **dest)
2597
{
2598
const char *value;
2616
- if (!git_configset_get_value(set, key, &value)) {
2599
+ if (!git_configset_get_value(set, key, &value, NULL)) {
2600
if (!value)
2601
return config_error_nonbool(key);
2602
*dest = value;
2609
int git_configset_get_int(struct config_set *set, const char *key, int *dest)
2610
{
2611
const char *value;
2629
- if (!git_configset_get_value(set, key, &value)) {
2630
- *dest = git_config_int(key, value);
2612
+ struct key_value_info kvi;
2613
+
2614
+ if (!git_configset_get_value(set, key, &value, &kvi)) {
2615
+ *dest = git_config_int(key, value, &kvi);
2616
return 0;
2617
} else
2618
return 1;
2621
int git_configset_get_ulong(struct config_set *set, const char *key, unsigned long *dest)
2622
{
2623
const char *value;
2639
- if (!git_configset_get_value(set, key, &value)) {
2640
- *dest = git_config_ulong(key, value);
2624
+ struct key_value_info kvi;
2625
+
2626
+ if (!git_configset_get_value(set, key, &value, &kvi)) {
2627
+ *dest = git_config_ulong(key, value, &kvi);
2628
return 0;
2629
} else
2630
return 1;
2633
int git_configset_get_bool(struct config_set *set, const char *key, int *dest)
2634
{
2635
const char *value;
2649
- if (!git_configset_get_value(set, key, &value)) {
2636
+ if (!git_configset_get_value(set, key, &value, NULL)) {
2637
*dest = git_config_bool(key, value);
2638
return 0;
2639
} else
2644
int *is_bool, int *dest)
2645
{
2646
const char *value;
2660
- if (!git_configset_get_value(set, key, &value)) {
2661
- *dest = git_config_bool_or_int(key, value, is_bool);
2647
+ struct key_value_info kvi;
2648
+
2649
+ if (!git_configset_get_value(set, key, &value, &kvi)) {
2650
+ *dest = git_config_bool_or_int(key, value, &kvi, is_bool);
2651
return 0;
2652
} else
2653
return 1;
2656
int git_configset_get_maybe_bool(struct config_set *set, const char *key, int *dest)
2657
{
2658
const char *value;
2670
- if (!git_configset_get_value(set, key, &value)) {
2659
+ if (!git_configset_get_value(set, key, &value, NULL)) {
2660
*dest = git_parse_maybe_bool(value);
2661
if (*dest == -1)
2662
return -1;
2668
int git_configset_get_pathname(struct config_set *set, const char *key, const char **dest)
2669
{
2670
const char *value;
2682
- if (!git_configset_get_value(set, key, &value))
2671
+ if (!git_configset_get_value(set, key, &value, NULL))
2672
return git_config_pathname(dest, key, value);
2673
else
2674
return 1;
2738
const char *key, const char **value)
2739
{
2740
git_config_check_init(repo);
2752
- return git_configset_get_value(repo->config, key, value);
2741
+ return git_configset_get_value(repo->config, key, value, NULL);
2742
}
2743
2744
int repo_config_get_value_multi(struct repository *repo, const char *key,
3978
return 0;
3979
}
3980
3992
-static int reader_origin_type(struct config_reader *reader,
3993
- enum config_origin_type *type)
3994
-{
3995
- if (the_reader.config_kvi)
3996
- *type = reader->config_kvi->origin_type;
3997
- else if(the_reader.source)
3998
- *type = reader->source->origin_type;
3999
- else
4000
- return 1;
4001
- return 0;
4002
-}
4003
-
3981
const char *config_origin_type_name(enum config_origin_type type)
3982
{
3983
switch (type) {
4016
}
4017
}
4018
4042
-static int reader_config_name(struct config_reader *reader, const char **out)
4043
-{
4044
- if (the_reader.config_kvi)
4045
- *out = reader->config_kvi->filename;
4046
- else if (the_reader.source)
4047
- *out = reader->source->name;
4048
- else
4049
- return 1;
4050
- return 0;
4051
-}
4052
-
4019
int lookup_config(const char **mapping, int nr_mapping, const char *var)
4020
{
4021
int i;