Le lundi 4 février 2008, Johannes Sixt a écrit :
Christian Couder schrieb:
quoted
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<---