Merge pull request #361 from nulltoken/ntk/fix/wrap-strcmp util: Add git__strcmp_cb() wrapper
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
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__ */