]> Kevux Git Server - rit/commit
odb: embed base source in the "files" backend
authorPatrick Steinhardt <ps@pks.im>
Thu, 5 Mar 2026 14:19:43 +0000 (15:19 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 5 Mar 2026 19:45:15 +0000 (11:45 -0800)
commitd9ecf268ef3f69130fa269012318470d908978f6
tree66550ddc707f4f2c1a562201b33a89140f581bc5
parentcb506a8a69c953f7b87bb3ae099e0bed8218d3ab
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>
18 files changed:
builtin/cat-file.c
builtin/fast-import.c
builtin/grep.c
builtin/index-pack.c
builtin/pack-objects.c
commit-graph.c
http.c
loose.c
midx.c
object-file.c
odb.c
odb/source-files.c
odb/source-files.h
odb/source.c
odb/source.h
odb/streaming.c
packfile.c
packfile.h