Skip to content

Commit 2b2287c

Browse files
pks-tgitster
authored andcommitted
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>
1 parent 38e09eb commit 2b2287c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

builtin/fsck.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -711,27 +711,28 @@ static void process_refs(struct repository *repo, struct snapshot *snap)
711711
}
712712
}
713713

714-
struct for_each_loose_cb
715-
{
714+
struct for_each_loose_cb {
715+
struct repository *repo;
716716
struct progress *progress;
717717
};
718718

719719
static int fsck_loose(const struct object_id *oid, const char *path,
720-
void *data UNUSED)
720+
void *cb_data)
721721
{
722+
struct for_each_loose_cb *data = cb_data;
722723
struct object *obj;
723724
enum object_type type = OBJ_NONE;
724725
unsigned long size;
725726
void *contents = NULL;
726727
int eaten;
727728
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);
729730
int err = 0;
730731

731732
oi.sizep = &size;
732733
oi.typep = &type;
733734

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) {
735736
if (contents && !oideq(&real_oid, oid))
736737
err = error(_("%s: hash-path mismatch, found at: %s"),
737738
oid_to_hex(&real_oid), path);
@@ -748,7 +749,7 @@ static int fsck_loose(const struct object_id *oid, const char *path,
748749
if (!contents && type != OBJ_BLOB)
749750
BUG("read_loose_object streamed a non-blob");
750751

751-
obj = parse_object_buffer(the_repository, oid, type, size,
752+
obj = parse_object_buffer(data->repo, oid, type, size,
752753
contents, &eaten);
753754

754755
if (!obj) {
@@ -790,6 +791,7 @@ static void fsck_source(struct repository *repo, struct odb_source *source)
790791
{
791792
struct progress *progress = NULL;
792793
struct for_each_loose_cb cb_data = {
794+
.repo = source->odb->repo,
793795
.progress = progress,
794796
};
795797

0 commit comments

Comments
 (0)