khash: avoid using `kh_foreach`/`kh_foreach_value` directly
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
diff --git a/src/cache.c b/src/cache.c
index e8fd207..e7a565e 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -53,7 +53,7 @@ void git_cache_dump_stats(git_cache *cache)
printf("Cache %p: %"PRIuZ" items cached, %"PRIdZ" bytes\n",
cache, git_cache_size(cache), cache->used_memory);
- kh_foreach_value(cache->map, object, {
+ git_oidmap_foreach_value(cache->map, object, {
char oid_str[9];
printf(" %s%c %s (%"PRIuZ")\n",
git_object_type2string(object->type),
@@ -84,7 +84,7 @@ static void clear_cache(git_cache *cache)
if (git_cache_size(cache) == 0)
return;
- kh_foreach_value(cache->map, evict, {
+ git_oidmap_foreach_value(cache->map, evict, {
git_cached_obj_decref(evict);
});
diff --git a/src/indexer.c b/src/indexer.c
index 606de2e..8b5fa6e 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -1106,8 +1106,9 @@ void git_indexer_free(git_indexer *idx)
if (idx->pack->idx_cache) {
struct git_pack_entry *pentry;
- kh_foreach_value(
- idx->pack->idx_cache, pentry, { git__free(pentry); });
+ git_oidmap_foreach_value(idx->pack->idx_cache, pentry, {
+ git__free(pentry);
+ });
git_oidmap_free(idx->pack->idx_cache);
}
diff --git a/src/odb_mempack.c b/src/odb_mempack.c
index 84ed9c1..b9bdf0b 100644
--- a/src/odb_mempack.c
+++ b/src/odb_mempack.c
@@ -149,7 +149,7 @@ void git_mempack_reset(git_odb_backend *_backend)
struct memory_packer_db *db = (struct memory_packer_db *)_backend;
struct memobject *object = NULL;
- kh_foreach_value(db->objects, object, {
+ git_oidmap_foreach_value(db->objects, object, {
git__free(object);
});
diff --git a/src/pack.c b/src/pack.c
index 243719d..0f2fa5c 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -78,13 +78,12 @@ static void free_cache_object(void *o)
static void cache_free(git_pack_cache *cache)
{
- khiter_t k;
+ git_pack_cache_entry *entry;
if (cache->entries) {
- for (k = kh_begin(cache->entries); k != kh_end(cache->entries); k++) {
- if (kh_exist(cache->entries, k))
- free_cache_object(kh_value(cache->entries, k));
- }
+ git_offmap_foreach_value(cache->entries, entry, {
+ free_cache_object(entry);
+ });
git_offmap_free(cache->entries);
cache->entries = NULL;
@@ -135,18 +134,13 @@ static void free_lowest_entry(git_pack_cache *cache)
git_pack_cache_entry *entry;
khiter_t k;
- for (k = kh_begin(cache->entries); k != kh_end(cache->entries); k++) {
- if (!kh_exist(cache->entries, k))
- continue;
-
- entry = kh_value(cache->entries, k);
-
+ git_offmap_foreach(cache->entries, k, entry, {
if (entry && entry->refcount.val == 0) {
cache->memory_used -= entry->raw.len;
kh_del(off, cache->entries, k);
free_cache_object(entry);
}
- }
+ });
}
static int cache_add(
diff --git a/src/revwalk.c b/src/revwalk.c
index 8c370bc..c5fdb7e 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -702,7 +702,7 @@ void git_revwalk_reset(git_revwalk *walk)
assert(walk);
- kh_foreach_value(walk->commits, commit, {
+ git_oidmap_foreach_value(walk->commits, commit, {
commit->seen = 0;
commit->in_degree = 0;
commit->topo_delay = 0;
diff --git a/src/transaction.c b/src/transaction.c
index 2c8a1e8..ffe374a 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -323,7 +323,6 @@ static int update_target(git_refdb *db, transaction_node *node)
int git_transaction_commit(git_transaction *tx)
{
transaction_node *node;
- git_strmap_iter pos;
int error = 0;
assert(tx);
@@ -335,11 +334,7 @@ int git_transaction_commit(git_transaction *tx)
return error;
}
- for (pos = kh_begin(tx->locks); pos < kh_end(tx->locks); pos++) {
- if (!git_strmap_has_data(tx->locks, pos))
- continue;
-
- node = git_strmap_value_at(tx->locks, pos);
+ git_strmap_foreach_value(tx->locks, node, {
if (node->reflog) {
if ((error = tx->db->backend->reflog_write(tx->db->backend, node->reflog)) < 0)
return error;
@@ -349,7 +344,7 @@ int git_transaction_commit(git_transaction *tx)
if ((error = update_target(tx->db, node)) < 0)
return error;
}
- }
+ });
return 0;
}
@@ -358,7 +353,6 @@ void git_transaction_free(git_transaction *tx)
{
transaction_node *node;
git_pool pool;
- git_strmap_iter pos;
assert(tx);
@@ -373,16 +367,12 @@ void git_transaction_free(git_transaction *tx)
}
/* start by unlocking the ones we've left hanging, if any */
- for (pos = kh_begin(tx->locks); pos < kh_end(tx->locks); pos++) {
- if (!git_strmap_has_data(tx->locks, pos))
- continue;
-
- node = git_strmap_value_at(tx->locks, pos);
+ git_strmap_foreach_value(tx->locks, node, {
if (node->committed)
continue;
git_refdb_unlock(tx->db, node->payload, false, false, NULL, NULL, NULL);
- }
+ });
git_refdb_free(tx->db);
git_strmap_free(tx->locks);