builtin/fsck: stop using `the_repository` with loose objects

We depend on `the_repository` when performing consistency checks for loose objects. Refactor this to use a context-provided repository instead that is injected via the `struct for_each_loose_cb`. 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:03 UTC 2b2287c479ced6f794a7c8d305c39eef4ee563f5
1 file changed +8 -6
builtin/fsck.c
+8 -6
@@ -711,27 +711,28 @@ static void process_refs(struct repository *repo, struct snapshot *snap)
711 }
712 }
713
714 -struct for_each_loose_cb
715 -{
714 +struct for_each_loose_cb {
715 + struct repository *repo;
716 struct progress *progress;
717 };
718
719 static int fsck_loose(const struct object_id *oid, const char *path,
720 - void *data UNUSED)
720 + void *cb_data)
721 {
722 + struct for_each_loose_cb *data = cb_data;
723 struct object *obj;
724 enum object_type type = OBJ_NONE;
725 unsigned long size;
726 void *contents = NULL;
727 int eaten;
728 struct object_info oi = OBJECT_INFO_INIT;
728 - struct object_id real_oid = *null_oid(the_hash_algo);
729 + struct object_id real_oid = *null_oid(data->repo->hash_algo);
730 int err = 0;
731
732 oi.sizep = &size;
733 oi.typep = &type;
734
734 - if (read_loose_object(the_repository, path, oid, &real_oid, &contents, &oi) < 0) {
735 + if (read_loose_object(data->repo, path, oid, &real_oid, &contents, &oi) < 0) {
736 if (contents && !oideq(&real_oid, oid))
737 err = error(_("%s: hash-path mismatch, found at: %s"),
738 oid_to_hex(&real_oid), path);
@@ -748,7 +749,7 @@ static int fsck_loose(const struct object_id *oid, const char *path,
749 if (!contents && type != OBJ_BLOB)
750 BUG("read_loose_object streamed a non-blob");
751
751 - obj = parse_object_buffer(the_repository, oid, type, size,
752 + obj = parse_object_buffer(data->repo, oid, type, size,
753 contents, &eaten);
754
755 if (!obj) {
@@ -790,6 +791,7 @@ static void fsck_source(struct repository *repo, struct odb_source *source)
791 {
792 struct progress *progress = NULL;
793 struct for_each_loose_cb cb_data = {
794 + .repo = source->odb->repo,
795 .progress = progress,
796 };
797