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

Re* [PATCH] Add `log.decorate' configuration variable.

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 17, 2010, 07:59 UTC
Message-ID
<7vk4uc70nh.fsf_-_@alter.siamese.dyndns.org>
In-Reply-To
<36ca99e91002162342v2f151962p4d8f85f06c32205f@mail.gmail.com>
Bert Wesarg <bert.wesarg@googlemail.com> writes:
Show 8 quoted lines
>> +int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
>> +{
>> +       int v = git_config_maybe_bool(name, value);
>> +       if (0 <= v)
>> +               return v;
>>        return git_config_int(name, value);
>>  }
> What happened with the is_bool parameter?

Good eyes. That was why it was "Perhaps something like this" without any serious commit message ;-).

How about this?
-- >8 --
Subject: git_config_maybe_bool()

Some configuration variables can take boolean values in addition to enumeration specific to them. Introduce git_config_maybe_bool() that returns 0 or 1 if the given value is boolean, or -1 if not, so that a parser for such a variable can check for boolean first and then parse other kinds of values as a fallback.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 cache.h  |    1 +
 config.c |   21 +++++++++++++++++----
 2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/cache.h b/cache.h
index d478eff..dd3be0a 100644
--- a/cache.h
+++ b/cache.h
@@ -924,6 +924,7 @@ extern int git_config_int(const char *, const char *);
 extern unsigned long git_config_ulong(const char *, const char *);
 extern int git_config_bool_or_int(const char *, const char *, int *);
 extern int git_config_bool(const char *, const char *);
+extern int git_config_maybe_bool(const char *, const char *);
 extern int git_config_string(const char **, const char *, const char *);
 extern int git_config_pathname(const char **, const char *, const char *);
 extern int git_config_set(const char *, const char *);
diff --git a/config.c b/config.c
index 6963fbe..64e41be 100644
--- a/config.c
+++ b/config.c
@@ -322,17 +322,30 @@ unsigned long git_config_ulong(const char *name, const char *value)
 	return ret;
 }
 
-int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
+int git_config_maybe_bool(const char *name, const char *value)
 {
-	*is_bool = 1;
 	if (!value)
 		return 1;
 	if (!*value)
 		return 0;
-	if (!strcasecmp(value, "true") || !strcasecmp(value, "yes") || !strcasecmp(value, "on"))
+	if (!strcasecmp(value, "true")
+	    || !strcasecmp(value, "yes")
+	    || !strcasecmp(value, "on"))
 		return 1;
-	if (!strcasecmp(value, "false") || !strcasecmp(value, "no") || !strcasecmp(value, "off"))
+	if (!strcasecmp(value, "false")
+	    || !strcasecmp(value, "no")
+	    || !strcasecmp(value, "off"))
 		return 0;
+	return -1;
+}
+
+int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
+{
+	int v = git_config_maybe_bool(name, value);
+	if (0 <= v) {
+		*is_bool = 1;
+		return v;
+	}
 	*is_bool = 0;
 	return git_config_int(name, value);
 }
Previous: Bert WesargNext: Heiko Voigt
Message 8 of 9 in “Add `log.decorate' configuration variable.”
  1. Add `log.decorate' configuration variable.Steven Drake, Feb 16, 2010
  2. Junio C HamanoFeb 17, 2010
  3. Steven DrakeFeb 17, 2010
  4. Junio C HamanoFeb 17, 2010
  5. Steven DrakeFeb 17, 2010
  6. Junio C HamanoFeb 17, 2010
  7. Bert WesargFeb 17, 2010
  8. Re* [PATCH] Add `log.decorate' configuration variable.Junio C Hamano, Feb 17, 2010
  9. Heiko VoigtFeb 17, 2010

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.