summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2012-06-19 00:59:04 +0200
committerVicent Marti <tanoku@gmail.com>2012-06-19 00:59:04 +0200
commit515a4c7c0634018097d3cd85f6a819dabe4cfd32 (patch)
tree2257e19ea245a9d7307e6c1ed4e8ac8bca173c41 /src
parentac8eac2f6632de6215d970b77b420601cedd6a91 (diff)
downloadlibgit2-515a4c7c0634018097d3cd85f6a819dabe4cfd32.tar.gz
tree: Proper path comparison logic
Diffstat (limited to 'src')
-rw-r--r--src/path.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/path.c b/src/path.c
index 1d85559a9..a6574b3de 100644
--- a/src/path.c
+++ b/src/path.c
@@ -468,19 +468,24 @@ int git_path_cmp(
const char *name1, size_t len1, int isdir1,
const char *name2, size_t len2, int isdir2)
{
+ unsigned char c1, c2;
size_t len = len1 < len2 ? len1 : len2;
int cmp;
cmp = memcmp(name1, name2, len);
if (cmp)
return cmp;
- if (len1 < len2)
- return (!isdir1 && !isdir2) ? -1 :
- (isdir1 ? '/' - name2[len1] : name2[len1] - '/');
- if (len1 > len2)
- return (!isdir1 && !isdir2) ? 1 :
- (isdir2 ? name1[len2] - '/' : '/' - name1[len2]);
- return 0;
+
+ c1 = name1[len];
+ c2 = name2[len];
+
+ if (c1 == '\0' && isdir1)
+ c1 = '/';
+
+ if (c2 == '\0' && isdir2)
+ c2 = '/';
+
+ return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0;
}
/* Taken from git.git */