aboutsummaryrefslogtreecommitdiff
path: root/odb
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2026-03-05 15:19:42 +0100
committerJunio C Hamano <gitster@pobox.com>2026-03-05 11:45:14 -0800
commitcb506a8a69c953f7b87bb3ae099e0bed8218d3ab (patch)
tree2b469f6c020f5fc1889a01754ed99443085eeb61 /odb
parentba1c21d34346e5979f9308806274bfcda4949ad4 (diff)
downloadgit-cb506a8a69c953f7b87bb3ae099e0bed8218d3ab.tar.xz
odb: introduce "files" source
Introduce a new "files" object database source. This source encapsulates access to both loose object files and the packfile store, similar to how the "files" backend for refs encapsulates access to loose refs and the packed-refs file. Note that for now the "files" source is still a direct member of a `struct odb_source`. This architecture will be reversed in the next commit so that the files source contains a `struct odb_source`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'odb')
-rw-r--r--odb/source-files.c23
-rw-r--r--odb/source-files.h24
-rw-r--r--odb/source.c6
-rw-r--r--odb/source.h9
-rw-r--r--odb/streaming.c2
5 files changed, 54 insertions, 10 deletions
diff --git a/odb/source-files.c b/odb/source-files.c
new file mode 100644
index 0000000000..cbdaa6850f
--- /dev/null
+++ b/odb/source-files.c
@@ -0,0 +1,23 @@
+#include "git-compat-util.h"
+#include "object-file.h"
+#include "odb/source-files.h"
+#include "packfile.h"
+
+void odb_source_files_free(struct odb_source_files *files)
+{
+ if (!files)
+ return;
+ odb_source_loose_free(files->loose);
+ packfile_store_free(files->packed);
+ free(files);
+}
+
+struct odb_source_files *odb_source_files_new(struct odb_source *source)
+{
+ struct odb_source_files *files;
+ CALLOC_ARRAY(files, 1);
+ files->source = source;
+ files->loose = odb_source_loose_new(source);
+ files->packed = packfile_store_new(source);
+ return files;
+}
diff --git a/odb/source-files.h b/odb/source-files.h
new file mode 100644
index 0000000000..0b8bf773ca
--- /dev/null
+++ b/odb/source-files.h
@@ -0,0 +1,24 @@
+#ifndef ODB_SOURCE_FILES_H
+#define ODB_SOURCE_FILES_H
+
+struct odb_source_loose;
+struct odb_source;
+struct packfile_store;
+
+/*
+ * The files object database source uses a combination of loose objects and
+ * packfiles. It is the default backend used by Git to store objects.
+ */
+struct odb_source_files {
+ struct odb_source *source;
+ struct odb_source_loose *loose;
+ struct packfile_store *packed;
+};
+
+/* Allocate and initialize a new object source. */
+struct odb_source_files *odb_source_files_new(struct odb_source *source);
+
+/* Free the object source and release all associated resources. */
+void odb_source_files_free(struct odb_source_files *files);
+
+#endif
diff --git a/odb/source.c b/odb/source.c
index 7fc89806f9..9d7fd19f45 100644
--- a/odb/source.c
+++ b/odb/source.c
@@ -13,8 +13,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);
- source->packfiles = packfile_store_new(source);
+ source->files = odb_source_files_new(source);
return source;
}
@@ -22,7 +21,6 @@ struct odb_source *odb_source_new(struct object_database *odb,
void odb_source_free(struct odb_source *source)
{
free(source->path);
- odb_source_loose_free(source->loose);
- packfile_store_free(source->packfiles);
+ odb_source_files_free(source->files);
free(source);
}
diff --git a/odb/source.h b/odb/source.h
index 391d6d1e38..1c34265189 100644
--- a/odb/source.h
+++ b/odb/source.h
@@ -1,6 +1,8 @@
#ifndef ODB_SOURCE_H
#define ODB_SOURCE_H
+#include "odb/source-files.h"
+
/*
* The source is the part of the object database that stores the actual
* objects. It thus encapsulates the logic to read and write the specific
@@ -19,11 +21,8 @@ struct odb_source {
/* Object database that owns this object source. */
struct object_database *odb;
- /* Private state for loose objects. */
- struct odb_source_loose *loose;
-
- /* Should only be accessed directly by packfile.c and midx.c. */
- struct packfile_store *packfiles;
+ /* The backend used to store objects. */
+ struct odb_source_files *files;
/*
* Figure out whether this is the local source of the owning
diff --git a/odb/streaming.c b/odb/streaming.c
index 4a4474f891..26b0a1a0f5 100644
--- a/odb/streaming.c
+++ b/odb/streaming.c
@@ -187,7 +187,7 @@ static int istream_source(struct odb_read_stream **out,
odb_prepare_alternates(odb);
for (source = odb->sources; source; source = source->next) {
- if (!packfile_store_read_object_stream(out, source->packfiles, oid) ||
+ if (!packfile_store_read_object_stream(out, source->files->packed, oid) ||
!odb_source_loose_read_object_stream(out, source, oid))
return 0;
}