]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb/source-inmemory: implement `count_objects()` callback
authorPatrick Steinhardt <ps@pks.im>
Fri, 10 Apr 2026 12:12:43 +0000 (14:12 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 14 May 2026 19:50:45 +0000 (04:50 +0900)
Implement the `count_objects()` callback function for the in-memory
source.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
odb/source-inmemory.c

index 44d9bbedeca6f2e5b770c1b7201ba95b40c43165..674dbcad3001a621e0608b823226dff0406de55a 100644 (file)
@@ -207,6 +207,25 @@ static int odb_source_inmemory_find_abbrev_len(struct odb_source *source,
        return ret;
 }
 
+static int count_objects_cb(const struct object_id *oid UNUSED,
+                           struct object_info *oi UNUSED,
+                           void *cb_data)
+{
+       unsigned long *counter = cb_data;
+       (*counter)++;
+       return 0;
+}
+
+static int odb_source_inmemory_count_objects(struct odb_source *source,
+                                            enum odb_count_objects_flags flags UNUSED,
+                                            unsigned long *out)
+{
+       struct odb_for_each_object_options opts = { 0 };
+       *out = 0;
+       return odb_source_inmemory_for_each_object(source, NULL, count_objects_cb,
+                                                  out, &opts);
+}
+
 static int odb_source_inmemory_write_object(struct odb_source *source,
                                            const void *buf, unsigned long len,
                                            enum object_type type,
@@ -314,6 +333,7 @@ struct odb_source_inmemory *odb_source_inmemory_new(struct object_database *odb)
        source->base.read_object_stream = odb_source_inmemory_read_object_stream;
        source->base.for_each_object = odb_source_inmemory_for_each_object;
        source->base.find_abbrev_len = odb_source_inmemory_find_abbrev_len;
+       source->base.count_objects = odb_source_inmemory_count_objects;
        source->base.write_object = odb_source_inmemory_write_object;
        source->base.write_object_stream = odb_source_inmemory_write_object_stream;