Skip to content

odb: add odb_source_files_try() for heterogeneous source iteration

Aaron Paterson via GitGitGadget git 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2odb: add odb_source_files_try() for heterogeneous source iterationodb/source-files.h+14 -00 replies
2/2odb: use odb_source_files_try() in source-chain iterationsMakefile builtin/cat-file.c builtin/fast-import.c +11 more+117 -351 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/2] odb: add odb_source_files_try() for heterogeneous source iteration

The odb_source vtable introduced in this release allows multiple backend implementations via the odb_source_type enum. However, 22 callsites iterate the source chain and downcast every source to odb_source_files to access files-specific internals (pack store, loose cache, MIDX). This prevents adding any non-files source to the chain without hitting a BUG() assertion.

This two-patch series adds odb_source_files_try() as a companion to the existing downcast function. It returns NULL for non-files sources instead of aborting. The 22 source-chain iteration sites are then converted to use this new helper, skipping non-files sources gracefully.

The existing odb_source_files_downcast() is unchanged and continues to BUG() on type mismatch, protecting call sites that should only ever receive a files source (primary source access, vtable callbacks).

This follows the pattern established by the refs subsystem, where eliminating backend downcasts was a prerequisite for adding the reftable backend.

Patch 1/2: Add odb_source_files_try() helper (14 lines, 1 file)

Patch 2/2: Convert 22 iteration sites across 11 files + unit test

Known limitation: repo_approximate_object_count() and has_object_pack() will not account for objects in non-files sources. These are display/optimization functions. A follow-up series can add vtable callbacks to address this.

Aaron Paterson (2):
odb: add odb_source_files_try() for heterogeneous source iteration
odb: use odb_source_files_try() in source-chain iterations

 Makefile                    |  1 +
 builtin/cat-file.c          |  9 ++++++---
 builtin/fast-import.c       |  8 ++++++--
 builtin/grep.c              |  4 +++-
 builtin/pack-objects.c      | 15 +++++++++++----
 commit-graph.c              |  4 +++-
 loose.c                     | 12 +++++++++---
 midx.c                      |  8 ++++++--
 object-file.c               | 20 ++++++++++++++------
 object-name.c               |  8 +++++---
 odb/source-files.h          | 14 ++++++++++++++
 packfile.c                  | 23 +++++++++++++++++------
 packfile.h                  | 14 ++++++++++----
 t/meson.build               |  1 +
 t/unit-tests/u-odb-source.c | 25 +++++++++++++++++++++++++
 15 files changed, 131 insertions(+), 35 deletions(-)
 create mode 100644 t/unit-tests/u-odb-source.c

base-commit: dc6ecd5354dca88d51b6d6562777fc8fc10d77e1
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2068%2FMayCXC%2Fps%2Fodb-source-type-guards-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2068/MayCXC/ps/odb-source-type-guards-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2068

Signature · 1 line
gitgitgadget