Skip to content

Commit 5961847

Browse files
peffgitster
authored andcommitted
oidmap: add size function
Callers which want to know how many items are in an oidmap have to look at the underlying hashmap struct, leaking an implementation detail. Let's provide a type-appropriate wrapper and use it. Note in the call from lookup_replace_object(), the caller was actually looking at the hashmap's tablesize parameter (the allocated size of the table) rather than hashmap_get_size(), the number of items in the table. This probably should have been checking the number of items all along, but the two are functionally equivalent here since we only add to the map and never remove anything. Thus if there was any allocation, it was because there is at least one item. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2744646 commit 5961847

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

commit-graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static int commit_graph_compatible(struct repository *r)
222222

223223
if (replace_refs_enabled(r)) {
224224
prepare_replace_object(r);
225-
if (hashmap_get_size(&r->objects->replace_map->map))
225+
if (oidmap_get_size(r->objects->replace_map))
226226
return 0;
227227
}
228228

oidmap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ void *oidmap_put(struct oidmap *map, void *entry);
6767
*/
6868
void *oidmap_remove(struct oidmap *map, const struct object_id *key);
6969

70+
static inline unsigned int oidmap_get_size(struct oidmap *map)
71+
{
72+
return hashmap_get_size(&map->map);
73+
}
7074

7175
struct oidmap_iter {
7276
struct hashmap_iter h_iter;

replace-object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static inline const struct object_id *lookup_replace_object(struct repository *r
4747
{
4848
if (!replace_refs_enabled(r) ||
4949
(r->objects->replace_map_initialized &&
50-
r->objects->replace_map->map.tablesize == 0))
50+
oidmap_get_size(r->objects->replace_map) == 0))
5151
return oid;
5252
return do_lookup_replace_object(r, oid);
5353
}

0 commit comments

Comments
 (0)