From: Karthik Nayak Date: Fri, 20 Mar 2026 09:01:42 GMT Subject: Re: [PATCH 03/14] odb: introduce `struct odb_for_each_object_options` Message-ID: In-Reply-To: <20260319-b4-pks-odb-source-abbrev-v1-3-5ddebad292b0@pks.im> Patrick Steinhardt writes: > The `odb_for_each_object()` function only accepts a bitset of flags. In > a subsequent commit we'll want to change object iteration to also > support iterating over only those objects that have a specific prefix. > While we could of course add the prefix to the function signature, or > alternative introduce a new function, both of these options don't really > seem to be that sensible. > > Instead, introduce a new `struct odb_for_each_object_options` that can > be passed to a new `odb_for_each_object_ext()` function. Splice through > the options structure into the respective object database sources. > Yeah I like this pattern, really cleans up the arguments sent into a function. Making future additions to the struct produce a localized diff rather than modifying the function params each time. Nice. > Signed-off-by: Patrick Steinhardt > --- > builtin/cat-file.c | 7 +++++-- > builtin/pack-objects.c | 12 +++++++----- > commit-graph.c | 5 ++++- > object-file.c | 6 +++--- > object-file.h | 2 +- > odb.c | 26 +++++++++++++++++++------- > odb.h | 16 ++++++++++++++++ > odb/source-files.c | 8 ++++---- > odb/source.h | 6 +++--- > packfile.c | 12 ++++++------ > packfile.h | 2 +- > 11 files changed, 69 insertions(+), 33 deletions(-) > > diff --git a/builtin/cat-file.c b/builtin/cat-file.c > index b6f12f41d6..cd13a3a89f 100644 > --- a/builtin/cat-file.c > +++ b/builtin/cat-file.c > @@ -848,6 +848,9 @@ static void batch_each_object(struct batch_options *opt, > .callback = callback, > .payload = _payload, > }; > + struct odb_for_each_object_options opts = { > + .flags = flags, > + }; > struct bitmap_index *bitmap = NULL; > struct odb_source *source; > > @@ -860,7 +863,7 @@ static void batch_each_object(struct batch_options *opt, > odb_prepare_alternates(the_repository->objects); > for (source = the_repository->objects->sources; source; source = source->next) { > int ret = odb_source_loose_for_each_object(source, NULL, batch_one_object_oi, > - &payload, flags); > + &payload, &opts); > if (ret) > break; > } > @@ -884,7 +887,7 @@ static void batch_each_object(struct batch_options *opt, > for (source = the_repository->objects->sources; source; source = source->next) { > struct odb_source_files *files = odb_source_files_downcast(source); > int ret = packfile_store_for_each_object(files->packed, &oi, > - batch_one_object_oi, &payload, flags); > + batch_one_object_oi, &payload, &opts); > if (ret) > break; > } > diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c > index cd013c0b68..3bb57ff183 100644 > --- a/builtin/pack-objects.c > +++ b/builtin/pack-objects.c > @@ -4344,6 +4344,12 @@ static void add_objects_in_unpacked_packs(void) > { > struct odb_source *source; > time_t mtime; > + struct odb_for_each_object_options opts = { > + .flags = ODB_FOR_EACH_OBJECT_PACK_ORDER | > + ODB_FOR_EACH_OBJECT_LOCAL_ONLY | > + ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS | > + ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS, > + }; > struct object_info oi = { > .mtimep = &mtime, > }; > @@ -4356,11 +4362,7 @@ static void add_objects_in_unpacked_packs(void) > continue; > > if (packfile_store_for_each_object(files->packed, &oi, > - add_object_in_unpacked_pack, NULL, > - ODB_FOR_EACH_OBJECT_PACK_ORDER | > - ODB_FOR_EACH_OBJECT_LOCAL_ONLY | > - ODB_FOR_EACH_OBJECT_SKIP_IN_CORE_KEPT_PACKS | > - ODB_FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS)) > + add_object_in_unpacked_pack, NULL, &opts)) Plus this is so much easier to read now. [snip] The rest looked good.