Re: [PATCH] builtin/remote: remove postfixcmp() and use suffixcmp() instead
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Nov 4, 2013, 22:17 UTC
- Message-ID
- <alpine.DEB.1.00.1311042316520.1191@s15462909.onlinehome-server.info>
- In-Reply-To
- <xmqq7gcnzznt.fsf@gitster.dls.corp.google.com>
Hi Junio,
On Mon, 4 Nov 2013, Junio C Hamano wrote:
Show 27 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
> > I do not think anybody sane uses prefixcmp() or suffixcmp() for
> > anything but checking with zero; in other words, I suspect that all
> > uses of Xcmp() can be replaced with !!Xcmp(), so as a separate
> > clean-up patch, we may at least want to make it clear that the
> > callers should not expect anything but "does str have sfx as its
> > suffix, yes or no?" by doing something like this:
> >
> > int suffixcmp(const char *str, const char *suffix)
> > {
> > int len = strlen(str), suflen = strlen(suffix);
> > if (len < suflen)
> > return -1;
> > else
> > - return strcmp(str + len - suflen, suffix);
> > + return !!strcmp(str + len - suflen, suffix);
> > }
> >
> > I am not absolutely sure about doing the same to prefixcmp(),
> > though. It could be used for ordering, even though no existing code
> > seems to do so.
>
> I just realized why this suggestion is incomplete; if we were to go
> this route, we should rename the function to has_suffix() or
> something. anything-cmp() ought to be usable as an ordering
> comparison function, but suffixcmp() clearly isn't.I have to admit that I do not understand why a change in suffixcmp()'s behavior is needed.
Ciao, Johannes