From: Karthik Nayak Date: Tue, 20 Jan 2026 09:16:34 GMT Subject: Re: [PATCH 04/14] object-file: introduce function to iterate through objects Message-ID: In-Reply-To: <20260115-pks-odb-for-each-object-v1-4-5418a91d5d99@pks.im> Patrick Steinhardt writes: > We have multiple divergent interfaces to iterate through objects of a > specific backend: > > - `for_each_loose_object()` yields all loose objects. > > - `for_each_packed_object()` (somewhat obviously) yields all packed > objects. > > These functions have different function signatures, which makes it hard > to create a common abstraction layer that covers both of these. > > Introduce a new function `odb_source_loose_for_each_object()` to plug > this gap. This function doesn't take any data specific to loose objects, > but instead it accepts a `struct object_info` that will be populated the > exact same as if `odb_source_loose_read_object()` was called. > > The benefit of this new interface is that we can continue to pass > backend-specific data, as `struct object_info` contains a union for > these exact use cases. This will allow us to unify how we iterate > through objects across both loose and packed objects in a subsequent > commit. > > The `for_each_loose_object()` function continues to exist for now, but > it will be removed at the end of this patch series. > > Signed-off-by: Patrick Steinhardt > --- > object-file.c | 41 +++++++++++++++++++++++++++++++++++++++++ > object-file.h | 11 +++++++++++ > odb.h | 12 ++++++++++++ > 3 files changed, 64 insertions(+) > > diff --git a/object-file.c b/object-file.c > index a651129426..65e730684b 100644 > --- a/object-file.c > +++ b/object-file.c > @@ -1801,6 +1801,47 @@ int for_each_loose_object(struct object_database *odb, > return 0; > } > > +struct for_each_object_wrapper_data { > + struct odb_source *source; > + struct object_info *oi; > + odb_for_each_object_cb cb; > + void *cb_data; > +}; > + > +static int for_each_object_wrapper_cb(const struct object_id *oid, > + const char *path, > + void *cb_data) > +{ > + struct for_each_object_wrapper_data *data = cb_data; > + if (data->oi && > + read_object_info_from_path(data->source, path, oid, data->oi, 0) < 0) > + return -1; > + return data->cb(oid, data->oi, data->cb_data); > +} Okay so here, we use `read_object_info_from_path()` since we already have the path, we don't need to call `odb_loose_path()`. [snip]