On 02/15/2017 03:11 PM, Junio C Hamano wrote:
Junio C Hamano <gitster@xxxxxxxxx> writes: Perhaps something like this?
This looks good. I was hoping to unify the processing logic between this CLI parsing and the usual stream parsing, but this approach is probably simpler.
config.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index c6b874a7bf..98bf8fee32 100644 --- a/config.c +++ b/config.c @@ -201,6 +201,20 @@ void git_config_push_parameter(const char *text) strbuf_release(&env); } +static void canonicalize_config_variable_name(struct strbuf *var) +{ + char *first_dot = strchr(var->buf, '.'); + char *last_dot = strrchr(var->buf, '.'); + char *cp; + + if (first_dot) + for (cp = var->buf; *cp && cp < first_dot; cp++)
"*cp &&" is unnecessary, as far as I can tell.
+ *cp = tolower(*cp); + if (last_dot) + for (cp = last_dot; *cp; cp++) + *cp = tolower(*cp); +} + int git_config_parse_parameter(const char *text, config_fn_t fn, void *data) { @@ -223,7 +237,7 @@ int git_config_parse_parameter(const char *text, strbuf_list_free(pair); return error("bogus config parameter: %s", text); } - strbuf_tolower(pair[0]); + canonicalize_config_variable_name(pair[0]); if (fn(pair[0]->buf, value, data) < 0) { strbuf_list_free(pair); return -1;