From: "Aaron Paterson via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Aaron Paterson <apaterson@pm.me>
Subject: [PATCH 0/2] odb: add odb_source_files_try() for heterogeneous source iteration
Date: Mon, 16 Mar 2026 15:29:41 +0000 [thread overview]
Message-ID: <pull.2068.git.1773674983.gitgitgadget@gmail.com> (raw)
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
--
gitgitgadget
next reply other threads:[~2026-03-16 15:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-16 15:29 Aaron Paterson via GitGitGadget [this message]
2026-03-16 15:29 ` [PATCH 1/2] odb: add odb_source_files_try() for heterogeneous source iteration Aaron Paterson via GitGitGadget
2026-03-16 15:29 ` [PATCH 2/2] odb: use odb_source_files_try() in source-chain iterations Aaron Paterson via GitGitGadget
2026-03-19 10:05 ` Patrick Steinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.2068.git.1773674983.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=apaterson@pm.me \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.