From b259f2175b0ccd5574fc6b06b8ec5cbeaa860610 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 12 Mar 2026 09:43:00 +0100 Subject: 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 Signed-off-by: Junio C Hamano --- odb/source.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'odb/source.h') diff --git a/odb/source.h b/odb/source.h index a1fd9dd920..96c906e7a1 100644 --- a/odb/source.h +++ b/odb/source.h @@ -142,6 +142,21 @@ struct odb_source { void *cb_data, unsigned flags); + /* + * This callback is expected to count objects in the given object + * database source. The callback function does not have to guarantee + * that only unique objects are counted. The result shall be assigned + * to the `out` pointer. + * + * Accepts `enum odb_count_objects_flag` flags to alter the behaviour. + * + * The callback is expected to return 0 on success, or a negative error + * code otherwise. + */ + int (*count_objects)(struct odb_source *source, + enum odb_count_objects_flags flags, + unsigned long *out); + /* * This callback is expected to freshen the given object so that its * last access time is set to the current time. This is used to ensure @@ -333,6 +348,18 @@ static inline int odb_source_for_each_object(struct odb_source *source, return source->for_each_object(source, request, cb, cb_data, flags); } +/* + * Count the number of objects in the given object database source. + * + * Returns 0 on success, a negative error code otherwise. + */ +static inline int odb_source_count_objects(struct odb_source *source, + enum odb_count_objects_flags flags, + unsigned long *out) +{ + return source->count_objects(source, flags, out); +} + /* * Freshen an object in the object database by updating its timestamp. * Returns 1 in case the object has been freshened, 0 in case the object does -- cgit v1.3-5-g9baa