38
long (*do_ftell)(struct config_source *c);
39
};
40
41
+/*
42
+ * These variables record the "current" config source, which
43
+ * can be accessed by parsing callbacks.
44
+ *
45
+ * The "cf" variable will be non-NULL only when we are actually parsing a real
46
+ * config source (file, blob, cmdline, etc).
47
+ *
48
+ * The "current_config_kvi" variable will be non-NULL only when we are feeding
49
+ * cached config from a configset into a callback.
50
+ *
51
+ * They should generally never be non-NULL at the same time. If they are both
52
+ * NULL, then we aren't parsing anything (and depending on the function looking
53
+ * at the variables, it's either a bug for it to be called in the first place,
54
+ * or it's a function which can be reused for non-config purposes, and should
55
+ * fall back to some sane behavior).
56
+ */
57
static struct config_source *cf;
58
+static struct key_value_info *current_config_kvi;
59
60
static int zlib_compression_seen;
61
1301
struct string_list *values;
1302
struct config_set_element *entry;
1303
struct configset_list *list = &cs->list;
1287
- struct key_value_info *kv_info;
1304
1305
for (i = 0; i < list->nr; i++) {
1306
entry = list->items[i].e;
1307
value_index = list->items[i].value_index;
1308
values = &entry->value_list;
1293
- if (fn(entry->key, values->items[value_index].string, data) < 0) {
1294
- kv_info = values->items[value_index].util;
1295
- git_die_config_linenr(entry->key, kv_info->filename, kv_info->linenr);
1296
- }
1309
+
1310
+ current_config_kvi = values->items[value_index].util;
1311
+
1312
+ if (fn(entry->key, values->items[value_index].string, data) < 0)
1313
+ git_die_config_linenr(entry->key,
1314
+ current_config_kvi->filename,
1315
+ current_config_kvi->linenr);
1316
+
1317
+ current_config_kvi = NULL;
1318
}
1319
}
1320
1376
if (cf->name) {
1377
kv_info->filename = strintern(cf->name);
1378
kv_info->linenr = cf->linenr;
1379
+ kv_info->origin_type = strintern(cf->origin_type);
1380
} else {
1381
/* for values read from `git_config_from_parameters()` */
1382
kv_info->filename = NULL;
1383
kv_info->linenr = -1;
1384
+ kv_info->origin_type = NULL;
1385
}
1386
si->util = kv_info;
1387
2461
2462
const char *current_config_origin_type(void)
2463
{
2441
- if (!cf)
2464
+ const char *type;
2465
+ if (current_config_kvi)
2466
+ type = current_config_kvi->origin_type;
2467
+ else if(cf)
2468
+ type = cf->origin_type;
2469
+ else
2470
die("BUG: current_config_origin_type called outside config callback");
2443
- return cf->origin_type ? cf->origin_type : "command line";
2471
+ return type ? type : "command line";
2472
}
2473
2474
const char *current_config_name(void)
2475
{
2448
- if (!cf)
2476
+ const char *name;
2477
+ if (current_config_kvi)
2478
+ name = current_config_kvi->filename;
2479
+ else if (cf)
2480
+ name = cf->name;
2481
+ else
2482
die("BUG: current_config_name called outside config callback");
2450
- return cf->name ? cf->name : "";
2483
+ return name ? name : "";
2484
}