]> git.ipfire.org Git - thirdparty/git.git/commitdiff
string-list: split-then-remove-empty can be done while splitting
authorJunio C Hamano <gitster@pobox.com>
Fri, 1 Aug 2025 22:04:23 +0000 (15:04 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 3 Aug 2025 05:34:45 +0000 (22:34 -0700)
Thanks to the new STRING_LIST_SPLIT_NONEMPTY flag, a common pattern
to split a string into a string list and then remove empty items in
the resulting list is no longer needed.  Instead, just tell the
string_list_split*() to omit empty ones while splitting.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
notes.c
pathspec.c
t/helper/test-hashmap.c
t/helper/test-json-writer.c

diff --git a/notes.c b/notes.c
index 6afcf088b974855627725a6b6ad61afb2bc7c649..3603c4a42bdc44cb0b57ab664992c9ca24850e13 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -970,8 +970,8 @@ void string_list_add_refs_from_colon_sep(struct string_list *list,
        char *globs_copy = xstrdup(globs);
        int i;
 
-       string_list_split_in_place(&split, globs_copy, ":", -1);
-       string_list_remove_empty_items(&split, 0);
+       string_list_split_in_place_f(&split, globs_copy, ":", -1,
+                                    STRING_LIST_SPLIT_NONEMPTY);
 
        for (i = 0; i < split.nr; i++)
                string_list_add_refs_by_glob(list, split.items[i].string);
index de325f7ef99df6ee7b69fb8307aab78033d01f93..5993c4afa0eb37f000414f23f4d9d25addd01d85 100644 (file)
@@ -201,8 +201,7 @@ static void parse_pathspec_attr_match(struct pathspec_item *item, const char *va
        if (!value || !*value)
                die(_("attr spec must not be empty"));
 
-       string_list_split(&list, value, " ", -1);
-       string_list_remove_empty_items(&list, 0);
+       string_list_split_f(&list, value, " ", -1, STRING_LIST_SPLIT_NONEMPTY);
 
        item->attr_check = attr_check_alloc();
        CALLOC_ARRAY(item->attr_match, list.nr);
index 7782ae585e6471df087d895629e1e111138e9dce..e4dc02bd7a0ba379db0d5c2894e943c85dc55b3c 100644 (file)
@@ -149,8 +149,8 @@ int cmd__hashmap(int argc UNUSED, const char **argv UNUSED)
 
                /* break line into command and up to two parameters */
                string_list_setlen(&parts, 0);
-               string_list_split_in_place(&parts, line.buf, DELIM, 2);
-               string_list_remove_empty_items(&parts, 0);
+               string_list_split_in_place_f(&parts, line.buf, DELIM, 2,
+                                            STRING_LIST_SPLIT_NONEMPTY);
 
                /* ignore empty lines */
                if (!parts.nr)
index a288069b04cb3b4d9360b834e8240589f2f5fd7b..f8316a7d29cdd5767257901b2533812593df350f 100644 (file)
@@ -492,8 +492,8 @@ static int scripted(void)
 
                /* break line into command and zero or more tokens */
                string_list_setlen(&parts, 0);
-               string_list_split_in_place(&parts, line, " ", -1);
-               string_list_remove_empty_items(&parts, 0);
+               string_list_split_in_place_f(&parts, line, " ", -1,
+                                            STRING_LIST_SPLIT_NONEMPTY);
 
                /* ignore empty lines */
                if (!parts.nr || !*parts.items[0].string)