diff options
| author | Patrick Steinhardt <ps@pks.im> | 2026-03-12 09:42:58 +0100 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-03-12 08:38:42 -0700 |
| commit | 222fddeaa44b633eea345996735b4f7893eb71ec (patch) | |
| tree | 27baa462f10c8b3531ad378daaef92acdee7ac31 /object-file.h | |
| parent | dd587cd59e1575f2d5698cb45b42644e1df9b835 (diff) | |
| download | git-222fddeaa44b633eea345996735b4f7893eb71ec.tar.xz | |
object-file: extract logic to approximate object count
In "builtin/gc.c" we have some logic that checks whether we need to
repack objects. This is done by counting the number of objects that we
have and checking whether it exceeds a certain threshold. We don't
really need an accurate object count though, which is why we only
open a single object directory shard and then extrapolate from there.
Extract this logic into a new function that is owned by the loose object
database source. This is done to prepare for a subsequent change, where
we'll introduce object counting on the object database source level.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'object-file.h')
| -rw-r--r-- | object-file.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/object-file.h b/object-file.h index ff6da65296..b870ea9fa8 100644 --- a/object-file.h +++ b/object-file.h @@ -139,6 +139,19 @@ int odb_source_loose_for_each_object(struct odb_source *source, void *cb_data, unsigned flags); +/* + * Count the number of loose objects in this source. + * + * The object count is approximated by opening a single sharding directory for + * loose objects and scanning its contents. The result is then extrapolated by + * 256. This should generally work as a reasonable estimate given that the + * object hash is supposed to be indistinguishable from random. + * + * Returns 0 on success, a negative error code otherwise. + */ +int odb_source_loose_approximate_object_count(struct odb_source *source, + unsigned long *out); + /** * format_object_header() is a thin wrapper around s xsnprintf() that * writes the initial "<type> <obj-len>" part of the loose object |
