Commit 7bc3d0c86d4f35048063f7f1466567163b497db2

Vicent Martí 2011-08-09T17:04:48

Merge pull request #361 from nulltoken/ntk/fix/wrap-strcmp util: Add git__strcmp_cb() wrapper

diff --git a/src/refs.c b/src/refs.c
index beb98a7..2e54668 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -503,7 +503,7 @@ static int packed_load(git_repository *repo)
 		ref_cache->packfile = git_hashtable_alloc(
 			default_table_size,
 			reftable_hash,
-			(git_hash_keyeq_ptr)strcmp);
+			(git_hash_keyeq_ptr)(&git__strcmp_cb));
 
 		if (ref_cache->packfile == NULL) {
 			error = GIT_ENOMEM;
@@ -1609,7 +1609,7 @@ int git_repository__refcache_init(git_refcache *refs)
 	refs->loose_cache = git_hashtable_alloc(
 		default_table_size,
 		reftable_hash,
-		(git_hash_keyeq_ptr)strcmp);
+		(git_hash_keyeq_ptr)(&git__strcmp_cb));
 
 	/* packfile loaded lazily */
 	refs->packfile = NULL;
@@ -1752,6 +1752,4 @@ int git_reference__normalize_name(char *buffer_out, size_t out_size, const char 
 int git_reference__normalize_name_oid(char *buffer_out, size_t out_size, const char *name)
 {
 	return normalize_name(buffer_out, out_size, name, 1);
-}
-
-
+}
\ No newline at end of file
diff --git a/src/transport_local.c b/src/transport_local.c
index 350f2ea..4e0ac6f 100644
--- a/src/transport_local.c
+++ b/src/transport_local.c
@@ -14,13 +14,6 @@ typedef struct {
 	git_vector *refs;
 } transport_local;
 
-static int cmp_refs(const void *a, const void *b)
-{
-	const char *stra = (const char *)a;
-	const char *strb = (const char *)b;
-	return strcmp(stra, strb);
-}
-
 /*
  * Try to open the url as a git directory. The direction doesn't
  * matter in this case because we're calulating the heads ourselves.
@@ -147,7 +140,7 @@ static int local_ls(git_transport *transport, git_headarray *array)
 		return error;
 
 	/* Sort the references first */
-	git__tsort((void **)refs.strings, refs.count, &cmp_refs);
+	git__tsort((void **)refs.strings, refs.count, &git__strcmp_cb);
 
 	/* Add HEAD */
 	error = add_ref(GIT_HEAD_FILE, repo, vec);
diff --git a/src/util.c b/src/util.c
index a51cbe6..57274b0 100644
--- a/src/util.c
+++ b/src/util.c
@@ -355,3 +355,16 @@ void **git__bsearch(const void *key, void **base, size_t nmemb, int (*compar)(co
         return NULL;
 }
 
+/**
+ * A strcmp wrapper
+ * 
+ * We don't want direct pointers to the CRT on Windows, we may
+ * get stdcall conflicts.
+ */
+int git__strcmp_cb(const void *a, const void *b)
+{
+	const char *stra = (const char *)a;
+	const char *strb = (const char *)b;
+
+	return strcmp(stra, strb);
+}
\ No newline at end of file
diff --git a/src/util.h b/src/util.h
index e78b2cd..18929af 100644
--- a/src/util.h
+++ b/src/util.h
@@ -120,4 +120,6 @@ extern void git__tsort(void **dst, size_t size, int (*cmp)(const void *, const v
 extern void **git__bsearch(const void *key, void **base, size_t nmemb,
 	int (*compar)(const void *, const void *));
 
+extern int git__strcmp_cb(const void *a, const void *b);
+
 #endif /* INCLUDE_util_h__ */