add line number and file name info to `config_set`
Store file name and line number for each key-value pair in the cache during parsing of the configuration files. Signed-off-by: Tanay Abhra <tanayabh@gmail.com> Reviewed-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Tanay Abhra committed
Aug 7, 2014 at 04:59 UTC
3df8fd625fba33a6525f61c85de39afb746db9bd
2 files changed
+19
-2
cache.h
+5
@@ -1383,6 +1383,11 @@ extern int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest);
1383
extern int git_config_get_maybe_bool(const char *key, int *dest);
1384
extern int git_config_get_pathname(const char *key, const char **dest);
1385
1386
+struct key_value_info {
1387
+ const char *filename;
1388
+ int linenr;
1389
+};
1390
+
1391
extern int committer_ident_sufficiently_given(void);
1392
extern int author_ident_sufficiently_given(void);
1393
config.c
+14
-2
@@ -1262,6 +1262,9 @@ static struct config_set_element *configset_find_element(struct config_set *cs,
1262
static int configset_add_value(struct config_set *cs, const char *key, const char *value)
1263
{
1264
struct config_set_element *e;
1265
+ struct string_list_item *si;
1266
+ struct key_value_info *kv_info = xmalloc(sizeof(*kv_info));
1267
+
1268
e = configset_find_element(cs, key);
1269
/*
1270
* Since the keys are being fed by git_config*() callback mechanism, they
@@ -1274,7 +1277,16 @@ static int configset_add_value(struct config_set *cs, const char *key, const cha
1277
string_list_init(&e->value_list, 1);
1278
hashmap_add(&cs->config_hash, e);
1279
}
1277
- string_list_append_nodup(&e->value_list, value ? xstrdup(value) : NULL);
1280
+ si = string_list_append_nodup(&e->value_list, value ? xstrdup(value) : NULL);
1281
+ if (cf) {
1282
+ kv_info->filename = strintern(cf->name);
1283
+ kv_info->linenr = cf->linenr;
1284
+ } else {
1285
+ /* for values read from `git_config_from_parameters()` */
1286
+ kv_info->filename = NULL;
1287
+ kv_info->linenr = -1;
1288
+ }
1289
+ si->util = kv_info;
1290
1291
return 0;
1292
}
@@ -1301,7 +1313,7 @@ void git_configset_clear(struct config_set *cs)
1313
hashmap_iter_init(&cs->config_hash, &iter);
1314
while ((entry = hashmap_iter_next(&iter))) {
1315
free(entry->key);
1304
- string_list_clear(&entry->value_list, 0);
1316
+ string_list_clear(&entry->value_list, 1);
1317
}
1318
hashmap_free(&cs->config_hash, 1);
1319
cs->hash_initialized = 0;