Re: [PATCH v2 6/7] string-list: optionally omit empty string pieces in string_list_split*()
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Aug 1, 2025, 08:47 UTC
- Message-ID
- <aIx_KAhKhGedQ0mV@pks.im>
- In-Reply-To
- <20250731224607.3942417-7-gitster@pobox.com>
On Thu, Jul 31, 2025 at 03:46:05PM -0700, Junio C Hamano wrote:
> Teach the unified split_string() machinery a new flag bit, > STRING_LIST_SPLIT_NONEMPTY, to cause empty split pieces omitted from
s/omitted/to be &/
Show 19 quoted lines
> the resulting string list. > > Signed-off-by: Junio C Hamano <gitster@pobox.com> > --- > string-list.c | 3 +++ > string-list.h | 3 +++ > t/unit-tests/u-string-list.c | 15 +++++++++++++++ > 3 files changed, 21 insertions(+) > > diff --git a/string-list.c b/string-list.c > index 86a309f8fb..343cf1ca90 100644 > --- a/string-list.c > +++ b/string-list.c > @@ -294,6 +294,9 @@ static int append_one(struct string_list *list, > break; > } > > + if ((flags & STRING_LIST_SPLIT_NONEMPTY) && (end <= p)) > + return 0;
Okay, this is where the return value of `append_one()` starts to make sense.
The condition for `end <= p` is probably overly defensive, as it shouldn't ever happen that `end < p`. We could make that a `BUG()`, but I'm not sure that's really worth it.
Patrick