From: Christian Couder <chriscool@tuxfamily.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>,
Antoine Pelisse <apelisse@gmail.com>,
Avery Pennarun <apenwarr@gmail.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Jonathan Nieder <jrnieder@gmail.com>, Max Horn <max@quendi.de>,
Andreas Ericsson <ae@op5.se>
Subject: [PATCH 2/5] builtin/remote: remove postfixcmp() and use suffixcmp() instead
Date: Sun, 01 Dec 2013 08:49:15 +0100 [thread overview]
Message-ID: <20131201074919.3042.71383.chriscool@tuxfamily.org> (raw)
In-Reply-To: <20131201074818.3042.57357.chriscool@tuxfamily.org>
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).
The only difference between the two implementations is that,
when the string is smaller than the suffix, one implementation
returns 1 while the other one returns -1.
But, as postfixcmp() is only used to compare for equality, the
distinction does not matter and does not affect the correctness of
this patch.
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().
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
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
--
1.8.4.1.561.g12affca
next prev parent reply other threads:[~2013-12-01 7:50 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-01 7:49 [PATCH 0/5] use starts_with() and ends_with() Christian Couder
2013-12-01 7:49 ` [PATCH 1/5] environment: normalize use of prefixcmp() by removing " != 0" Christian Couder
2013-12-01 7:49 ` Christian Couder [this message]
2013-12-01 7:49 ` [PATCH 3/5] strbuf: introduce starts_with() and ends_with() Christian Couder
2013-12-01 7:49 ` [PATCH 5/5] strbuf: remove prefixcmp() and suffixcmp() Christian Couder
2013-12-02 15:09 ` [PATCH 0/5] use starts_with() and ends_with() Jeff King
2013-12-02 18:32 ` Junio C Hamano
2013-12-02 19:29 ` Christian Couder
2013-12-02 19:32 ` Antoine Pelisse
2013-12-03 6:06 ` Christian Couder
[not found] ` <20131201074919.3042.92026.chriscool@tuxfamily.org>
[not found] ` <CAP8UFD0jg_Vr7Zf+DiMX9RG6vmmQvmk2NvmL7j=MC-x3fLOOBA@mail.gmail.com>
2013-12-03 12:46 ` Fwd: [PATCH 4/5] Replace {pre,suf}fixcmp() with {starts,ends}_with() Jeff King
2013-12-03 20:24 ` Christian Couder
2013-12-04 19:45 ` Jeff King
2013-12-04 20:51 ` Junio C Hamano
2013-12-04 22:02 ` Junio C Hamano
2013-12-05 7:19 ` Christian Couder
2013-12-05 18:04 ` 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=20131201074919.3042.71383.chriscool@tuxfamily.org \
--to=chriscool@tuxfamily.org \
--cc=Johannes.Schindelin@gmx.de \
--cc=ae@op5.se \
--cc=apelisse@gmail.com \
--cc=apenwarr@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=max@quendi.de \
--cc=peff@peff.net \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).