summaryrefslogtreecommitdiff
path: root/src/refs.c
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2012-02-29 12:04:59 -0800
committerRussell Belfer <arrbee@arrbee.com>2012-03-02 15:51:55 -0800
commit854eccbb2d86c2910f9d98dc52f9ebd0e37c262a (patch)
treeb22048a02480598477cde9c41fc16d3967226d6b /src/refs.c
parent74fa4bfae37e9d7c9e35550c881b114d7a83c4fa (diff)
downloadlibgit2-854eccbb2d86c2910f9d98dc52f9ebd0e37c262a.tar.gz
Clean up GIT_UNUSED macros on all platforms
It turns out that commit 31e9cfc4cbcaf1b38cdd3dbe3282a8f57e5366a5 did not fix the GIT_USUSED behavior on all platforms. This commit walks through and really cleans things up more thoroughly, getting rid of the unnecessary stuff. To remove the use of some GIT_UNUSED, I ended up adding a couple of new iterators for hashtables that allow you to iterator just over keys or just over values. In making this change, I found a bug in the clar tests (where we were doing *count++ but meant to do (*count)++ to increment the value). I fixed that but then found the test failing because it was not really using an empty repo. So, I took some of the code that I wrote for iterator testing and moved it to clar_helpers.c, then made use of that to make it easier to open fixtures on a per test basis even within a single test file.
Diffstat (limited to 'src/refs.c')
-rw-r--r--src/refs.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/refs.c b/src/refs.c
index 2e1d92da2..f3388bf53 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -105,7 +105,7 @@ static int reference_alloc(
reference->name = git__strdup(name);
if (reference->name == NULL) {
- free(reference);
+ git__free(reference);
return GIT_ENOMEM;
}
@@ -222,7 +222,7 @@ static int loose_lookup(git_reference *ref)
return GIT_SUCCESS;
if (ref->flags & GIT_REF_SYMBOLIC) {
- free(ref->target.symbolic);
+ git__free(ref->target.symbolic);
ref->target.symbolic = NULL;
}
@@ -278,7 +278,8 @@ static int loose_lookup_to_packfile(
cleanup:
git_buf_free(&ref_file);
- free(ref);
+ git__free(ref);
+
return git__rethrow(error, "Failed to lookup loose reference");
}
@@ -420,7 +421,7 @@ static int packed_parse_oid(
return GIT_SUCCESS;
cleanup:
- free(ref);
+ git__free(ref);
return git__rethrow(error, "Failed to parse OID of packed reference");
}
@@ -495,7 +496,7 @@ static int packed_load(git_repository *repo)
error = git_hashtable_insert(ref_cache->packfile, ref->name, ref);
if (error < GIT_SUCCESS) {
- free(ref);
+ git__free(ref);
goto cleanup;
}
}
@@ -560,12 +561,12 @@ static int _dirent_loose_load(void *data, git_buf *full_path)
if (git_hashtable_insert2(
repository->references.packfile,
ref->name, ref, &old_ref) < GIT_SUCCESS) {
- free(ref);
+ git__free(ref);
return GIT_ENOMEM;
}
if (old_ref != NULL)
- free(old_ref);
+ git__free(old_ref);
}
return error == GIT_SUCCESS ?
@@ -773,9 +774,8 @@ static int packed_write(git_repository *repo)
/* Load all the packfile into a vector */
{
struct packref *reference;
- const void *GIT_UNUSED(_unused);
- GIT_HASHTABLE_FOREACH(repo->references.packfile, _unused, reference,
+ GIT_HASHTABLE_FOREACH_VALUE(repo->references.packfile, reference,
/* cannot fail: vector already has the right size */
git_vector_insert(&packing_list, reference);
);
@@ -929,7 +929,7 @@ static int packed_lookup(git_reference *ref)
return GIT_SUCCESS;
if (ref->flags & GIT_REF_SYMBOLIC) {
- free(ref->target.symbolic);
+ git__free(ref->target.symbolic);
ref->target.symbolic = NULL;
}
@@ -1513,12 +1513,11 @@ int git_reference_foreach(
/* list all the packed references first */
if (list_flags & GIT_REF_PACKED) {
const char *ref_name;
- void *GIT_UNUSED(_unused);
if ((error = packed_load(repo)) < GIT_SUCCESS)
return git__rethrow(error, "Failed to list references");
- GIT_HASHTABLE_FOREACH(repo->references.packfile, ref_name, _unused,
+ GIT_HASHTABLE_FOREACH_KEY(repo->references.packfile, ref_name,
if ((error = callback(ref_name, payload)) < GIT_SUCCESS)
return git__throw(error,
"Failed to list references. User callback failed");
@@ -1595,12 +1594,10 @@ void git_repository__refcache_free(git_refcache *refs)
assert(refs);
if (refs->packfile) {
- const void *GIT_UNUSED(_unused);
struct packref *reference;
- GIT_HASHTABLE_FOREACH(refs->packfile, _unused, reference,
- free(reference);
- );
+ GIT_HASHTABLE_FOREACH_VALUE(
+ refs->packfile, reference, git__free(reference));
git_hashtable_free(refs->packfile);
}