summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-08-04 22:40:19 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-08-05 17:09:17 (GMT)
commita789ca70e7a5b02973b116d21674acd795238f99 (patch)
treefd5e0827a1737e07858c5418e9d5c4fa6b570dfc /config.c
parente6aaa393478bf3ee9f4cde8d82cd258c034cd335 (diff)
downloadgit-a789ca70e7a5b02973b116d21674acd795238f99.zip
git-a789ca70e7a5b02973b116d21674acd795238f99.tar.gz
git-a789ca70e7a5b02973b116d21674acd795238f99.tar.bz2
config: teach "git -c" to recognize an empty string
In a config file, you can do: [foo] bar to turn the "foo.bar" boolean flag on, and you can do: [foo] bar= to set "foo.bar" to the empty string. However, git's "-c" parameter treats both: git -c foo.bar and git -c foo.bar= as the boolean flag, and there is no way to set a variable to the empty string. This patch enables the latter form to do that. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r--config.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/config.c b/config.c
index e1d66a1..5390a63 100644
--- a/config.c
+++ b/config.c
@@ -164,19 +164,27 @@ void git_config_push_parameter(const char *text)
int git_config_parse_parameter(const char *text,
config_fn_t fn, void *data)
{
+ const char *value;
struct strbuf **pair;
+
pair = strbuf_split_str(text, '=', 2);
if (!pair[0])
return error("bogus config parameter: %s", text);
- if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=')
+
+ if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=') {
strbuf_setlen(pair[0], pair[0]->len - 1);
+ value = pair[1] ? pair[1]->buf : "";
+ } else {
+ value = NULL;
+ }
+
strbuf_trim(pair[0]);
if (!pair[0]->len) {
strbuf_list_free(pair);
return error("bogus config parameter: %s", text);
}
lowercase(pair[0]->buf);
- if (fn(pair[0]->buf, pair[1] ? pair[1]->buf : NULL, data) < 0) {
+ if (fn(pair[0]->buf, value, data) < 0) {
strbuf_list_free(pair);
return -1;
}