summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e593638)
raw | patch | inline | side by side (parent: e593638)
author | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Fri, 20 May 2005 16:09:18 +0000 (09:09 -0700) | ||
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | |
Fri, 20 May 2005 16:09:18 +0000 (09:09 -0700) |
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.
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.
cache.h | patch | blob | history | |
read-cache.c | patch | blob | history |
index 2cfaa1959d4fd1a7581718e770f28a6f754f4816..28e3dbddcabbbff0f246a21114f27e1e5721ce04 100644 (file)
--- a/cache.h
+++ b/cache.h
extern void die(const char *err, ...);
extern int error(const char *err, ...);
+extern int base_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 void *read_object_with_reference(const unsigned char *sha1,
diff --git a/read-cache.c b/read-cache.c
index 732f483cda5cf88db59470fd17cc219580f12409..b3eec846731b3c3b8b61f94ba0dff3e80fc1407d 100644 (file)
--- a/read-cache.c
+++ b/read-cache.c
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;