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

[PATCH/RFC] branch.c: Replace `git_config` with `git_config_get_string`

From
Tanay Abhra <tanayabh@gmail.com>
Date
Jun 16, 2014, 08:52 UTC
Message-ID
<1402908750-24851-1-git-send-email-tanayabh@gmail.com>

Original implementation uses a callback based approach which has some deficiencies like a convoluted control flow and redundant variables. Use git_config_get_string instead of git_config to take advantage of the config hash-table.

---

This patch builds on top of patch series[1]. It passes all the tests, and this in first of series of patches that aim to replace all git_config calls scattered arund the code base with appropriate non-callback based calls.

There are total 111 calls in total in all of git codebase. How should I send the patches, alphabetically or otherwise?

[1] http://thread.gmane.org/gmane.comp.version-control.git/251704

Cheers, Tanay Abhra.

 branch.c | 25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)
diff --git a/branch.c b/branch.c
index 660097b..257b1bf 100644
--- a/branch.c
+++ b/branch.c
@@ -140,33 +140,26 @@ static int setup_tracking(const char *new_ref, const char *orig_ref,
 	return 0;
 }
 
-struct branch_desc_cb {
+struct branch_desc {
 	const char *config_name;
 	const char *value;
 };
 
-static int read_branch_desc_cb(const char *var, const char *value, void *cb)
-{
-	struct branch_desc_cb *desc = cb;
-	if (strcmp(desc->config_name, var))
-		return 0;
-	free((char *)desc->value);
-	return git_config_string(&desc->value, var, value);
-}
-
 int read_branch_desc(struct strbuf *buf, const char *branch_name)
 {
-	struct branch_desc_cb cb;
+	const char *value;
+	struct branch_desc desc;
 	struct strbuf name = STRBUF_INIT;
 	strbuf_addf(&name, "branch.%s.description", branch_name);
-	cb.config_name = name.buf;
-	cb.value = NULL;
-	if (git_config(read_branch_desc_cb, &cb) < 0) {
+	desc.config_name = name.buf;
+	desc.value = NULL;
+	value = git_config_get_string(desc.config_name);
+	git_config_string(&desc.value, desc.config_name, value);
+	if (!desc.value) {
 		strbuf_release(&name);
 		return -1;
 	}
-	if (cb.value)
-		strbuf_addstr(buf, cb.value);
+	strbuf_addstr(buf, desc.value);
 	strbuf_release(&name);
 	return 0;
 }
-- 
1.9.0.GIT
Next: Matthieu Moy
Message 1 of 3 in “branch.c: Replace `git_config` with `git_config_get_string`”
  1. branch.c: Replace `git_config` with `git_config_get_string`Tanay Abhra, Jun 16, 2014
  2. Matthieu MoyJun 16, 2014
  3. Tanay AbhraJun 16, 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.