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

From: Justin Tobler <[email-masked]>
Date: Thu, 15 Jan 2026 15:17:07 -0600

On 26/01/15 12:04PM, 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.
> 
> Signed-off-by: Patrick Steinhardt <[email-masked]>
> ---
>  odb.c | 27 +++++++++++++++++++++++++++
>  odb.h | 17 +++++++++++++++++
>  2 files changed, 44 insertions(+)
> 
> diff --git a/odb.c b/odb.c
> index ac70b6a099..65f0447aa5 100644
> --- a/odb.c
> +++ b/odb.c
> @@ -995,6 +995,33 @@ int odb_freshen_object(struct object_database *odb,
>  	return 0;
>  }
>  
> +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;
> +		}
> +
> +		ret = packfile_store_for_each_object(source->packfiles, oi, cb, cb_data, flags);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	return 0;
> +}

Ok, I think I understand a bit more clearly now. As implemented here,
odb_for_each_object() iterates across each the objects (loose and
packed) in each source. Object iteration is not handled transparently
for each source yet though and we still explicitly iterate both loose
and packed objects. If I understand correctly, this current
implementation will become specific to the "files" backend/source in the
future.

-Justin