Skip to content

Commit ec9c038

Browse files
committed
config: do not use strbuf_split()
When parsing an old-style GIT_CONFIG_PARAMETERS environment variable, the code parses key=value pairs by splitting them at '=' into an array of strbuf's. As strbuf_split() leaves the delimiter at the end of the split piece, the code has to manually trim it. If we split with string_list_split(), that becomes unnecessary. Retire the use of strbuf_split() from this code path. Note that the max parameter of string_list_split() is of an ergonomically iffy design---it specifies the maximum number of times the function is allowed to split, which means that in order to split a text into up to 2 pieces, you have to pass 1, not 2. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 927eae1 commit ec9c038

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

config.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -638,31 +638,28 @@ int git_config_parse_parameter(const char *text,
638638
config_fn_t fn, void *data)
639639
{
640640
const char *value;
641-
struct strbuf **pair;
641+
struct string_list pair = STRING_LIST_INIT_DUP;
642642
int ret;
643643
struct key_value_info kvi = KVI_INIT;
644644

645645
kvi_from_param(&kvi);
646646

647-
pair = strbuf_split_str(text, '=', 2);
648-
if (!pair[0])
647+
string_list_split(&pair, text, "=", 1);
648+
if (!pair.nr)
649649
return error(_("bogus config parameter: %s"), text);
650650

651-
if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=') {
652-
strbuf_setlen(pair[0], pair[0]->len - 1);
653-
value = pair[1] ? pair[1]->buf : "";
654-
} else {
651+
if (pair.nr == 1)
655652
value = NULL;
656-
}
653+
else
654+
value = pair.items[1].string;
657655

658-
strbuf_trim(pair[0]);
659-
if (!pair[0]->len) {
660-
strbuf_list_free(pair);
656+
if (!*pair.items[0].string) {
657+
string_list_clear(&pair, 0);
661658
return error(_("bogus config parameter: %s"), text);
662659
}
663660

664-
ret = config_parse_pair(pair[0]->buf, value, &kvi, fn, data);
665-
strbuf_list_free(pair);
661+
ret = config_parse_pair(pair.items[0].string, value, &kvi, fn, data);
662+
string_list_clear(&pair, 0);
666663
return ret;
667664
}
668665

0 commit comments

Comments
 (0)