]> git.ipfire.org Git - thirdparty/git.git/commitdiff
object-file: introduce `struct odb_source_loose`
authorPatrick Steinhardt <ps@pks.im>
Mon, 3 Nov 2025 07:42:00 +0000 (08:42 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 3 Nov 2025 20:18:46 +0000 (12:18 -0800)
Currently, all state that relates to loose objects is held directly by
the `struct odb_source`. Introduce a new `struct odb_source_loose` 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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
object-file.c
object-file.h
odb.c
odb.h

index 4675c8ed6b67eb8b1f054aa7326f380d9a0a29b5..cd6aa561fa7db28144dfc9f8c49c2e5ca6e3191b 100644 (file)
@@ -1995,3 +1995,16 @@ void object_file_transaction_commit(struct odb_transaction *transaction)
        transaction->odb->transaction = NULL;
        free(transaction);
 }
+
+struct odb_source_loose *odb_source_loose_new(struct odb_source *source)
+{
+       struct odb_source_loose *loose;
+       CALLOC_ARRAY(loose, 1);
+       loose->source = source;
+       return loose;
+}
+
+void odb_source_loose_free(struct odb_source_loose *loose)
+{
+       free(loose);
+}
index 097e9764be169ebba2db7dd52d797d0090fa5cf7..695a7e8e7c4b0b3efc7c54dd46ccc7a0ab4d2a9a 100644 (file)
@@ -18,6 +18,13 @@ int index_path(struct index_state *istate, struct object_id *oid, const char *pa
 
 struct odb_source;
 
+struct odb_source_loose {
+       struct odb_source *source;
+};
+
+struct odb_source_loose *odb_source_loose_new(struct odb_source *source);
+void odb_source_loose_free(struct odb_source_loose *loose);
+
 /*
  * Populate and return the loose object cache array corresponding to the
  * given object ID.
diff --git a/odb.c b/odb.c
index 77490d7fdbeb4b1ccb8474e03f857098e18d7c56..2d06ab0bb85c27d824ab7229cb22b00e6cf8fb71 100644 (file)
--- 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_source_loose_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_source_loose_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 2346ffeca859618e3d57a88c618c70543cc631c5..49b398bedae64067251a15b3e7f5087576de6c89 100644 (file)
--- 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_source_loose *loose;
+
        /*
         * Used to store the results of readdir(3) calls when we are OK
         * sacrificing accuracy due to races for speed. That includes