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

[PATCH v2 08/11] pager.c: replace `git_config()` with `git_config_get_value()`

From
Tanay Abhra <tanayabh@gmail.com>
Date
Aug 7, 2014, 16:21 UTC
Message-ID
<1407428486-19049-9-git-send-email-tanayabh@gmail.com>
In-Reply-To
<1407428486-19049-1-git-send-email-tanayabh@gmail.com>

Use `git_config_get_value()` instead of `git_config()` to take advantage of the config-set API which provides a cleaner control flow.

Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
---
 pager.c | 40 +++++++++++++---------------------------
 1 file changed, 13 insertions(+), 27 deletions(-)
diff --git a/pager.c b/pager.c
index 8b5cbc5..b7eb7e7 100644
--- a/pager.c
+++ b/pager.c
@@ -6,12 +6,6 @@
 #define DEFAULT_PAGER "less"
 #endif
 
-struct pager_config {
-	const char *cmd;
-	int want;
-	char *value;
-};
-
 /*
  * This is split up from the rest of git so that we can do
  * something different on Windows.
@@ -155,30 +149,22 @@ int decimal_width(int number)
 	return width;
 }
 
-static int pager_command_config(const char *var, const char *value, void *data)
+/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
+int check_pager_config(const char *cmd)
 {
-	struct pager_config *c = data;
-	if (starts_with(var, "pager.") && !strcmp(var + 6, c->cmd)) {
-		int b = git_config_maybe_bool(var, value);
+	int want = -1;
+	struct strbuf key = STRBUF_INIT;
+	const char *value = NULL;
+	strbuf_addf(&key, "pager.%s", cmd);
+	if (!git_config_get_value(key.buf, &value)) {
+		int b = git_config_maybe_bool(key.buf, value);
 		if (b >= 0)
-			c->want = b;
+			want = b;
 		else {
-			c->want = 1;
-			c->value = xstrdup(value);
+			want = 1;
+			pager_program = xstrdup(value);
 		}
 	}
-	return 0;
-}
-
-/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
-int check_pager_config(const char *cmd)
-{
-	struct pager_config c;
-	c.cmd = cmd;
-	c.want = -1;
-	c.value = NULL;
-	git_config(pager_command_config, &c);
-	if (c.value)
-		pager_program = c.value;
-	return c.want;
+	strbuf_release(&key);
+	return want;
 }
-- 
1.9.0.GIT
Previous: Tanay AbhraNext: Tanay Abhra
Message 9 of 16 in “git_config callers rewritten with the new config-set API”
  1. 00/11 git_config callers rewritten with the new config-set APITanay Abhra, Aug 7, 2014
  2. 01/11 daemon.c: replace `git_config()` with `git_config_get_bool()` familyTanay Abhra, Aug 7, 2014
  3. 02/11 http-backend.c: replace `git_config()` with `git_config_get_bool()` familyTanay Abhra, Aug 7, 2014
  4. 03/11 read-cache.c: replace `git_config()` with `git_config_get_*()` familyTanay Abhra, Aug 7, 2014
  5. 04/11 archive.c: replace `git_config()` with `git_config_get_bool()` familyTanay Abhra, Aug 7, 2014
  6. 05/11 fetchpack.c: replace `git_config()` with `git_config_get_*()` familyTanay Abhra, Aug 7, 2014
  7. 06/11 rerere.c: replace `git_config()` with `git_config_get_*()` familyTanay Abhra, Aug 7, 2014
  8. 07/11 builtin/gc.c: replace `git_config()` with `git_config_get_*()` familyTanay Abhra, Aug 7, 2014
  9. 08/11 pager.c: replace `git_config()` with `git_config_get_value()`Tanay Abhra, Aug 7, 2014
  10. 09/11 imap-send.c: replace `git_config()` with `git_config_get_*()` familyTanay Abhra, Aug 7, 2014
  11. 10/11 alias.c: replace `git_config()` with `git_config_get_string()`Tanay Abhra, Aug 7, 2014
  12. 11/11 branch.c: replace `git_config()` with `git_config_get_string()Tanay Abhra, Aug 7, 2014
  13. Matthieu MoyAug 7, 2014
  14. 11/11 branch.c: replace `git_config()` with `git_config_get_string()Tanay Abhra, Aug 7, 2014
  15. Matthieu MoyAug 7, 2014
  16. Junio C HamanoAug 7, 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.