aboutsummaryrefslogtreecommitdiff
path: root/odb/source.h
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2026-03-12 09:43:00 +0100
committerJunio C Hamano <gitster@pobox.com>2026-03-12 08:38:42 -0700
commitb259f2175b0ccd5574fc6b06b8ec5cbeaa860610 (patch)
tree62a0f6dae02ca80a874f08c5adb694d202b59222 /odb/source.h
parent2b24db1110150138ac1e09bc60d9ae5245909625 (diff)
downloadgit-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.h')
-rw-r--r--odb/source.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/odb/source.h b/odb/source.h
index a1fd9dd920..96c906e7a1 100644
--- a/odb/source.h
+++ b/odb/source.h
@@ -143,6 +143,21 @@ struct odb_source {
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
* that objects that are recent will not get garbage collected even if
@@ -334,6 +349,18 @@ static inline int odb_source_for_each_object(struct odb_source *source,
}
/*
+ * 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
* not exist.