summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorJeremiah Mahler <jmmahler@gmail.com>2014-06-20 02:06:44 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-06-20 17:12:14 (GMT)
commitccdd4a0f3c7c550526a980e93156f25a956497bc (patch)
tree84db06d840bf4600a30e6a6a2d784a12a09baa71 /dir.c
parentbe99ec97c8a1f94e723c6cc5331eff921ae49ed3 (diff)
downloadgit-ccdd4a0f3c7c550526a980e93156f25a956497bc.zip
git-ccdd4a0f3c7c550526a980e93156f25a956497bc.tar.gz
git-ccdd4a0f3c7c550526a980e93156f25a956497bc.tar.bz2
cleanup duplicate name_compare() functions
We often represent our strings as a counted string, i.e. a pair of the pointer to the beginning of the string and its length, and the string may not be NUL terminated to that length. To compare a pair of such counted strings, unpack-trees.c and read-cache.c implement their own name_compare() functions identically. In addition, the cache_name_compare() function in read-cache.c is nearly identical. The only difference is when one string is the prefix of the other string, in which case name_compare() returns -1/+1 to show which one is longer, and cache_name_compare() returns the difference of the lengths to show the same information. Unify these three functions by using the implementation from cache_name_compare(). This does not make any difference to the existing and future callers, as they must be paying attention only to the sign of the returned value (and not the magnitude) because the original implementations of these two functions return values returned by memcmp(3) when the one string is not a prefix of the other string, and the only thing memcmp(3) guarantees its callers is the sign of the returned value, not the magnitude. Signed-off-by: Jeremiah Mahler <jmmahler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/dir.c b/dir.c
index 797805d..e65888d 100644
--- a/dir.c
+++ b/dir.c
@@ -1354,8 +1354,7 @@ static int cmp_name(const void *p1, const void *p2)
const struct dir_entry *e1 = *(const struct dir_entry **)p1;
const struct dir_entry *e2 = *(const struct dir_entry **)p2;
- return cache_name_compare(e1->name, e1->len,
- e2->name, e2->len);
+ return name_compare(e1->name, e1->len, e2->name, e2->len);
}
static struct path_simplify *create_simplify(const char **pathspec)