Store file name and line number for each key-value pair in the cache. Use the information to print line number and file name in errors raised by `git_config()` which now uses the configuration files caching layer internally. Signed-off-by: Tanay Abhra <tanayabh@xxxxxxxxx> --- config.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/config.c b/config.c index a7fb9a4..43a951f 100644 --- a/config.c +++ b/config.c @@ -1237,9 +1237,15 @@ static int git_config_raw(config_fn_t fn, void *data) return git_config_with_options(fn, data, NULL, 1); } +struct key_value_info { + const char *filename; + int linenr; +}; + static int configset_iter(struct config_set *cs, config_fn_t fn, void *data) { int i; + struct key_value_info *kv_info; struct string_list *strptr; struct config_set_element *entry; struct hashmap_iter iter; @@ -1247,8 +1253,15 @@ static int configset_iter(struct config_set *cs, config_fn_t fn, void *data) while ((entry = hashmap_iter_next(&iter))) { strptr = &entry->value_list; for (i = 0; i < strptr->nr; i++) { - if (fn(entry->key, strptr->items[i].string, data) < 0) - die("bad config file line in (TODO: file/line info)"); + if (fn(entry->key, strptr->items[i].string, data) < 0) { + kv_info = strptr->items[i].util; + if (!kv_info->linenr) + die("unable to parse command-line config"); + else + die("bad config file line %d in %s", + kv_info->linenr, + kv_info->filename); + } } } return 0; @@ -1287,6 +1300,8 @@ static struct config_set_element *configset_find_element(struct config_set *cs, static int configset_add_value(struct config_set *cs, const char *key, const char *value) { struct config_set_element *e; + struct key_value_info *kv_info = xmalloc(sizeof(*kv_info)); + struct string_list_item *si; e = configset_find_element(cs, key); /* * Since the keys are being fed by git_config*() callback mechanism, they @@ -1299,7 +1314,16 @@ static int configset_add_value(struct config_set *cs, const char *key, const cha string_list_init(&e->value_list, 1); hashmap_add(&cs->config_hash, e); } - string_list_append_nodup(&e->value_list, value ? xstrdup(value) : NULL); + si = string_list_append_nodup(&e->value_list, value ? xstrdup(value) : NULL); + if (cf) { + kv_info->filename = strintern(cf->name); + kv_info->linenr = cf->linenr; + } else { + /* for values read from `git_config_from_parameters()` */ + kv_info->filename = strintern("parameter"); + kv_info->linenr = 0; + } + si->util = kv_info; return 0; } @@ -1326,7 +1350,7 @@ void git_configset_clear(struct config_set *cs) hashmap_iter_init(&cs->config_hash, &iter); while ((entry = hashmap_iter_next(&iter))) { free(entry->key); - string_list_clear(&entry->value_list, 0); + string_list_clear(&entry->value_list, 1); } hashmap_free(&cs->config_hash, 1); cs->hash_initialized = 0; -- 1.9.0.GIT -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html