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

[RFC/PATCH] pager.c: replace git_config with git_config_get_string

From
Tanay Abhra <tanayabh@gmail.com>
Date
Jun 23, 2014, 10:41 UTC
Message-ID
<1403520105-23250-6-git-send-email-tanayabh@gmail.com>
In-Reply-To
<1403520105-23250-1-git-send-email-tanayabh@gmail.com>

Use git_config_get_string instead of git_config to take advantage of the config hash-table api which provides a cleaner control flow.

Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
---
 pager.c | 44 +++++++++++++++-----------------------------
 1 file changed, 15 insertions(+), 29 deletions(-)
diff --git a/pager.c b/pager.c
index 8b5cbc5..96abe6d 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)
-{
-	struct pager_config *c = data;
-	if (starts_with(var, "pager.") && !strcmp(var + 6, c->cmd)) {
-		int b = git_config_maybe_bool(var, value);
-		if (b >= 0)
-			c->want = b;
-		else {
-			c->want = 1;
-			c->value = 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;
+	struct strbuf key = STRBUF_INIT;
+	int want = -1;
+	const char *value = NULL;
+	strbuf_addf(&key, "pager.%s", cmd);
+	if (!git_config_get_string(key.buf, &value)) {
+		int b = git_config_maybe_bool(key.buf, value);
+		if (b >= 0)
+			want = b;
+		else
+			want = 1;
+	}
+	if (value)
+		pager_program = value;
+	strbuf_release(&key);
+	return want;
 }
-- 
1.9.0.GIT
Previous: Tanay AbhraNext: Eric Sunshine
Message 26 of 41 in “alias.c: replace git_config with git_config_get_string”
  1. alias.c: replace git_config with git_config_get_stringTanay Abhra, Jun 23, 2014
  2. branch.c: replace git_config with git_config_get_stringTanay Abhra, Jun 23, 2014
  3. Eric SunshineJun 25, 2014
  4. Tanay AbhraJun 26, 2014
  5. Eric SunshineJun 29, 2014
  6. imap-send.c: replace git_config with git_config_get_stringTanay Abhra, Jun 23, 2014
  7. Eric SunshineJun 25, 2014
  8. Tanay AbhraJun 26, 2014
  9. Matthieu MoyJun 26, 2014
  10. Karsten BleesJun 26, 2014
  11. notes-util.c: replace git_config with git_config_get_stringTanay Abhra, Jun 23, 2014
  12. Eric SunshineJun 25, 2014
  13. Tanay AbhraJun 26, 2014
  14. Eric SunshineJun 29, 2014
  15. Karsten BleesJun 30, 2014
  16. Eric SunshineJun 30, 2014
  17. Karsten BleesJun 30, 2014
  18. Tanay AbhraJun 30, 2014
  19. Karsten BleesJun 30, 2014
  20. Tanay AbhraJun 30, 2014
  21. Junio C HamanoJun 30, 2014
  22. Matthieu MoyJul 1, 2014
  23. notes.c: replace git_config with git_config_get_stringTanay Abhra, Jun 23, 2014
  24. Eric SunshineJun 25, 2014
  25. Tanay AbhraJun 26, 2014
  26. pager.c: replace git_config with git_config_get_stringTanay Abhra, Jun 23, 2014
  27. Eric SunshineJun 25, 2014
  28. Tanay AbhraJun 26, 2014
  29. Karsten BleesJun 26, 2014
  30. Matthieu MoyJun 27, 2014
  31. Karsten BleesJun 27, 2014
  32. Matthieu MoyJun 27, 2014
  33. Karsten BleesJun 28, 2014
  34. Matthieu MoyJun 28, 2014
  35. Karsten BleesJun 28, 2014
  36. Matthieu MoyJun 29, 2014
  37. Jonathan NiederJun 23, 2014
  38. Tanay AbhraJun 24, 2014
  39. Eric SunshineJun 25, 2014
  40. Tanay AbhraJun 26, 2014
  41. Matthieu MoyJun 26, 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.