builtin/fsck: stop using `the_repository` when checking refs
We implicitly rely on `the_repository` when checking refs. Refactor this to instead inject the repository via the callback payload. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Mar 23, 2026 at 16:02 UTC
3ea779432d28b0229ef2a64e6a73a9018ad4c940
1 file changed
+6
-5
builtin/fsck.c
+6
-5
@@ -574,11 +574,12 @@ static int snapshot_ref(const struct reference *ref, void *cb_data)
574
return 0;
575
}
576
577
-static int fsck_handle_ref(const struct reference *ref, void *cb_data UNUSED)
577
+static int fsck_handle_ref(const struct reference *ref, void *cb_data)
578
{
579
+ struct repository *repo = cb_data;
580
struct object *obj;
581
581
- obj = parse_object(the_repository, ref->oid);
582
+ obj = parse_object(repo, ref->oid);
583
obj->flags |= USED;
584
fsck_put_object_name(&fsck_walk_options,
585
ref->oid, "%s", ref->name);
@@ -665,7 +666,7 @@ static void free_snapshot_refs(struct snapshot *snap)
666
free(snap->ref);
667
}
668
668
-static void process_refs(struct snapshot *snap)
669
+static void process_refs(struct repository *repo, struct snapshot *snap)
670
{
671
struct worktree **worktrees, **p;
672
@@ -674,7 +675,7 @@ static void process_refs(struct snapshot *snap)
675
.name = snap->ref[i].refname,
676
.oid = &snap->ref[i].oid,
677
};
677
- fsck_handle_ref(&ref, NULL);
678
+ fsck_handle_ref(&ref, repo);
679
}
680
681
if (include_reflogs) {
@@ -1095,7 +1096,7 @@ int cmd_fsck(int argc,
1096
}
1097
1098
/* Process the snapshotted refs and the reflogs. */
1098
- process_refs(&snap);
1099
+ process_refs(repo, &snap);
1100
1101
/* If not given any explicit objects, process index files too. */
1102
if (!argc)