Subject: Re: [PATCH v3 07/14] odb: introduce `odb_for_each_object()`

From: Taylor Blau <[email-masked]>
Date: Thu, 22 Jan 2026 19:13:38 -0500

On Wed, Jan 21, 2026 at 01:50:23PM +0100, Patrick Steinhardt wrote:
> 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.

> +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