From: Junio C Hamano <gitster@pobox.com>
To: Christian Couder <chriscool@tuxfamily.org>
Cc: git@vger.kernel.org, Avery Pennarun <apenwarr@gmail.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH] builtin/remote: remove postfixcmp() and use suffixcmp() instead
Date: Mon, 04 Nov 2013 11:19:43 -0800 [thread overview]
Message-ID: <xmqqbo20ynxs.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <20131103201303.14446.7508.chriscool@tuxfamily.org> (Christian Couder's message of "Sun, 03 Nov 2013 21:13:02 +0100")
Christian Couder <chriscool@tuxfamily.org> writes:
> Commit 8cc5b290 (git merge -X<option>, 25 Nov 2009) introduced
> suffixcmp() with nearly the same implementation as postfixcmp()
> that already existed since commit 211c8968 (Make git-remote a
> builtin, 29 Feb 2008).
This "nearly the same" piqued my curiosity ;-)
The postfixcmp() you are removing will say "f" > ".txt" while
suffixcmp() will say "f" < ".txt".
As postfixcmp() is only used to compare for equality, the
distinction does not matter and does not affect the correctness of
this patch, but I am not sure which answer is more correct.
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.
> As postfixcmp() has always been static in builtin/remote.c
> and is used nowhere else, it makes more sense to remove it
> and use suffixcmp() instead in builtin/remote.c, rather than
> to remove suffixcmp().
>
> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> ---
> builtin/remote.c | 14 +++-----------
> 1 file changed, 3 insertions(+), 11 deletions(-)
>
> diff --git a/builtin/remote.c b/builtin/remote.c
> index 4e14891..9b3a98e 100644
> --- a/builtin/remote.c
> +++ b/builtin/remote.c
> @@ -80,14 +80,6 @@ static int verbose;
> static int show_all(void);
> static int prune_remote(const char *remote, int dry_run);
>
> -static inline int postfixcmp(const char *string, const char *postfix)
> -{
> - int len1 = strlen(string), len2 = strlen(postfix);
> - if (len1 < len2)
> - return 1;
> - return strcmp(string + len1 - len2, postfix);
> -}
> -
> static int fetch_remote(const char *name)
> {
> const char *argv[] = { "fetch", name, NULL, NULL };
> @@ -277,13 +269,13 @@ static int config_read_branches(const char *key, const char *value, void *cb)
> enum { REMOTE, MERGE, REBASE } type;
>
> key += 7;
> - if (!postfixcmp(key, ".remote")) {
> + if (!suffixcmp(key, ".remote")) {
> name = xstrndup(key, strlen(key) - 7);
> type = REMOTE;
> - } else if (!postfixcmp(key, ".merge")) {
> + } else if (!suffixcmp(key, ".merge")) {
> name = xstrndup(key, strlen(key) - 6);
> type = MERGE;
> - } else if (!postfixcmp(key, ".rebase")) {
> + } else if (!suffixcmp(key, ".rebase")) {
> name = xstrndup(key, strlen(key) - 7);
> type = REBASE;
> } else
next prev parent reply other threads:[~2013-11-04 19:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-03 20:13 [PATCH] builtin/remote: remove postfixcmp() and use suffixcmp() instead Christian Couder
2013-11-04 17:56 ` Jonathan Nieder
2013-11-04 19:19 ` Junio C Hamano [this message]
2013-11-04 20:16 ` Christian Couder
2013-11-04 20:21 ` Junio C Hamano
2013-11-04 22:17 ` Johannes Schindelin
2013-11-04 22:37 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqbo20ynxs.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=apenwarr@gmail.com \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.