Re: [PATCH v3 07/14] odb: introduce `odb_for_each_object()`
- From
Taylor Blau <me@ttaylorr.com>
- Date
- Jan 23, 2026, 00:13 UTC
- Message-ID
- <aXK9MkCTt6LrSi+E@nand.local>
- In-Reply-To
- <20260121-pks-odb-for-each-object-v3-7-12c4dfd24227@pks.im>
On Wed, Jan 21, 2026 at 01:50:23PM +0100, Patrick Steinhardt wrote:
Show 5 quoted lines
> Introduce a new function `odb_for_each_object()` that knows to iterate > through all objects part of a given object database. This function is > essentially a simple wrapper around the object database sources. > > Subsequent commits will adapt callers to use this new function.
Makes sense.
Show 18 quoted lines
> +int odb_for_each_object(struct object_database *odb,
> + struct object_info *oi,
> + odb_for_each_object_cb cb,
> + void *cb_data,
> + unsigned flags)
> +{
> + int ret;
> +
> + odb_prepare_alternates(odb);
> + for (struct odb_source *source = odb->sources; source; source = source->next) {
> + if (flags & ODB_FOR_EACH_OBJECT_LOCAL_ONLY && !source->local)
> + continue;
> +
> + if (!(flags & ODB_FOR_EACH_OBJECT_PROMISOR_ONLY)) {
> + ret = odb_source_loose_for_each_object(source, oi, cb, cb_data, flags);
> + if (ret)
> + return ret;
> + }Having the bits corresponding to these two flags be set means that we can avoid looking into the source entirely, as we know ahead of time that none of its objects would match the caller's criteria.
> + ret = packfile_store_for_each_object(source->packfiles, oi, cb, cb_data, flags);
...but when we *do* need to iterate through an individual source, we pass the flags down to that source which handles the rest of them. Good.
Thanks, Taylor