string-list: optionally omit empty string pieces in string_list_split*()

Teach the unified split_string() machinery a new flag bit,
STRING_LIST_SPLIT_NONEMPTY, to cause empty split pieces to be
omitted from the resulting string list.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano
2025-08-01 15:04:22 -07:00
parent f3a303aef0
commit 27531efa41
3 changed files with 20 additions and 0 deletions

View File

@@ -294,6 +294,9 @@ static int append_one(struct string_list *list,
break;
}
if ((flags & STRING_LIST_SPLIT_NONEMPTY) && (end <= p))
return 0;
if (in_place) {
*((char *)end) = '\0';
string_list_append(list, p);