1311
return 1;
1312
}
1313
1314
+static int reader_config_name(struct config_reader *reader, const char **out);
1315
+static int reader_origin_type(struct config_reader *reader,
1316
+ enum config_origin_type *type);
1317
NORETURN
1315
-static void die_bad_number(struct config_source *cf, const char *name,
1318
+static void die_bad_number(struct config_reader *reader, const char *name,
1319
const char *value)
1320
{
1321
const char *error_type = (errno == ERANGE) ?
1322
N_("out of range") : N_("invalid unit");
1323
const char *bad_numeric = N_("bad numeric config value '%s' for '%s': %s");
1324
+ const char *config_name = NULL;
1325
+ enum config_origin_type config_origin = CONFIG_ORIGIN_UNKNOWN;
1326
1327
if (!value)
1328
value = "";
1329
1325
- if (!(cf && cf->name))
1330
+ /* Ignoring the return value is okay since we handle missing values. */
1331
+ reader_config_name(reader, &config_name);
1332
+ reader_origin_type(reader, &config_origin);
1333
+
1334
+ if (!config_name)
1335
die(_(bad_numeric), value, name, _(error_type));
1336
1328
- switch (cf->origin_type) {
1337
+ switch (config_origin) {
1338
case CONFIG_ORIGIN_BLOB:
1339
die(_("bad numeric config value '%s' for '%s' in blob %s: %s"),
1331
- value, name, cf->name, _(error_type));
1340
+ value, name, config_name, _(error_type));
1341
case CONFIG_ORIGIN_FILE:
1342
die(_("bad numeric config value '%s' for '%s' in file %s: %s"),
1334
- value, name, cf->name, _(error_type));
1343
+ value, name, config_name, _(error_type));
1344
case CONFIG_ORIGIN_STDIN:
1345
die(_("bad numeric config value '%s' for '%s' in standard input: %s"),
1346
value, name, _(error_type));
1347
case CONFIG_ORIGIN_SUBMODULE_BLOB:
1348
die(_("bad numeric config value '%s' for '%s' in submodule-blob %s: %s"),
1340
- value, name, cf->name, _(error_type));
1349
+ value, name, config_name, _(error_type));
1350
case CONFIG_ORIGIN_CMDLINE:
1351
die(_("bad numeric config value '%s' for '%s' in command line %s: %s"),
1343
- value, name, cf->name, _(error_type));
1352
+ value, name, config_name, _(error_type));
1353
default:
1354
die(_("bad numeric config value '%s' for '%s' in %s: %s"),
1346
- value, name, cf->name, _(error_type));
1355
+ value, name, config_name, _(error_type));
1356
}
1357
}
1358
1360
{
1361
int ret;
1362
if (!git_parse_int(value, &ret))
1354
- die_bad_number(the_reader.source, name, value);
1363
+ die_bad_number(&the_reader, name, value);
1364
return ret;
1365
}
1366
1368
{
1369
int64_t ret;
1370
if (!git_parse_int64(value, &ret))
1362
- die_bad_number(the_reader.source, name, value);
1371
+ die_bad_number(&the_reader, name, value);
1372
return ret;
1373
}
1374
1376
{
1377
unsigned long ret;
1378
if (!git_parse_ulong(value, &ret))
1370
- die_bad_number(the_reader.source, name, value);
1379
+ die_bad_number(&the_reader, name, value);
1380
return ret;
1381
}
1382
1384
{
1385
ssize_t ret;
1386
if (!git_parse_ssize_t(value, &ret))
1378
- die_bad_number(the_reader.source, name, value);
1387
+ die_bad_number(&the_reader, name, value);
1388
return ret;
1389
}
1390
3848
return 0;
3849
}
3850
3842
-const char *current_config_origin_type(void)
3851
+static int reader_origin_type(struct config_reader *reader,
3852
+ enum config_origin_type *type)
3853
{
3844
- int type;
3854
if (the_reader.config_kvi)
3846
- type = the_reader.config_kvi->origin_type;
3855
+ *type = reader->config_kvi->origin_type;
3856
else if(the_reader.source)
3848
- type = the_reader.source->origin_type;
3857
+ *type = reader->source->origin_type;
3858
else
3859
+ return 1;
3860
+ return 0;
3861
+}
3862
+
3863
+const char *current_config_origin_type(void)
3864
+{
3865
+ enum config_origin_type type = CONFIG_ORIGIN_UNKNOWN;
3866
+
3867
+ if (reader_origin_type(&the_reader, &type))
3868
BUG("current_config_origin_type called outside config callback");
3869
3870
switch (type) {
3903
}
3904
}
3905
3888
-const char *current_config_name(void)
3906
+static int reader_config_name(struct config_reader *reader, const char **out)
3907
{
3890
- const char *name;
3908
if (the_reader.config_kvi)
3892
- name = the_reader.config_kvi->filename;
3909
+ *out = reader->config_kvi->filename;
3910
else if (the_reader.source)
3894
- name = the_reader.source->name;
3911
+ *out = reader->source->name;
3912
else
3913
+ return 1;
3914
+ return 0;
3915
+}
3916
+
3917
+const char *current_config_name(void)
3918
+{
3919
+ const char *name;
3920
+ if (reader_config_name(&the_reader, &name))
3921
BUG("current_config_name called outside config callback");
3922
return name ? name : "";
3923
}