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

Re: [bug] generic issue with git_config handlers

From
Christian Couder <chriscool@tuxfamily.org>
Date
Feb 4, 2008, 23:13 UTC
Message-ID
<200802050013.20335.chriscool@tuxfamily.org>
In-Reply-To
<47A74503.4090201@viscovery.net>
Le lundi 4 février 2008, Johannes Sixt a écrit :
Show 9 quoted lines
> Christian Couder schrieb:
> >                         return -1;
> >         }
> > -       return fn(name, value);
> > +       return fn(name, value ? value : "");
> >  }
>
> You can't. The reason is that get_config_bool() treats value == NULL and
> *value == '\0' differently. *That's* the most unfortunate part of it. :-(
You are right. We have this (in config.c:299):
int git_config_bool(const char *name, const char *value)
{
	if (!value)
		return 1;
	if (!*value)
		return 0;
	if (!strcasecmp(value, "true") || !strcasecmp(value, "yes"))
		return 1;
	if (!strcasecmp(value, "false") || !strcasecmp(value, "no"))
		return 0;
	return git_config_int(name, value) != 0;
}
Very unfortunate.

I finally had the following patch that passed all tests (it changed only one test), in case someone wants to suggest that we change git_config_bool, hint, hint!

Thanks, Christian.

---8<---
diff --git a/builtin-config.c b/builtin-config.c
index e4a12e3..b92cf4b 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -20,7 +20,7 @@ static enum { T_RAW, T_INT, T_BOOL } type = T_RAW;

 static int show_all_config(const char *key_, const char *value_)
 {
-       if (value_)
+       if (value_ && *value_)
                printf("%s%c%s%c", key_, delim, value_, term);
        else
                printf("%s%c", key_, term);
@@ -42,7 +42,7 @@ static int show_config(const char* key_, const char* 
value_)
                return 0;

        if (show_keys) {
-               if (value_)
+               if (value_ && *value_)
                        printf("%s%c", key_, key_delim);
                else
                        printf("%s", key_);
diff --git a/config.c b/config.c
index 526a3f4..a2c7214 100644
--- a/config.c
+++ b/config.c
@@ -131,7 +131,7 @@ static int get_value(config_fn_t fn, char *name, 
unsigned in
        while (c == ' ' || c == '\t')
                c = get_next_char();

-       value = NULL;
+       value = "";
        if (c != '\n') {
                if (c != '=')
                        return -1;
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index a786c5c..deb11dc 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -611,8 +611,7 @@ foo
 barQsection.sub=section.val3


-Qsection.sub=section.val4
-Qsection.sub=section.val5Q
+Qsection.sub=section.val4Qsection.sub=section.val5Q
 EOF

 git config --null --list | tr '\000' 'Q' > result
---8<---
Previous: Johannes SixtNext: Junio C Hamano
Message 6 of 8 in “[bug] generic issue with git_config handlers”
  1. Pierre HabouzitJan 31, 2008
  2. Junio C HamanoJan 31, 2008
  3. Pierre HabouzitJan 31, 2008
  4. Christian CouderFeb 4, 2008
  5. Johannes SixtFeb 4, 2008
  6. Christian CouderFeb 4, 2008
  7. Junio C HamanoFeb 5, 2008
  8. Christian CouderFeb 7, 2008

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.