clean: do not use strbuf_split*() [part 2]
builtin/clean.c:filter_by_patterns_cmd() interactively reads a line that has exclude patterns from the user and splits the line into a list of patterns. It uses the strbuf_split() so that each split piece can then trimmed. There is no need to use strbuf anymore, thanks to the recent enhancement to string_list_split*() family that allows us to trim the pieces split into a string_list. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jul 31, 2025 at 15:54 UTC
4f60672f6f7cbc61fb704c993c54187860f1e9c8
1 file changed
+11
-9
builtin/clean.c
+11
-9
@@ -674,12 +674,13 @@ static int filter_by_patterns_cmd(void)
674
{
675
struct dir_struct dir = DIR_INIT;
676
struct strbuf confirm = STRBUF_INIT;
677
- struct strbuf **ignore_list;
678
- struct string_list_item *item;
677
struct pattern_list *pl;
678
int changed = -1, i;
679
680
for (;;) {
681
+ struct string_list ignore_list = STRING_LIST_INIT_NODUP;
682
+ struct string_list_item *item;
683
+
684
if (!del_list.nr)
685
break;
686
@@ -697,14 +698,15 @@ static int filter_by_patterns_cmd(void)
698
break;
699
700
pl = add_pattern_list(&dir, EXC_CMDL, "manual exclude");
700
- ignore_list = strbuf_split_max(&confirm, ' ', 0);
701
702
- for (i = 0; ignore_list[i]; i++) {
703
- strbuf_trim(ignore_list[i]);
704
- if (!ignore_list[i]->len)
705
- continue;
702
+ string_list_split_in_place_f(&ignore_list, confirm.buf, " ", -1,
703
+ STRING_LIST_SPLIT_TRIM);
704
707
- add_pattern(ignore_list[i]->buf, "", 0, pl, -(i+1));
705
+ for (i = 0; i < ignore_list.nr; i++) {
706
+ item = &ignore_list.items[i];
707
+ if (!*item->string)
708
+ continue;
709
+ add_pattern(item->string, "", 0, pl, -(i+1));
710
}
711
712
changed = 0;
@@ -725,7 +727,7 @@ static int filter_by_patterns_cmd(void)
727
clean_print_color(CLEAN_COLOR_RESET);
728
}
729
728
- strbuf_list_free(ignore_list);
730
+ string_list_clear(&ignore_list, 0);
731
dir_clear(&dir);
732
}
733