Git fork

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 <gitster@pobox.com>

+10 -13
+10 -13
config.c
··· 638 config_fn_t fn, void *data) 639 { 640 const char *value; 641 - struct strbuf **pair; 642 int ret; 643 struct key_value_info kvi = KVI_INIT; 644 645 kvi_from_param(&kvi); 646 647 - pair = strbuf_split_str(text, '=', 2); 648 - if (!pair[0]) 649 return error(_("bogus config parameter: %s"), text); 650 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 { 655 value = NULL; 656 - } 657 658 - strbuf_trim(pair[0]); 659 - if (!pair[0]->len) { 660 - strbuf_list_free(pair); 661 return error(_("bogus config parameter: %s"), text); 662 } 663 664 - ret = config_parse_pair(pair[0]->buf, value, &kvi, fn, data); 665 - strbuf_list_free(pair); 666 return ret; 667 } 668
··· 638 config_fn_t fn, void *data) 639 { 640 const char *value; 641 + struct string_list pair = STRING_LIST_INIT_DUP; 642 int ret; 643 struct key_value_info kvi = KVI_INIT; 644 645 kvi_from_param(&kvi); 646 647 + string_list_split(&pair, text, "=", 1); 648 + if (!pair.nr) 649 return error(_("bogus config parameter: %s"), text); 650 651 + if (pair.nr == 1) 652 value = NULL; 653 + else 654 + value = pair.items[1].string; 655 656 + if (!*pair.items[0].string) { 657 + string_list_clear(&pair, 0); 658 return error(_("bogus config parameter: %s"), text); 659 } 660 661 + ret = config_parse_pair(pair.items[0].string, value, &kvi, fn, data); 662 + string_list_clear(&pair, 0); 663 return ret; 664 } 665