diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/path.c | 19 |
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 */ |