git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 2/6] add line number and file name info to `config_set`

From
Tanay Abhra <tanayabh@gmail.com>
Date
Jul 28, 2014, 10:33 UTC
Message-ID
<1406543635-19281-3-git-send-email-tanayabh@gmail.com>
In-Reply-To
<1406543635-19281-1-git-send-email-tanayabh@gmail.com>

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>
---
 config.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/config.c b/config.c
index e5b7f10..5499108 100644
--- a/config.c
+++ b/config.c
@@ -1232,6 +1232,11 @@ int git_config_with_options(config_fn_t fn, void *data,
 	return ret;
 }
 
+struct key_value_info {
+	const char *filename;
+	int linenr;
+};
+
 int git_config(config_fn_t fn, void *data)
 {
 	return git_config_with_options(fn, data, NULL, 1);
@@ -1262,6 +1267,9 @@ 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 string_list_item *si;
+	struct key_value_info *kv_info = xmalloc(sizeof(*kv_info));
+
 	e = configset_find_element(cs, key);
 	/*
 	 * Since the keys are being fed by git_config*() callback mechanism, they
@@ -1274,7 +1282,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;
 }
@@ -1301,7 +1318,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
Previous: Tanay AbhraNext: Tanay Abhra
Message 3 of 15 in “Rewrite `git_config()` using config-set API”
  1. 0/6 Rewrite `git_config()` using config-set APITanay Abhra, Jul 28, 2014
  2. 1/6 config.c: fix accuracy of line number in errorsTanay Abhra, Jul 28, 2014
  3. 2/6 add line number and file name info to `config_set`Tanay Abhra, Jul 28, 2014
  4. 3/6 rewrite git_config() to use the config-set APITanay Abhra, Jul 28, 2014
  5. 4/6 add a test for semantic errors in config filesTanay Abhra, Jul 28, 2014
  6. Matthieu MoyJul 28, 2014
  7. Tanay AbhraJul 28, 2014
  8. Matthieu MoyJul 28, 2014
  9. 5/6 config: add `git_die_config()` to the config-set APITanay Abhra, Jul 28, 2014
  10. Ramsay JonesJul 28, 2014
  11. Tanay AbhraJul 28, 2014
  12. Matthieu MoyJul 28, 2014
  13. Matthieu MoyJul 28, 2014
  14. 6/6 add tests for `git_config_get_string_const()`Tanay Abhra, Jul 28, 2014
  15. Matthieu MoyJul 28, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.