odb/source-inmemory: implement `count_objects()` callback
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>
Patrick Steinhardt committed
Apr 10, 2026 at 14:12 UTC
27d219132afe13db43d9732caeb37a14c026e717
1 file changed
+20
odb/source-inmemory.c
+20
@@ -207,6 +207,25 @@ static int odb_source_inmemory_find_abbrev_len(struct odb_source *source,
207
return ret;
208
}
209
210
+static int count_objects_cb(const struct object_id *oid UNUSED,
211
+ struct object_info *oi UNUSED,
212
+ void *cb_data)
213
+{
214
+ unsigned long *counter = cb_data;
215
+ (*counter)++;
216
+ return 0;
217
+}
218
+
219
+static int odb_source_inmemory_count_objects(struct odb_source *source,
220
+ enum odb_count_objects_flags flags UNUSED,
221
+ unsigned long *out)
222
+{
223
+ struct odb_for_each_object_options opts = { 0 };
224
+ *out = 0;
225
+ return odb_source_inmemory_for_each_object(source, NULL, count_objects_cb,
226
+ out, &opts);
227
+}
228
+
229
static int odb_source_inmemory_write_object(struct odb_source *source,
230
const void *buf, unsigned long len,
231
enum object_type type,
@@ -314,6 +333,7 @@ struct odb_source_inmemory *odb_source_inmemory_new(struct object_database *odb)
333
source->base.read_object_stream = odb_source_inmemory_read_object_stream;
334
source->base.for_each_object = odb_source_inmemory_for_each_object;
335
source->base.find_abbrev_len = odb_source_inmemory_find_abbrev_len;
336
+ source->base.count_objects = odb_source_inmemory_count_objects;
337
source->base.write_object = odb_source_inmemory_write_object;
338
source->base.write_object_stream = odb_source_inmemory_write_object_stream;
339