From: Jeremiah Mahler <jmmahler@gmail.com>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: "Torsten Bögershausen" <tboegi@web.de>,
git@vger.kernel.org, "Jeremiah Mahler" <jmmahler@gmail.com>
Subject: [PATCH v3 1/5] cache: rename cache_name_compare() to name_compare()
Date: Wed, 18 Jun 2014 11:45:13 -0700 [thread overview]
Message-ID: <1403117117-10384-2-git-send-email-jmmahler@gmail.com> (raw)
In-Reply-To: <1403117117-10384-1-git-send-email-jmmahler@gmail.com>
The cache_name_compare() function is not specific to a cache.
Make its name more general by renaming it to name_compare().
Simplify cache_name_stage_compare() via name_compare().
Where lengths are involved, change int to size_t.
Signed-off-by: Jeremiah Mahler <jmmahler@gmail.com>
---
cache.h | 2 +-
read-cache.c | 23 +++++++++++++----------
2 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/cache.h b/cache.h
index c498a30..e3205fe 100644
--- a/cache.h
+++ b/cache.h
@@ -1027,7 +1027,7 @@ extern int validate_headref(const char *ref);
extern int base_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2);
extern int df_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2);
-extern int cache_name_compare(const char *name1, int len1, const char *name2, int len2);
+extern int name_compare(const char *name1, size_t len1, const char *name2, size_t len2);
extern int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2);
extern void *read_object_with_reference(const unsigned char *sha1,
diff --git a/read-cache.c b/read-cache.c
index 9f56d76..158241d 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -434,18 +434,26 @@ int df_name_compare(const char *name1, int len1, int mode1,
return c1 - c2;
}
-int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2)
+int name_compare(const char *name1, size_t len1, const char *name2, size_t len2)
{
- int len = len1 < len2 ? len1 : len2;
- int cmp;
-
- cmp = memcmp(name1, name2, len);
+ size_t min_len = (len1 < len2) ? len1 : len2;
+ int cmp = memcmp(name1, name2, min_len);
if (cmp)
return cmp;
if (len1 < len2)
return -1;
if (len1 > len2)
return 1;
+ return 0;
+}
+
+int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2)
+{
+ int cmp;
+
+ cmp = name_compare(name1, len1, name2, len2);
+ if (cmp)
+ return cmp;
if (stage1 < stage2)
return -1;
@@ -454,11 +462,6 @@ int cache_name_stage_compare(const char *name1, int len1, int stage1, const char
return 0;
}
-int cache_name_compare(const char *name1, int len1, const char *name2, int len2)
-{
- return cache_name_stage_compare(name1, len1, 0, name2, len2, 0);
-}
-
static int index_name_stage_pos(const struct index_state *istate, const char *name, int namelen, int stage)
{
int first, last;
--
2.0.0
next prev parent reply other threads:[~2014-06-18 18:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-18 18:45 [PATCH v3 0/5] cleanup duplicate name_compare() functions Jeremiah Mahler
2014-06-18 18:45 ` Jeremiah Mahler [this message]
2014-06-18 19:11 ` [PATCH v3 1/5] cache: rename cache_name_compare() to name_compare() Jonathan Nieder
2014-06-18 18:45 ` [PATCH v3 2/5] tree-walk.c: remove name_compare() function Jeremiah Mahler
2014-06-18 19:03 ` Jonathan Nieder
2014-06-19 8:04 ` Jeremiah Mahler
2014-06-18 18:45 ` [PATCH v3 3/5] unpack-trees.c: " Jeremiah Mahler
2014-06-18 19:04 ` Jonathan Nieder
2014-06-18 18:45 ` [PATCH v3 4/5] dir.c: rename to name_compare() Jeremiah Mahler
2014-06-18 19:09 ` Jonathan Nieder
2014-06-18 18:45 ` [PATCH v3 5/5] name-hash.c: " Jeremiah Mahler
2014-06-18 19:10 ` Jonathan Nieder
2014-06-18 19:14 ` [PATCH v3 0/5] cleanup duplicate name_compare() functions Jonathan Nieder
2014-06-19 8:04 ` Jeremiah Mahler
2014-06-19 8:54 ` Jeff King
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=1403117117-10384-2-git-send-email-jmmahler@gmail.com \
--to=jmmahler@gmail.com \
--cc=git@vger.kernel.org \
--cc=jrnieder@gmail.com \
--cc=tboegi@web.de \
/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).