Skip to content

Commit aaa0a85

Browse files
pks-tgitster
authored andcommitted
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>
1 parent bb59813 commit aaa0a85

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

odb/source-inmemory.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,25 @@ static int odb_source_inmemory_find_abbrev_len(struct odb_source *source,
207207
return ret;
208208
}
209209

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+
210229
static int odb_source_inmemory_write_object(struct odb_source *source,
211230
const void *buf, unsigned long len,
212231
enum object_type type,
@@ -314,6 +333,7 @@ struct odb_source_inmemory *odb_source_inmemory_new(struct object_database *odb)
314333
source->base.read_object_stream = odb_source_inmemory_read_object_stream;
315334
source->base.for_each_object = odb_source_inmemory_for_each_object;
316335
source->base.find_abbrev_len = odb_source_inmemory_find_abbrev_len;
336+
source->base.count_objects = odb_source_inmemory_count_objects;
317337
source->base.write_object = odb_source_inmemory_write_object;
318338
source->base.write_object_stream = odb_source_inmemory_write_object_stream;
319339

0 commit comments

Comments
 (0)