Skip to content

Commit 067fef8

Browse files
committed
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 <[email protected]>
1 parent c35941e commit 067fef8

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

builtin/clean.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -674,12 +674,13 @@ static int filter_by_patterns_cmd(void)
674674
{
675675
struct dir_struct dir = DIR_INIT;
676676
struct strbuf confirm = STRBUF_INIT;
677-
struct strbuf **ignore_list;
678-
struct string_list_item *item;
679677
struct pattern_list *pl;
680678
int changed = -1, i;
681679

682680
for (;;) {
681+
struct string_list ignore_list = STRING_LIST_INIT_NODUP;
682+
struct string_list_item *item;
683+
683684
if (!del_list.nr)
684685
break;
685686

@@ -697,14 +698,15 @@ static int filter_by_patterns_cmd(void)
697698
break;
698699

699700
pl = add_pattern_list(&dir, EXC_CMDL, "manual exclude");
700-
ignore_list = strbuf_split_max(&confirm, ' ', 0);
701701

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);
706704

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));
708710
}
709711

710712
changed = 0;
@@ -725,7 +727,7 @@ static int filter_by_patterns_cmd(void)
725727
clean_print_color(CLEAN_COLOR_RESET);
726728
}
727729

728-
strbuf_list_free(ignore_list);
730+
string_list_clear(&ignore_list, 0);
729731
dir_clear(&dir);
730732
}
731733

0 commit comments

Comments
 (0)