aboutsummaryrefslogtreecommitdiff
path: root/odb.h
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2026-03-12 09:43:01 +0100
committerJunio C Hamano <gitster@pobox.com>2026-03-12 08:38:43 -0700
commit6801ffd37df8420917e1feaf03b5f7c175798bff (patch)
tree07c19a65d1974eed84639ed1b5682aae2491f8c3 /odb.h
parentb259f2175b0ccd5574fc6b06b8ec5cbeaa860610 (diff)
downloadgit-6801ffd37df8420917e1feaf03b5f7c175798bff.tar.xz
odb: introduce generic object counting
Similar to the preceding commit, introduce counting of objects on the object database level, replacing the logic that we have in `repo_approximate_object_count()`. Note that the function knows to cache the object count. It's unclear whether this cache is really required as we shouldn't have that many cases where we count objects repeatedly. But to be on the safe side the caching mechanism is retained, with the only excepting being that we also have to use the passed flags as caching key. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'odb.h')
-rw-r--r--odb.h19
1 files changed, 16 insertions, 3 deletions
diff --git a/odb.h b/odb.h
index e6057477f6..9aee260105 100644
--- a/odb.h
+++ b/odb.h
@@ -110,10 +110,11 @@ struct object_database {
/*
* A fast, rough count of the number of objects in the repository.
* These two fields are not meant for direct access. Use
- * repo_approximate_object_count() instead.
+ * odb_count_objects() instead.
*/
- unsigned long approximate_object_count;
- unsigned approximate_object_count_valid : 1;
+ unsigned long object_count;
+ unsigned object_count_flags;
+ unsigned object_count_valid : 1;
/*
* Submodule source paths that will be added as additional sources to
@@ -509,6 +510,18 @@ enum odb_count_objects_flags {
ODB_COUNT_OBJECTS_APPROXIMATE = (1 << 0),
};
+/*
+ * Count the number of objects in the given object database. This object count
+ * may double-count objects that are stored in multiple backends, or which are
+ * stored multiple times in a single backend.
+ *
+ * Returns 0 on success, a negative error code otherwise. The number of objects
+ * will be assigned to the `out` pointer on success.
+ */
+int odb_count_objects(struct object_database *odb,
+ enum odb_count_objects_flags flags,
+ unsigned long *out);
+
enum {
/*
* By default, `odb_write_object()` does not actually write anything