config: display key_delim for config --bool --get-regexp
The previous logic in show_config was to print the delimiter when the value was set, but Boolean variables have an implicit value "true" when they appear with no value in the config file. As a result, we got: git_Config --get-regexp '.*\.Boolean' #1. Ok: example.boolean git_Config --bool --get-regexp '.*\.Boolean' #2. NO: example.booleantrue Fix this by defering the display of the separator until after the value to display has been computed. Reported-by: Brian Foster <brian.foster@maxim-ic.com> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matthieu Moy committed
Oct 10, 2011 at 14:54 UTC
008e3cc5d781273053c79d1ccf8cc3bf36086a07
2 files changed
+19
-7
builtin/config.c
+13
-7
@@ -99,6 +99,7 @@ static int show_config(const char *key_, const char *value_, void *cb)
99
const char *vptr = value;
100
int must_free_vptr = 0;
101
int dup_error = 0;
102
+ int must_print_delim = 0;
103
104
if (!use_key_regexp && strcmp(key_, key))
105
return 0;
@@ -109,10 +110,8 @@ static int show_config(const char *key_, const char *value_, void *cb)
110
return 0;
111
112
if (show_keys) {
112
- if (value_)
113
- printf("%s%c", key_, key_delim);
114
- else
115
- printf("%s", key_);
113
+ printf("%s", key_);
114
+ must_print_delim = 1;
115
}
116
if (seen && !do_all)
117
dup_error = 1;
@@ -130,16 +129,23 @@ static int show_config(const char *key_, const char *value_, void *cb)
129
} else if (types == TYPE_PATH) {
130
git_config_pathname(&vptr, key_, value_);
131
must_free_vptr = 1;
132
+ } else if (value_) {
133
+ vptr = value_;
134
+ } else {
135
+ /* Just show the key name */
136
+ vptr = "";
137
+ must_print_delim = 0;
138
}
134
- else
135
- vptr = value_?value_:"";
139
seen++;
140
if (dup_error) {
141
error("More than one value for the key %s: %s",
142
key_, vptr);
143
}
141
- else
144
+ else {
145
+ if (must_print_delim)
146
+ printf("%c", key_delim);
147
printf("%s%c", vptr, term);
148
+ }
149
if (must_free_vptr)
150
/* If vptr must be freed, it's a pointer to a
151
* dynamically allocated buffer, it's safe to cast to
t/t1300-repo-config.sh
+6
@@ -333,6 +333,12 @@ test_expect_success 'get-regexp variable with no value' \
333
'git config --get-regexp novalue > output &&
334
cmp output expect'
335
336
+echo 'novalue.variable true' > expect
337
+
338
+test_expect_success 'get-regexp --bool variable with no value' \
339
+ 'git config --bool --get-regexp novalue > output &&
340
+ cmp output expect'
341
+
342
echo 'emptyvalue.variable ' > expect
343
344
test_expect_success 'get-regexp variable with empty value' \