Re: [PATCH v2] refs: use skip_prefix() in ref_is_hidden()
- From
Jeff King <peff@peff.net>
- Date
- Jul 24, 2017, 16:09 UTC
- Message-ID
- <20170724160938.bpdqf64p2ja2vvbd@sigill.intra.peff.net>
- In-Reply-To
- <20170722043912.32118-1-chriscool@tuxfamily.org>
On Sat, Jul 22, 2017 at 06:39:12AM +0200, Christian Couder wrote:
Show 12 quoted lines
> @@ -1175,10 +1175,9 @@ int ref_is_hidden(const char *refname, const char *refname_full) > } > > /* refname can be NULL when namespaces are used. */ > - if (!subject || !starts_with(subject, match)) > - continue; > - len = strlen(match); > - if (!subject[len] || subject[len] == '/') > + if (subject && > + skip_prefix(subject, match, &p) && > + (!*p || *p == '/')) > return !neg;
This looks good to me.
I seem to recall running across a similar pattern elsewhere, where a caller wanted either an exact match, or a match ending with a particular character. We could add one more helper like:
if (subject && skip_prefix_with_sep(subject, match, '/', &p)) return !neg;
But I don't offhand recall where that other place was, and it's not like it's saving a huge amount of complexity in the caller. So I'll file it away in the back of my mind and see if it comes up a third time. ;)
-Peff