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

[PATCH v4 2/5] notes.c: replace `git_config()` with `git_config_get_value_multi()`

From
Tanay Abhra <tanayabh@gmail.com>
Date
Jul 30, 2014, 13:39 UTC
Message-ID
<1406727549-22334-3-git-send-email-tanayabh@gmail.com>
In-Reply-To
<1406727549-22334-1-git-send-email-tanayabh@gmail.com>

Use `git_config_get_value_multi()` instead of `git_config()` to take advantage of the config-set API which provides a cleaner control flow, also previously 'string_list_add_refs_by_glob()' was called even when the retrieved value was NULL, correct it while we are at it.

Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
---
 notes.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/notes.c b/notes.c
index 5fe691d..abb0ce0 100644
--- a/notes.c
+++ b/notes.c
@@ -961,19 +961,6 @@ void string_list_add_refs_from_colon_sep(struct string_list *list,
 	free(globs_copy);
 }
 
-static int notes_display_config(const char *k, const char *v, void *cb)
-{
-	int *load_refs = cb;
-
-	if (*load_refs && !strcmp(k, "notes.displayref")) {
-		if (!v)
-			config_error_nonbool(k);
-		string_list_add_refs_by_glob(&display_notes_refs, v);
-	}
-
-	return 0;
-}
-
 const char *default_notes_ref(void)
 {
 	const char *notes_ref = NULL;
@@ -1041,7 +1028,8 @@ struct notes_tree **load_notes_trees(struct string_list *refs)
 void init_display_notes(struct display_notes_opt *opt)
 {
 	char *display_ref_env;
-	int load_config_refs = 0;
+	const struct string_list *values;
+	int load_config_refs = 0, i;
 	display_notes_refs.strdup_strings = 1;
 
 	assert(!display_notes_trees);
@@ -1058,7 +1046,18 @@ void init_display_notes(struct display_notes_opt *opt)
 			load_config_refs = 1;
 	}
 
-	git_config(notes_display_config, &load_config_refs);
+	if (load_config_refs) {
+		values = git_config_get_value_multi("notes.displayref");
+		if (values) {
+			for (i = 0; i < values->nr; i++) {
+				if (!values->items[i].string)
+					config_error_nonbool("notes.displayref");
+				else
+					string_list_add_refs_by_glob(&display_notes_refs,
+								     values->items[i].string);
+			}
+		}
+	}
 
 	if (opt) {
 		struct string_list_item *item;
-- 
1.9.0.GIT
Previous: Tanay AbhraNext: Matthieu Moy
Message 3 of 16 in “git_config callers rewritten with the new config cache API”
  1. 0/5 git_config callers rewritten with the new config cache APITanay Abhra, Jul 30, 2014
  2. 1/5 pager.c: replace `git_config()` with `git_config_get_value()`Tanay Abhra, Jul 30, 2014
  3. 2/5 notes.c: replace `git_config()` with `git_config_get_value_multi()`Tanay Abhra, Jul 30, 2014
  4. Matthieu MoyJul 30, 2014
  5. Tanay AbhraJul 30, 2014
  6. Matthieu MoyJul 30, 2014
  7. Matthieu MoyJul 31, 2014
  8. Tanay AbhraJul 31, 2014
  9. 3/5 imap-send.c: replace `git_config()` with `git_config_get_*()` familyTanay Abhra, Jul 30, 2014
  10. 4/5 branch.c: replace `git_config()` with `git_config_get_string()Tanay Abhra, Jul 30, 2014
  11. Matthieu MoyJul 30, 2014
  12. 5/5 alias.c: replace `git_config()` with `git_config_get_string()`Tanay Abhra, Jul 30, 2014
  13. Matthieu MoyJul 30, 2014
  14. Tanay AbhraJul 30, 2014
  15. Matthieu MoyJul 30, 2014
  16. Ramsay JonesJul 31, 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.