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

On boolean configuration variables...

From
Junio C Hamano <junkio@cox.net>
Date
Jun 24, 2006, 12:28 UTC
Message-ID
<7vy7vmviul.fsf@assigned-by-dhcp.cox.net>

Boolean configuration variables in $GIT_DIR/config are a bit strange.

	[bool]
        	var1
                var2 =
                var3 = true
                var4 = yes
                var5 = 1
                var6 = 2
                var7 = false
                var8 = no
                var9 = 0

var1, var3, var5, and var6 are "true"; var2, var7 and var9 are "false". var4 and var8 are syntax errors.

Currently "git repo-config --bool --get bool.var1" returns "false", which is fixed by the attached patch, but I am wondering if it is a good idea to allow "yes" and "no" as well.

-- >8 -- [PATCH] repo-config: fix printing of bool

When a bool variable appears without any value, it means true. However, replacing the NULL value with an empty string, an earlier commit f067a13745fbeae1aa357876348a00e5edd0a629 broke show-config.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 repo-config.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/repo-config.c b/repo-config.c
index ab8f1af..743f02b 100644
--- a/repo-config.c
+++ b/repo-config.c
@@ -29,16 +29,13 @@ static int show_config(const char* key_,
 	const char *vptr = value;
 	int dup_error = 0;
 
-	if (value_ == NULL)
-		value_ = "";
-
 	if (!use_key_regexp && strcmp(key_, key))
 		return 0;
 	if (use_key_regexp && regexec(key_regexp, key_, 0, NULL, 0))
 		return 0;
 	if (regexp != NULL &&
 			 (do_not_match ^
-			  regexec(regexp, value_, 0, NULL, 0)))
+			  regexec(regexp, (value_?value_:""), 0, NULL, 0)))
 		return 0;
 
 	if (show_keys)
@@ -46,11 +43,11 @@ static int show_config(const char* key_,
 	if (seen && !do_all)
 		dup_error = 1;
 	if (type == T_INT)
-		sprintf(value, "%d", git_config_int(key_, value_));
+		sprintf(value, "%d", git_config_int(key_, value_?value_:""));
 	else if (type == T_BOOL)
 		vptr = git_config_bool(key_, value_) ? "true" : "false";
 	else
-		vptr = value_;
+		vptr = value_?value_:"";
 	seen++;
 	if (dup_error) {
 		error("More than one value for the key %s: %s",
-- 
1.4.1.rc1.ga77b7
Next: Anand Kumria
Message 1 of 4 in “On boolean configuration variables...”
  1. Junio C HamanoJun 24, 2006
  2. Anand KumriaJun 25, 2006
  3. Johannes SchindelinJun 25, 2006
  4. Anand KumriaJun 25, 2006

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.