[PATCH 07/14] builtin/fsck: stop using `the_repository` when snapshotting refs
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Mar 20, 2026, 11:47 UTC
- Message-ID
- <20260320-b4-pks-fsck-without-the-repository-v1-7-6594f997926b@pks.im>
- In-Reply-To
- <20260320-b4-pks-fsck-without-the-repository-v1-0-6594f997926b@pks.im>
We depedn on `the_repository` when snapshotting refs. Refactor this to use a context-provided repository instead that is injected via the `struct snapshot_ref_data`.
Signed-off-by: Patrick Steinhardt <ps@pks.im> --- builtin/fsck.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c index 8a52ad02ae..00476bb921 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -532,14 +532,20 @@ struct snapshot { /* TODO: Consider also snapshotting the index of each worktree. */ }; +struct snapshot_ref_data { + struct repository *repo; + struct snapshot *snap; +}; + static int snapshot_ref(const struct reference *ref, void *cb_data) { - struct snapshot *snap = cb_data; + struct snapshot_ref_data *data = cb_data; + struct snapshot *snap = data->snap; struct object *obj; - obj = parse_object(the_repository, ref->oid); + obj = parse_object(data->repo, ref->oid); if (!obj) { - if (is_promisor_object(the_repository, ref->oid)) { + if (is_promisor_object(data->repo, ref->oid)) { /* * Increment default_refs anyway, because this is a * valid ref. @@ -586,6 +592,10 @@ static void snapshot_refs(struct repository *repo, struct snapshot *snap, struct refs_for_each_ref_options opts = { .flags = REFS_FOR_EACH_INCLUDE_BROKEN, }; + struct snapshot_ref_data data = { + .repo = repo, + .snap = snap, + }; struct worktree **worktrees, **p; const char *head_points_at; struct object_id head_oid; @@ -599,7 +609,7 @@ static void snapshot_refs(struct repository *repo, struct snapshot *snap, .oid = &oid, }; - snapshot_ref(&ref, snap); + snapshot_ref(&ref, &data); continue; } error(_("invalid parameter: expected sha1, got '%s'"), arg); @@ -612,7 +622,7 @@ static void snapshot_refs(struct repository *repo, struct snapshot *snap, } refs_for_each_ref_ext(get_main_ref_store(repo), - snapshot_ref, snap, &opts); + snapshot_ref, &data, &opts); worktrees = get_worktrees(); for (p = worktrees; *p; p++) { @@ -630,7 +640,7 @@ static void snapshot_refs(struct repository *repo, struct snapshot *snap, .oid = &head_oid, }; - snapshot_ref(&ref, snap); + snapshot_ref(&ref, &data); } strbuf_release(&refname);
-- 2.53.0.1055.ga2ffed1127.dirty