From: Patrick Steinhardt Date: Fri, 24 Oct 2025 09:56:04 GMT Subject: [PATCH 05/13] object-file: introduce `struct odb_loose_source` Message-ID: <20251024-b4-pks-odb-loose-backend-v1-5-1a4202273c38@pks.im> In-Reply-To: <20251024-b4-pks-odb-loose-backend-v1-0-1a4202273c38@pks.im> Currently, all state that relates to loose objects is held directly by the `struct odb_source`. Introduce a new `struct odb_loose_source` to hold the state instead so that it is entirely self-contained. This structure will eventually morph into the backend for accessing loose objects. As such, this is part of the refactorings to introduce pluggable object databases. Signed-off-by: Patrick Steinhardt --- object-file.c | 13 +++++++++++++ object-file.h | 7 +++++++ odb.c | 2 ++ odb.h | 3 +++ 4 files changed, 25 insertions(+) diff --git a/object-file.c b/object-file.c index 4675c8ed6b6..38e09262e42 100644 --- a/object-file.c +++ b/object-file.c @@ -1995,3 +1995,16 @@ void object_file_transaction_commit(struct odb_transaction *transaction) transaction->odb->transaction = NULL; free(transaction); } + +struct odb_loose_source *odb_loose_source_new(struct odb_source *source) +{ + struct odb_loose_source *loose; + CALLOC_ARRAY(loose, 1); + loose->source = source; + return loose; +} + +void odb_loose_source_free(struct odb_loose_source *source) +{ + free(source); +} diff --git a/object-file.h b/object-file.h index 097e9764be1..aa84fc2a752 100644 --- a/object-file.h +++ b/object-file.h @@ -18,6 +18,13 @@ int index_path(struct index_state *istate, struct object_id *oid, const char *pa struct odb_source; +struct odb_loose_source { + struct odb_source *source; +}; + +struct odb_loose_source *odb_loose_source_new(struct odb_source *source); +void odb_loose_source_free(struct odb_loose_source *source); + /* * Populate and return the loose object cache array corresponding to the * given object ID. diff --git a/odb.c b/odb.c index 77490d7fdbe..f1b250ceffe 100644 --- a/odb.c +++ b/odb.c @@ -151,6 +151,7 @@ struct odb_source *odb_source_new(struct object_database *odb, source->odb = odb; source->local = local; source->path = xstrdup(path); + source->loose = odb_loose_source_new(source); return source; } @@ -368,6 +369,7 @@ struct odb_source *odb_set_temporary_primary_source(struct object_database *odb, static void odb_source_free(struct odb_source *source) { free(source->path); + odb_loose_source_free(source->loose); odb_clear_loose_cache(source); loose_object_map_clear(&source->loose_map); free(source); diff --git a/odb.h b/odb.h index 2346ffeca85..f7e1bf87803 100644 --- a/odb.h +++ b/odb.h @@ -48,6 +48,9 @@ struct odb_source { /* Object database that owns this object source. */ struct object_database *odb; + /* Private state for loose objects. */ + struct odb_loose_source *loose; + /* * Used to store the results of readdir(3) calls when we are OK * sacrificing accuracy due to races for speed. That includes -- 2.51.1.930.gacf6e81ea2.dirty