Skip to content

Commit b342ae6

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 13c4495 commit b342ae6

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

config.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,26 @@ int git_config_key_is_valid(const char *key)
462462
return !git_config_parse_key_1(key, NULL, NULL, 1);
463463
}
464464

465+
static int config_parse_pair(const char *key, const char *value,
466+
config_fn_t fn, void *data)
467+
{
468+
char *canonical_name;
469+
int ret;
470+
471+
if (!strlen(key))
472+
return error(_("empty config key"));
473+
if (git_config_parse_key(key, &canonical_name, NULL))
474+
return -1;
475+
476+
ret = (fn(canonical_name, value, data) < 0) ? -1 : 0;
477+
free(canonical_name);
478+
return ret;
479+
}
480+
465481
int git_config_parse_parameter(const char *text,
466482
config_fn_t fn, void *data)
467483
{
468484
const char *value;
469-
char *canonical_name;
470485
struct strbuf **pair;
471486
int ret;
472487

@@ -487,12 +502,7 @@ int git_config_parse_parameter(const char *text,
487502
return error(_("bogus config parameter: %s"), text);
488503
}
489504

490-
if (git_config_parse_key(pair[0]->buf, &canonical_name, NULL)) {
491-
ret = -1;
492-
} else {
493-
ret = (fn(canonical_name, value, data) < 0) ? -1 : 0;
494-
free(canonical_name);
495-
}
505+
ret = config_parse_pair(pair[0]->buf, value, fn, data);
496506
strbuf_list_free(pair);
497507
return ret;
498508
}

0 commit comments

Comments
 (0)