Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2021-01-12 15:26:54 +0300
committerJunio C Hamano <gitster@pobox.com>2021-01-12 23:03:18 +0300
commitb342ae61b3658ed4c062a27f8e46ea79c38d4197 (patch)
tree637ec6550f3c4b0caa5bdb3152fd4e217dbcaf62 /config.c
parent13c44953fb0b396d3594b4a712f956ab3a48169e (diff)
config: extract function to parse config pairs
The function `git_config_parse_parameter` is responsible for parsing a `foo.bar=baz`-formatted configuration key, sanitizing the key and then processing it via the given callback function. Given that we're about to add a second user which is going to process keys which already has keys and values separated, this commit extracts a function `config_parse_pair` which only does the sanitization and processing part as a preparatory step. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r--config.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/config.c b/config.c
index ed89c557bd..4452277d1a 100644
--- a/config.c
+++ b/config.c
@@ -462,11 +462,26 @@ int git_config_key_is_valid(const char *key)
return !git_config_parse_key_1(key, NULL, NULL, 1);
}
+static int config_parse_pair(const char *key, const char *value,
+ config_fn_t fn, void *data)
+{
+ char *canonical_name;
+ int ret;
+
+ if (!strlen(key))
+ return error(_("empty config key"));
+ if (git_config_parse_key(key, &canonical_name, NULL))
+ return -1;
+
+ ret = (fn(canonical_name, value, data) < 0) ? -1 : 0;
+ free(canonical_name);
+ return ret;
+}
+
int git_config_parse_parameter(const char *text,
config_fn_t fn, void *data)
{
const char *value;
- char *canonical_name;
struct strbuf **pair;
int ret;
@@ -487,12 +502,7 @@ int git_config_parse_parameter(const char *text,
return error(_("bogus config parameter: %s"), text);
}
- if (git_config_parse_key(pair[0]->buf, &canonical_name, NULL)) {
- ret = -1;
- } else {
- ret = (fn(canonical_name, value, data) < 0) ? -1 : 0;
- free(canonical_name);
- }
+ ret = config_parse_pair(pair[0]->buf, value, fn, data);
strbuf_list_free(pair);
return ret;
}