Skip to content

Commit 008e3cc

Browse files
moygitster
authored andcommitted
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>
1 parent 7ed863a commit 008e3cc

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

builtin/config.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ static int show_config(const char *key_, const char *value_, void *cb)
9999
const char *vptr = value;
100100
int must_free_vptr = 0;
101101
int dup_error = 0;
102+
int must_print_delim = 0;
102103

103104
if (!use_key_regexp && strcmp(key_, key))
104105
return 0;
@@ -109,10 +110,8 @@ static int show_config(const char *key_, const char *value_, void *cb)
109110
return 0;
110111

111112
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;
116115
}
117116
if (seen && !do_all)
118117
dup_error = 1;
@@ -130,16 +129,23 @@ static int show_config(const char *key_, const char *value_, void *cb)
130129
} else if (types == TYPE_PATH) {
131130
git_config_pathname(&vptr, key_, value_);
132131
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;
133138
}
134-
else
135-
vptr = value_?value_:"";
136139
seen++;
137140
if (dup_error) {
138141
error("More than one value for the key %s: %s",
139142
key_, vptr);
140143
}
141-
else
144+
else {
145+
if (must_print_delim)
146+
printf("%c", key_delim);
142147
printf("%s%c", vptr, term);
148+
}
143149
if (must_free_vptr)
144150
/* If vptr must be freed, it's a pointer to a
145151
* dynamically allocated buffer, it's safe to cast to

t/t1300-repo-config.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,12 @@ test_expect_success 'get-regexp variable with no value' \
333333
'git config --get-regexp novalue > output &&
334334
cmp output expect'
335335

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+
336342
echo 'emptyvalue.variable ' > expect
337343

338344
test_expect_success 'get-regexp variable with empty value' \

0 commit comments

Comments
 (0)