Skip to content

Commit f31cb45

Browse files
committed
khash: avoid using kh_put directly
1 parent a8cd560 commit f31cb45

File tree

11 files changed

+17
-11
lines changed

11 files changed

+17
-11
lines changed

src/indexer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ static int store_object(git_indexer *idx)
294294
git_oid_cpy(&pentry->sha1, &oid);
295295
pentry->offset = entry_start;
296296

297-
k = kh_put(oid, idx->pack->idx_cache, &pentry->sha1, &error);
297+
k = git_oidmap_put(idx->pack->idx_cache, &pentry->sha1, &error);
298298
if (error == -1) {
299299
git__free(pentry);
300300
giterr_set_oom();
@@ -349,7 +349,7 @@ static int save_entry(git_indexer *idx, struct entry *entry, struct git_pack_ent
349349
}
350350

351351
pentry->offset = entry_start;
352-
k = kh_put(oid, idx->pack->idx_cache, &pentry->sha1, &error);
352+
k = git_oidmap_put(idx->pack->idx_cache, &pentry->sha1, &error);
353353

354354
if (error <= 0) {
355355
giterr_set(GITERR_INDEXER, "cannot insert object into pack");

src/odb_mempack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static int impl__write(git_odb_backend *_backend, const git_oid *oid, const void
4141
size_t alloc_len;
4242
int rval;
4343

44-
pos = kh_put(oid, db->objects, oid, &rval);
44+
pos = git_oidmap_put(db->objects, oid, &rval);
4545
if (rval < 0)
4646
return -1;
4747

src/offmap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ typedef khash_t(off) git_offmap;
3838
#define git_offmap_set_value_at(h, idx, v) kh_val(h, idx) = v
3939
#define git_offmap_delete_at(h, idx) kh_del(off, h, idx)
4040

41+
#define git_offmap_put(h, k, err) kh_put(off, h, k, err)
42+
4143
#define git_offmap_insert(h, key, val, rval) do { \
4244
khiter_t __pos = kh_put(off, h, key, &rval); \
4345
if (rval >= 0) { \

src/oidmap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ GIT_INLINE(khint_t) git_oidmap_hash(const git_oid *oid)
4343
#define git_oidmap_value_at(h, idx) kh_val(h, idx)
4444
#define git_oidmap_delete_at(h, idx) kh_del(oid, h, idx)
4545

46+
#define git_oidmap_put(h, k, err) kh_put(oid, h, k, err)
47+
4648
#define git_oidmap_insert(h, key, val, rval) do { \
4749
khiter_t __pos = kh_put(oid, h, key, &rval); \
4850
if (rval >= 0) { \

src/pack-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static void rehash(git_packbuilder *pb)
199199

200200
git_oidmap_clear(pb->object_ix);
201201
for (i = 0, po = pb->object_list; i < pb->nr_objects; i++, po++) {
202-
pos = kh_put(oid, pb->object_ix, &po->id, &ret);
202+
pos = git_oidmap_put(pb->object_ix, &po->id, &ret);
203203
git_oidmap_value_at(pb->object_ix, pos) = po;
204204
}
205205
}
@@ -246,7 +246,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
246246
git_oid_cpy(&po->id, oid);
247247
po->hash = name_hash(name);
248248

249-
pos = kh_put(oid, pb->object_ix, &po->id, &ret);
249+
pos = git_oidmap_put(pb->object_ix, &po->id, &ret);
250250
if (ret < 0) {
251251
giterr_set_oom();
252252
return ret;

src/pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static int cache_add(
169169
while (cache->memory_used + base->len > cache->memory_limit)
170170
free_lowest_entry(cache);
171171

172-
k = kh_put(off, cache->entries, offset, &error);
172+
k = git_offmap_put(cache->entries, offset, &error);
173173
assert(error != 0);
174174
git_oidmap_value_at(cache->entries, k) = entry;
175175
cache->memory_used += entry->raw.len;

src/revwalk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ git_commit_list_node *git_revwalk__commit_lookup(
3535

3636
git_oid_cpy(&commit->oid, oid);
3737

38-
pos = kh_put(oid, walk->commits, &commit->oid, &ret);
38+
pos = git_oidmap_put(walk->commits, &commit->oid, &ret);
3939
assert(ret != 0);
4040
git_oidmap_value_at(walk->commits, pos) = commit;
4141

src/sortedcache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ int git_sortedcache_upsert(void **out, git_sortedcache *sc, const char *key)
294294
item_key = ((char *)item) + sc->item_path_offset;
295295
memcpy(item_key, key, keylen);
296296

297-
pos = kh_put(str, sc->map, item_key, &error);
297+
pos = git_strmap_put(sc->map, item_key, &error);
298298
if (error < 0)
299299
goto done;
300300

src/strmap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ typedef khiter_t git_strmap_iter;
4242
#define git_strmap_set_value_at(h, idx, v) kh_val(h, idx) = v
4343
#define git_strmap_delete_at(h, idx) kh_del(str, h, idx)
4444

45+
#define git_strmap_put(h, k, err) kh_put(str, h, k, err)
46+
4547
#define git_strmap_insert(h, key, val, rval) do { \
4648
khiter_t __pos = kh_put(str, h, key, &rval); \
4749
if (rval >= 0) { \

src/submodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ static int submodule_get_or_create(git_submodule **out, git_repository *repo, gi
329329
if ((error = submodule_alloc(&sm, repo, name)) < 0)
330330
return error;
331331

332-
pos = kh_put(str, map, sm->name, &error);
332+
pos = git_strmap_put(map, sm->name, &error);
333333
/* nobody can beat us to adding it */
334334
assert(error != 0);
335335
if (error < 0) {

0 commit comments

Comments
 (0)