From: Patrick Steinhardt Date: Tue, 20 Jan 2026 15:25:56 GMT Subject: [PATCH v2 00/14] odb: introduce `odb_for_each_object()` Message-ID: <20260120-pks-odb-for-each-object-v2-0-d05cbfd3d6f8@pks.im> In-Reply-To: <20260115-pks-odb-for-each-object-v1-0-5418a91d5d99@pks.im> Hi, this patch series introduces a generic `odb_for_each_object()` function to iterate through objects and adapts callers to use it. The intent is to make iteration through objects independent of the actual storage backend. The series is structured as follows: - Commits 1 to 2 do some cleanups for the for-each-object flags. - Commits 3 to 7 introduce the infrastructure for `odb_for_each_object()`. - Commits 8 to 13 convert a couple of callers to use the new interfaces. - Commit 14 drops now-unused functions. The patch series is built on top of 8745eae506 (The 17th batch, 2026-01-11) with the following two series merged into it: - ps/read-object-info-improvements at a282a8f163 (packfile: move MIDX into packfile store, 2026-01-09). - ps/packfile-store-in-odb-source at 12d3b58b55 (packfile: drop repository parameter from `packed_object_info()`, 2026-01-12) . Changes in v2: - Clarify the comment of `odb_for_each_object()` to point out that it's the callback that can abort iteration by returning a non-zero error code. - Document in the commit message that we don't yet convert all sites to use `odb_for_each_object()`. - Link to v1: https://lore.kernel.org/r/20260115-pks-odb-for-each-object-v1-0-5418a91d5d99@pks.im Thanks! Patrick --- Patrick Steinhardt (14): odb: rename `FOR_EACH_OBJECT_*` flags odb: fix flags parameter to be unsigned object-file: extract function to read object info from path object-file: introduce function to iterate through objects packfile: extract function to iterate through objects of a store packfile: introduce function to iterate through objects odb: introduce `odb_for_each_object()` builtin/fsck: refactor to use `odb_for_each_object()` treewide: enumerate promisor objects via `odb_for_each_object()` treewide: drop uses of `for_each_{loose,packed}_object()` odb: introduce mtime fields for object info requests builtin/pack-objects: use `packfile_store_for_each_object()` reachable: convert to use `odb_for_each_object()` odb: drop unused `for_each_{loose,packed}_object()` functions builtin/cat-file.c | 30 +++++++-- builtin/fsck.c | 57 ++++------------ builtin/pack-objects.c | 47 +++++++------- commit-graph.c | 46 +++++++++---- object-file.c | 120 ++++++++++++++++++++++------------ object-file.h | 21 +++--- odb.c | 29 +++++++++ odb.h | 43 ++++++++++-- packfile.c | 173 +++++++++++++++++++++++++++++++++---------------- packfile.h | 18 ++++- reachable.c | 129 +++++++++++------------------------- repack-promisor.c | 8 +-- revision.c | 10 ++- 13 files changed, 420 insertions(+), 311 deletions(-) Range-diff versus v1: 1: 1202ac1d9d = 1: 7658b0e3d1 odb: rename `FOR_EACH_OBJECT_*` flags 2: 8fd78aad98 = 2: c082223854 odb: fix flags parameter to be unsigned 3: 40e049c68b = 3: 9d00d20178 object-file: extract function to read object info from path 4: 9eaebd1181 = 4: 213548b0ee object-file: introduce function to iterate through objects 5: d88e439de2 = 5: 1521d6285e packfile: extract function to iterate through objects of a store 6: 85f52c0db7 = 6: 7dcb9e5cb1 packfile: introduce function to iterate through objects 7: ed42cbcf6b ! 7: 9ab2a31068 odb: introduce `odb_for_each_object()` @@ odb.h: typedef int (*odb_for_each_object_cb)(const struct object_id *oid, + * objects may be iterated over multiple times in case they are either stored + * in different backends or in case they are stored in multiple sources. + * -+ * Returning a non-zero error code will cause iteration to abort. The error -+ * code will be propagated. ++ * Returning a non-zero error code from the callback function will cause ++ * iteration to abort. The error code will be propagated. + * + * Returns 0 on success, a negative error code in case a failure occurred, or + * an arbitrary non-zero error code returned by the callback itself. 8: 39e10e18ed = 8: 343f2007bb builtin/fsck: refactor to use `odb_for_each_object()` 9: d3a87909f2 = 9: a524a2aae8 treewide: enumerate promisor objects via `odb_for_each_object()` 10: 06392d8a2e ! 10: f375828c1f treewide: drop uses of `for_each_{loose,packed}_object()` @@ Commit message Prepare for this by refactoring the sites accordingly. + Note that ideally, we'd convert all callsites to use the generic + `odb_for_each_object()` function already. But for some callers this is + not possible (yet), and it would require some significant refactorings + to make this work. Converting these site will thus be deferred to a + later patch series. + Signed-off-by: Patrick Steinhardt ## builtin/cat-file.c ## 11: 4a9e5687d0 = 11: b2b2025502 odb: introduce mtime fields for object info requests 12: 80284057a8 = 12: 8b596e7a8e builtin/pack-objects: use `packfile_store_for_each_object()` 13: 7c38197ee5 = 13: b8bb1cf980 reachable: convert to use `odb_for_each_object()` 14: 886002ba49 = 14: b53ac29d2c odb: drop unused `for_each_{loose,packed}_object()` functions --- base-commit: 1ff0e42d332523a11cc3d61b8d8463db5f9f14e8 change-id: 20260115-pks-odb-for-each-object-60b78cde09fd