From: Patrick Steinhardt Date: Mon, 01 Jun 2026 08:20:23 GMT Subject: [PATCH v2 00/18] odb: make loose object source a proper `struct odb_source` Message-ID: <20260601-b4-pks-odb-source-loose-v2-0-90ff159430af@pks.im> In-Reply-To: <20260521-b4-pks-odb-source-loose-v1-0-6553b399be2d@pks.im> Hi, this patch series converts the loose object source into a proper `struct odb_source` so that it can be used via our generic interfaces. The patch series is relatively straight-forward, as the source basically already exists as such and the interfaces already match. So for most of the part we are just moving around some code and converting functions that were previously called directly into callbacks. I guess the only part that needs some attention is that there is some confusion at first with the `struct odb_source_loose::source` parent pointer that initially points at the owning `struct odb_source_files`. This relationship doesn't make much sense, as a loose source can totally exist standalone without the files source. We're thus getting rid of this relationship in this series, too. I found it quite hard to reason about which pointer one is holding at any point in time though, doubly so because the parent pointer was named "source", which is rather generic. The second commit thus renames the pointer to `files` and converts it into `struct odb_source_files` to make the transition cleaner, but the whole pointer will be dropped at the end of this series. The series is built on top of aec3f58750 (Sync with 'maint', 2026-05-21) with ps/odb-in-memory at d2902a4549 (t/unit-tests: add tests for the in-memory object source, 2026-04-10) merged into it. Changes in v2: - Some smaller typo fixes. - Link to v1: https://patch.msgid.link/20260521-b4-pks-odb-source-loose-v1-0-6553b399be2d@pks.im Thanks! Patrick --- Patrick Steinhardt (18): odb/source-loose: move loose source into "odb/" subsystem odb/source-loose: store pointer to "files" instead of generic source odb/source-loose: start converting to a proper `struct odb_source` odb/source-loose: wire up `reprepare()` callback odb/source-loose: wire up `close()` callback odb/source-loose: wire up `read_object_info()` callback odb/source-loose: wire up `read_object_stream()` callback odb/source-loose: wire up `for_each_object()` callback odb/source-loose: wire up `find_abbrev_len()` callback odb/source-loose: wire up `count_objects()` callback odb/source-loose: drop `odb_source_loose_has_object()` odb/source-loose: wire up `freshen_object()` callback loose: refactor object map to operate on `struct odb_source_loose` odb/source-loose: wire up `write_object()` callback object-file: refactor writing objects to use loose source odb/source-loose: wire up `write_object_stream()` callback odb/source-loose: stub out remaining callbacks odb/source-loose: drop pointer to the "files" source Makefile | 1 + builtin/cat-file.c | 5 +- builtin/gc.c | 6 +- builtin/pack-objects.c | 12 +- http-walker.c | 3 +- http.c | 6 +- loose.c | 45 ++- loose.h | 4 +- meson.build | 1 + object-file.c | 796 ++++--------------------------------------------- object-file.h | 149 ++++----- odb/source-files.c | 28 +- odb/source-loose.c | 736 +++++++++++++++++++++++++++++++++++++++++++++ odb/source-loose.h | 48 +++ odb/source.h | 3 + 15 files changed, 973 insertions(+), 870 deletions(-) Range-diff versus v1: 1: f25aaf0889 = 1: 7c97c1687c odb/source-loose: move loose source into "odb/" subsystem 2: 0bfebeb0da = 2: 1e1e267b39 odb/source-loose: store pointer to "files" instead of generic source 3: 35787e6ca6 ! 3: 847cb523ee odb/source-loose: start converting to a proper `struct odb_source` @@ odb/source-loose.h: struct odb_source_loose { +/* + * Cast the given object database source to the loose backend. This will cause -+ * a BUG in case the source uses doesn't use this backend. ++ * a BUG in case the source doesn't use this backend. + */ +static inline struct odb_source_loose *odb_source_loose_downcast(struct odb_source *source) +{ 4: 392962c177 = 4: af543598ee odb/source-loose: wire up `reprepare()` callback 5: b4102668c3 = 5: 884f573f89 odb/source-loose: wire up `close()` callback 6: 63da6e4abb = 6: de85ffb4a9 odb/source-loose: wire up `read_object_info()` callback 7: 12b0c5c32d = 7: 522aaa9c3d odb/source-loose: wire up `read_object_stream()` callback 8: 8df176e282 = 8: 75cf3f4428 odb/source-loose: wire up `for_each_object()` callback 9: 6199ae90e0 = 9: 87c1c9ae5e odb/source-loose: wire up `find_abbrev_len()` callback 10: d0b1ef48d4 = 10: f6405c8070 odb/source-loose: wire up `count_objects()` callback 11: 0476d8b0c4 = 11: 0e8d6b6487 odb/source-loose: drop `odb_source_loose_has_object()` 12: 27bb7b0724 = 12: 58cc626dd1 odb/source-loose: wire up `freshen_object()` callback 13: f8ce6a169d = 13: 51a22e7400 loose: refactor object map to operate on `struct odb_source_loose` 14: 7ab570b776 = 14: a9a88d6200 odb/source-loose: wire up `write_object()` callback 15: 8c9240aaa0 = 15: 9236d2fd26 object-file: refactor writing objects to use loose source 16: de69621fa1 ! 16: 6316efb890 odb/source-loose: wire up `write_object_stream()` callback @@ object-file.h: int index_path(struct index_state *istate, struct object_id *oid, -int odb_source_loose_write_stream(struct odb_source_loose *loose, +/* -+ * Write the given stream into the loose object source. The only difference to -+ * the generic implementation of this function is that we don't perform an ++ * Write the given stream into the loose object source. The only difference ++ * from the generic implementation of this function is that we don't perform an + * object existence check here. + * + * TODO: We should stop exposing this function altogether and move it into 17: f2d45e1a56 = 17: 789ec50474 odb/source-loose: stub out remaining callbacks 18: 070052fc22 = 18: 0a64d23377 odb/source-loose: drop pointer to the "files" source --- base-commit: 072edab49f312c80561b2899f03f361f74fc38e4 change-id: 20260413-b4-pks-odb-source-loose-4900c8ca91db