mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-05 20:11:17 +00:00
khash: avoid using kh_put
directly
This commit is contained in:
parent
a8cd560b10
commit
f31cb45ad2
@ -294,7 +294,7 @@ static int store_object(git_indexer *idx)
|
||||
git_oid_cpy(&pentry->sha1, &oid);
|
||||
pentry->offset = entry_start;
|
||||
|
||||
k = kh_put(oid, idx->pack->idx_cache, &pentry->sha1, &error);
|
||||
k = git_oidmap_put(idx->pack->idx_cache, &pentry->sha1, &error);
|
||||
if (error == -1) {
|
||||
git__free(pentry);
|
||||
giterr_set_oom();
|
||||
@ -349,7 +349,7 @@ static int save_entry(git_indexer *idx, struct entry *entry, struct git_pack_ent
|
||||
}
|
||||
|
||||
pentry->offset = entry_start;
|
||||
k = kh_put(oid, idx->pack->idx_cache, &pentry->sha1, &error);
|
||||
k = git_oidmap_put(idx->pack->idx_cache, &pentry->sha1, &error);
|
||||
|
||||
if (error <= 0) {
|
||||
giterr_set(GITERR_INDEXER, "cannot insert object into pack");
|
||||
|
@ -41,7 +41,7 @@ static int impl__write(git_odb_backend *_backend, const git_oid *oid, const void
|
||||
size_t alloc_len;
|
||||
int rval;
|
||||
|
||||
pos = kh_put(oid, db->objects, oid, &rval);
|
||||
pos = git_oidmap_put(db->objects, oid, &rval);
|
||||
if (rval < 0)
|
||||
return -1;
|
||||
|
||||
|
@ -38,6 +38,8 @@ typedef khash_t(off) git_offmap;
|
||||
#define git_offmap_set_value_at(h, idx, v) kh_val(h, idx) = v
|
||||
#define git_offmap_delete_at(h, idx) kh_del(off, h, idx)
|
||||
|
||||
#define git_offmap_put(h, k, err) kh_put(off, h, k, err)
|
||||
|
||||
#define git_offmap_insert(h, key, val, rval) do { \
|
||||
khiter_t __pos = kh_put(off, h, key, &rval); \
|
||||
if (rval >= 0) { \
|
||||
|
@ -43,6 +43,8 @@ GIT_INLINE(khint_t) git_oidmap_hash(const git_oid *oid)
|
||||
#define git_oidmap_value_at(h, idx) kh_val(h, idx)
|
||||
#define git_oidmap_delete_at(h, idx) kh_del(oid, h, idx)
|
||||
|
||||
#define git_oidmap_put(h, k, err) kh_put(oid, h, k, err)
|
||||
|
||||
#define git_oidmap_insert(h, key, val, rval) do { \
|
||||
khiter_t __pos = kh_put(oid, h, key, &rval); \
|
||||
if (rval >= 0) { \
|
||||
|
@ -199,7 +199,7 @@ static void rehash(git_packbuilder *pb)
|
||||
|
||||
git_oidmap_clear(pb->object_ix);
|
||||
for (i = 0, po = pb->object_list; i < pb->nr_objects; i++, po++) {
|
||||
pos = kh_put(oid, pb->object_ix, &po->id, &ret);
|
||||
pos = git_oidmap_put(pb->object_ix, &po->id, &ret);
|
||||
git_oidmap_value_at(pb->object_ix, pos) = po;
|
||||
}
|
||||
}
|
||||
@ -246,7 +246,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
|
||||
git_oid_cpy(&po->id, oid);
|
||||
po->hash = name_hash(name);
|
||||
|
||||
pos = kh_put(oid, pb->object_ix, &po->id, &ret);
|
||||
pos = git_oidmap_put(pb->object_ix, &po->id, &ret);
|
||||
if (ret < 0) {
|
||||
giterr_set_oom();
|
||||
return ret;
|
||||
|
@ -169,7 +169,7 @@ static int cache_add(
|
||||
while (cache->memory_used + base->len > cache->memory_limit)
|
||||
free_lowest_entry(cache);
|
||||
|
||||
k = kh_put(off, cache->entries, offset, &error);
|
||||
k = git_offmap_put(cache->entries, offset, &error);
|
||||
assert(error != 0);
|
||||
git_oidmap_value_at(cache->entries, k) = entry;
|
||||
cache->memory_used += entry->raw.len;
|
||||
|
@ -35,7 +35,7 @@ git_commit_list_node *git_revwalk__commit_lookup(
|
||||
|
||||
git_oid_cpy(&commit->oid, oid);
|
||||
|
||||
pos = kh_put(oid, walk->commits, &commit->oid, &ret);
|
||||
pos = git_oidmap_put(walk->commits, &commit->oid, &ret);
|
||||
assert(ret != 0);
|
||||
git_oidmap_value_at(walk->commits, pos) = commit;
|
||||
|
||||
|
@ -294,7 +294,7 @@ int git_sortedcache_upsert(void **out, git_sortedcache *sc, const char *key)
|
||||
item_key = ((char *)item) + sc->item_path_offset;
|
||||
memcpy(item_key, key, keylen);
|
||||
|
||||
pos = kh_put(str, sc->map, item_key, &error);
|
||||
pos = git_strmap_put(sc->map, item_key, &error);
|
||||
if (error < 0)
|
||||
goto done;
|
||||
|
||||
|
@ -42,6 +42,8 @@ typedef khiter_t git_strmap_iter;
|
||||
#define git_strmap_set_value_at(h, idx, v) kh_val(h, idx) = v
|
||||
#define git_strmap_delete_at(h, idx) kh_del(str, h, idx)
|
||||
|
||||
#define git_strmap_put(h, k, err) kh_put(str, h, k, err)
|
||||
|
||||
#define git_strmap_insert(h, key, val, rval) do { \
|
||||
khiter_t __pos = kh_put(str, h, key, &rval); \
|
||||
if (rval >= 0) { \
|
||||
|
@ -329,7 +329,7 @@ static int submodule_get_or_create(git_submodule **out, git_repository *repo, gi
|
||||
if ((error = submodule_alloc(&sm, repo, name)) < 0)
|
||||
return error;
|
||||
|
||||
pos = kh_put(str, map, sm->name, &error);
|
||||
pos = git_strmap_put(map, sm->name, &error);
|
||||
/* nobody can beat us to adding it */
|
||||
assert(error != 0);
|
||||
if (error < 0) {
|
||||
|
@ -36,7 +36,7 @@ void test_core_oidmap__basic(void)
|
||||
pos = git_oidmap_lookup_index(map, &items[i].oid);
|
||||
cl_assert(!git_oidmap_valid_index(map, pos));
|
||||
|
||||
pos = kh_put(oid, map, &items[i].oid, &ret);
|
||||
pos = git_oidmap_put(map, &items[i].oid, &ret);
|
||||
cl_assert(ret != 0);
|
||||
|
||||
git_oidmap_value_at(map, pos) = &items[i];
|
||||
@ -90,7 +90,7 @@ void test_core_oidmap__hash_collision(void)
|
||||
pos = git_oidmap_lookup_index(map, &items[i].oid);
|
||||
cl_assert(!git_oidmap_valid_index(map, pos));
|
||||
|
||||
pos = kh_put(oid, map, &items[i].oid, &ret);
|
||||
pos = git_oidmap_put(map, &items[i].oid, &ret);
|
||||
cl_assert(ret != 0);
|
||||
|
||||
git_oidmap_value_at(map, pos) = &items[i];
|
||||
|
Loading…
Reference in New Issue
Block a user