object-file: introduce `struct odb_source_loose`
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>
Patrick Steinhardt committed
Nov 3, 2025 at 08:42 UTC
ece43d9dc70b1717484ee78b66aef4f9390c2b2b
4 files changed
+25
object-file.c
+13
@@ -1995,3 +1995,16 @@ void object_file_transaction_commit(struct odb_transaction *transaction)
1995
transaction->odb->transaction = NULL;
1996
free(transaction);
1997
}
1998
+
1999
+struct odb_source_loose *odb_source_loose_new(struct odb_source *source)
2000
+{
2001
+ struct odb_source_loose *loose;
2002
+ CALLOC_ARRAY(loose, 1);
2003
+ loose->source = source;
2004
+ return loose;
2005
+}
2006
+
2007
+void odb_source_loose_free(struct odb_source_loose *loose)
2008
+{
2009
+ free(loose);
2010
+}
object-file.h
+7
@@ -18,6 +18,13 @@ int index_path(struct index_state *istate, struct object_id *oid, const char *pa
18
19
struct odb_source;
20
21
+struct odb_source_loose {
22
+ struct odb_source *source;
23
+};
24
+
25
+struct odb_source_loose *odb_source_loose_new(struct odb_source *source);
26
+void odb_source_loose_free(struct odb_source_loose *loose);
27
+
28
/*
29
* Populate and return the loose object cache array corresponding to the
30
* given object ID.
odb.c
+2
@@ -151,6 +151,7 @@ struct odb_source *odb_source_new(struct object_database *odb,
151
source->odb = odb;
152
source->local = local;
153
source->path = xstrdup(path);
154
+ source->loose = odb_source_loose_new(source);
155
156
return source;
157
}
@@ -368,6 +369,7 @@ struct odb_source *odb_set_temporary_primary_source(struct object_database *odb,
369
static void odb_source_free(struct odb_source *source)
370
{
371
free(source->path);
372
+ odb_source_loose_free(source->loose);
373
odb_clear_loose_cache(source);
374
loose_object_map_clear(&source->loose_map);
375
free(source);
odb.h
+3
@@ -48,6 +48,9 @@ struct odb_source {
48
/* Object database that owns this object source. */
49
struct object_database *odb;
50
51
+ /* Private state for loose objects. */
52
+ struct odb_source_loose *loose;
53
+
54
/*
55
* Used to store the results of readdir(3) calls when we are OK
56
* sacrificing accuracy due to races for speed. That includes