Commit ccef1c9dc22b07398970f26eb9fd3be669db7734

Vicent Marti 2011-02-27T22:09:36

Move the path comparison method to fileops.c Signed-off-by: Vicent Marti <tanoku@gmail.com>

diff --git a/src/fileops.c b/src/fileops.c
index 602862c..9938011 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -493,3 +493,22 @@ int gitfo_prettify_file_path(char *buffer_out, const char *path)
 
 	return GIT_SUCCESS;
 }
+
+int gitfo_cmp_path(const char *name1, int len1, int isdir1,
+		const char *name2, int len2, int isdir2)
+{
+	int 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;
+}
+
diff --git a/src/fileops.h b/src/fileops.h
index d333805..16e7103 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -131,6 +131,10 @@ extern int gitfo_write_cached(gitfo_cache *ioc, void *buf, size_t len);
 extern int gitfo_flush_cached(gitfo_cache *ioc);
 extern int gitfo_close_cached(gitfo_cache *ioc);
 
+
+extern int gitfo_cmp_path(const char *name1, int len1, int isdir1,
+		const char *name2, int len2, int isdir2);
+
 /**
  * Clean up a provided absolute or relative directory path.
  * 
diff --git a/src/tree.c b/src/tree.c
index e8cf179..a23be91 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -40,30 +40,12 @@ int entry_search_cmp(const void *key, const void *array_member)
 	return strcmp(filename, entry->filename);
 }
 
-static int cache_name_compare(const char *name1, int len1, int isdir1,
-                              const char *name2, int len2, int isdir2)
-{
-	int 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;
-}
-
 int entry_sort_cmp(const void *a, const void *b)
 {
 	const git_tree_entry *entry_a = *(const git_tree_entry **)(a);
 	const git_tree_entry *entry_b = *(const git_tree_entry **)(b);
 
-	return cache_name_compare(entry_a->filename, strlen(entry_a->filename),
+	return gitfo_cmp_path(entry_a->filename, strlen(entry_a->filename),
                                   entry_a->attr & 040000,
                                   entry_b->filename, strlen(entry_b->filename),
                                   entry_b->attr & 040000);