aboutsummaryrefslogtreecommitdiffstats
path: root/read-cache.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-20 09:09:18 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-20 09:09:18 -0700
commit958ba6c96eb58b359c855c9d07e3e45072f0503e (patch)
tree0d9f3f853998315a6d6abd045b5de32b074066c8 /read-cache.c
parente59363822f7026896209a9e986c6bf80b10ab37a (diff)
downloadgit-958ba6c96eb58b359c855c9d07e3e45072f0503e.tar.gz
Introduce "base_name_compare()" helper function
This one compares two pathnames that may be partial basenames, not full paths. We need to get the path sorting right, since a directory name will sort as if it had the final '/' at the end.
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/read-cache.c b/read-cache.c
index 732f483cda..b3eec84673 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -74,6 +74,25 @@ int ce_match_stat(struct cache_entry *ce, struct stat *st)
return changed;
}
+int base_name_compare(const char *name1, int len1, int mode1,
+ const char *name2, int len2, int mode2)
+{
+ unsigned char c1, c2;
+ int len = len1 < len2 ? len1 : len2;
+ int cmp;
+
+ cmp = memcmp(name1, name2, len);
+ if (cmp)
+ return cmp;
+ c1 = name1[len];
+ c2 = name2[len];
+ if (!c1 && S_ISDIR(mode1))
+ c1 = '/';
+ if (!c2 && S_ISDIR(mode2))
+ c2 = '/';
+ return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0;
+}
+
int cache_name_compare(const char *name1, int flags1, const char *name2, int flags2)
{
int len1 = flags1 & CE_NAMEMASK;