]> git.ipfire.org Git - thirdparty/git.git/commitdiff
oidmap: add size function
authorJeff King <peff@peff.net>
Mon, 12 May 2025 18:51:30 +0000 (14:51 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 May 2025 20:06:26 +0000 (13:06 -0700)
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit-graph.c
oidmap.h
replace-object.h

index 6394752b0b0868b4337cf36f5747c2a9b36c364c..1a74e1e1baffbe3e99db3f34548ddfd3a7a9e63f 100644 (file)
@@ -222,7 +222,7 @@ static int commit_graph_compatible(struct repository *r)
 
        if (replace_refs_enabled(r)) {
                prepare_replace_object(r);
-               if (hashmap_get_size(&r->objects->replace_map->map))
+               if (oidmap_get_size(r->objects->replace_map))
                        return 0;
        }
 
index 603ae1adbcc0587cbcddd654eb87ef143da10fdb..67fb32290f1c494a36be653a908f37b58f5e6202 100644 (file)
--- a/oidmap.h
+++ b/oidmap.h
@@ -67,6 +67,10 @@ void *oidmap_put(struct oidmap *map, void *entry);
  */
 void *oidmap_remove(struct oidmap *map, const struct object_id *key);
 
+static inline unsigned int oidmap_get_size(struct oidmap *map)
+{
+       return hashmap_get_size(&map->map);
+}
 
 struct oidmap_iter {
        struct hashmap_iter h_iter;
index ba478eb30c47a639c679ba0cfd3d42a3932b0a1c..4226376534b22e7b0293063f2637f0dd3a401055 100644 (file)
@@ -47,7 +47,7 @@ static inline const struct object_id *lookup_replace_object(struct repository *r
 {
        if (!replace_refs_enabled(r) ||
            (r->objects->replace_map_initialized &&
-            r->objects->replace_map->map.tablesize == 0))
+            oidmap_get_size(r->objects->replace_map) == 0))
                return oid;
        return do_lookup_replace_object(r, oid);
 }