aboutsummaryrefslogtreecommitdiff
path: root/builtin/pack-objects.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2026-03-05 15:19:43 +0100
committerJunio C Hamano <gitster@pobox.com>2026-03-05 11:45:15 -0800
commitd9ecf268ef3f69130fa269012318470d908978f6 (patch)
tree66550ddc707f4f2c1a562201b33a89140f581bc5 /builtin/pack-objects.c
parentcb506a8a69c953f7b87bb3ae099e0bed8218d3ab (diff)
downloadgit-d9ecf268ef3f69130fa269012318470d908978f6.tar.xz
odb: embed base source in the "files" backend
The "files" backend is implemented as a pointer in the `struct odb_source`. This contradicts our typical pattern for pluggable backends like we use it for example in the ref store or for object database streams, where we typically embed the generic base structure in the specialized implementation. This pattern has a couple of small benefits: - We avoid an extra allocation. - We hide implementation details in the generic structure. - We can easily downcast from a generic backend to the specialized structure and vice versa because the offsets are known at compile time. - It becomes trivial to identify locations where we depend on backend specific logic because the cast needs to be explicit. Refactor our "files" object database source to do the same and embed the `struct odb_source` in the `struct odb_source_files`. There are still a bunch of sites in our code base where we do have to access internals of the "files" backend. The intent is that those will go away over time, but this will certainly take a while. Meanwhile, provide a `odb_source_files_downcast()` function that can convert a generic source into a "files" source. As we only have a single source the downcast succeeds unconditionally for now. Eventually though the intent is to make the cast `BUG()` in case the caller requests to downcast a non-"files" backend to a "files" backend. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/pack-objects.c')
-rw-r--r--builtin/pack-objects.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 0c3c01cdc9..63fea80b08 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1531,7 +1531,8 @@ static int want_cruft_object_mtime(struct repository *r,
struct odb_source *source;
for (source = r->objects->sources; source; source = source->next) {
- struct packed_git **cache = packfile_store_get_kept_pack_cache(source->files->packed, flags);
+ struct odb_source_files *files = odb_source_files_downcast(source);
+ struct packed_git **cache = packfile_store_get_kept_pack_cache(files->packed, flags);
for (; *cache; cache++) {
struct packed_git *p = *cache;
@@ -1753,11 +1754,13 @@ static int want_object_in_pack_mtime(const struct object_id *oid,
}
for (source = the_repository->objects->sources; source; source = source->next) {
- for (e = source->files->packed->packs.head; e; e = e->next) {
+ struct odb_source_files *files = odb_source_files_downcast(source);
+
+ for (e = files->packed->packs.head; e; e = e->next) {
struct packed_git *p = e->pack;
want = want_object_in_pack_one(p, oid, exclude, found_pack, found_offset, found_mtime);
if (!exclude && want > 0)
- packfile_list_prepend(&source->files->packed->packs, p);
+ packfile_list_prepend(&files->packed->packs, p);
if (want != -1)
return want;
}
@@ -4337,10 +4340,12 @@ static void add_objects_in_unpacked_packs(void)
odb_prepare_alternates(to_pack.repo->objects);
for (source = to_pack.repo->objects->sources; source; source = source->next) {
+ struct odb_source_files *files = odb_source_files_downcast(source);
+
if (!source->local)
continue;
- if (packfile_store_for_each_object(source->files->packed, &oi,
+ if (packfile_store_for_each_object(files->packed, &oi,
add_object_in_unpacked_pack, NULL,
ODB_FOR_EACH_OBJECT_PACK_ORDER |
ODB_FOR_EACH_OBJECT_LOCAL_ONLY |