diff options
| author | Patrick Steinhardt <ps@pks.im> | 2026-03-12 09:43:00 +0100 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-03-12 08:38:42 -0700 |
| commit | b259f2175b0ccd5574fc6b06b8ec5cbeaa860610 (patch) | |
| tree | 62a0f6dae02ca80a874f08c5adb694d202b59222 /odb/source-files.c | |
| parent | 2b24db1110150138ac1e09bc60d9ae5245909625 (diff) | |
| download | git-b259f2175b0ccd5574fc6b06b8ec5cbeaa860610.tar.xz | |
odb/source: introduce generic object counting
Introduce generic object counting on the object database source level
with a new backend-specific callback function.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'odb/source-files.c')
| -rw-r--r-- | odb/source-files.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/odb/source-files.c b/odb/source-files.c index 14cb9adeca..c08d8993e3 100644 --- a/odb/source-files.c +++ b/odb/source-files.c @@ -93,6 +93,35 @@ static int odb_source_files_for_each_object(struct odb_source *source, return 0; } +static int odb_source_files_count_objects(struct odb_source *source, + enum odb_count_objects_flags flags, + unsigned long *out) +{ + struct odb_source_files *files = odb_source_files_downcast(source); + unsigned long count; + int ret; + + ret = packfile_store_count_objects(files->packed, flags, &count); + if (ret < 0) + goto out; + + if (!(flags & ODB_COUNT_OBJECTS_APPROXIMATE)) { + unsigned long loose_count; + + ret = odb_source_loose_count_objects(source, flags, &loose_count); + if (ret < 0) + goto out; + + count += loose_count; + } + + *out = count; + ret = 0; + +out: + return ret; +} + static int odb_source_files_freshen_object(struct odb_source *source, const struct object_id *oid) { @@ -220,6 +249,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb, files->base.read_object_info = odb_source_files_read_object_info; files->base.read_object_stream = odb_source_files_read_object_stream; files->base.for_each_object = odb_source_files_for_each_object; + files->base.count_objects = odb_source_files_count_objects; files->base.freshen_object = odb_source_files_freshen_object; files->base.write_object = odb_source_files_write_object; files->base.write_object_stream = odb_source_files_write_object_stream; |
