[PATCH 02/14] fsck: drop `the_repository` in `fsck_finish()`
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Mar 20, 2026, 11:47 UTC
- Message-ID
- <20260320-b4-pks-fsck-without-the-repository-v1-2-6594f997926b@pks.im>
- In-Reply-To
- <20260320-b4-pks-fsck-without-the-repository-v1-0-6594f997926b@pks.im>
The function `fsck_finish()` and its transitively called function `fsck_blobs()` implicitly rely on `the_repository`. Remove this dependency by injecting the repository as a parameter instead.
Signed-off-by: Patrick Steinhardt <ps@pks.im> --- builtin/fsck.c | 2 +- builtin/index-pack.c | 2 +- builtin/unpack-objects.c | 2 +- fetch-pack.c | 4 ++-- fsck.c | 13 +++++++------ fsck.h | 2 +- object-file.c | 2 +- 7 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c index 15477767c7..8f994010da 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -1075,7 +1075,7 @@ int cmd_fsck(int argc, stop_progress(&progress); } - if (fsck_finish(&fsck_obj_options)) + if (fsck_finish(the_repository, &fsck_obj_options)) errors_found |= ERROR_OBJECT; } diff --git a/builtin/index-pack.c b/builtin/index-pack.c index a3d37d34cc..3d1f7dbd5f 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -2123,7 +2123,7 @@ int cmd_index_pack(int argc, die(_("cannot perform queued object checks outside " "of a repository")); - if (fsck_finish(&fsck_options)) + if (fsck_finish(the_repository, &fsck_options)) die(_("fsck error in pack objects")); } diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index 52b62ff6d4..9596b3ea4f 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -676,7 +676,7 @@ int cmd_unpack_objects(int argc, git_hash_final_oid(&oid, &tmp_ctx); if (strict) { write_rest(); - if (fsck_finish(&fsck_options)) + if (fsck_finish(the_repository, &fsck_options)) die(_("fsck error in pack objects")); } if (!hasheq(fill(the_hash_algo->rawsz), oid.hash, diff --git a/fetch-pack.c b/fetch-pack.c index 6ecd468ef7..6fd534633d 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -1231,7 +1231,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args, if (get_pack(args, fd, pack_lockfiles, NULL, sought, nr_sought, &fsck_options.gitmodules_found)) die(_("git fetch-pack: fetch failed.")); - if (fsck_finish(&fsck_options)) + if (fsck_finish(the_repository, &fsck_options)) die("fsck failed"); all_done: @@ -1876,7 +1876,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, string_list_clear(&packfile_uris, 0); strvec_clear(&index_pack_args); - if (fsck_finish(&fsck_options)) + if (fsck_finish(the_repository, &fsck_options)) die("fsck failed"); if (negotiator) diff --git a/fsck.c b/fsck.c index c6b6f533be..1f7d568acf 100644 --- a/fsck.c +++ b/fsck.c @@ -1331,7 +1331,8 @@ int fsck_refs_error_function(struct fsck_options *options UNUSED, return ret; } -static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done, +static int fsck_blobs(struct repository *repo, + struct oidset *blobs_found, struct oidset *blobs_done, enum fsck_msg_id msg_missing, enum fsck_msg_id msg_type, struct fsck_options *options, const char *blob_type) { @@ -1348,9 +1349,9 @@ static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done, if (oidset_contains(blobs_done, oid)) continue; - buf = odb_read_object(the_repository->objects, oid, &type, &size); + buf = odb_read_object(repo->objects, oid, &type, &size); if (!buf) { - if (is_promisor_object(the_repository, oid)) + if (is_promisor_object(repo, oid)) continue; ret |= report(options, oid, OBJ_BLOB, msg_missing, @@ -1372,14 +1373,14 @@ static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done, return ret; } -int fsck_finish(struct fsck_options *options) +int fsck_finish(struct repository *repo, struct fsck_options *options) { int ret = 0; - ret |= fsck_blobs(&options->gitmodules_found, &options->gitmodules_done, + ret |= fsck_blobs(repo, &options->gitmodules_found, &options->gitmodules_done, FSCK_MSG_GITMODULES_MISSING, FSCK_MSG_GITMODULES_BLOB, options, ".gitmodules"); - ret |= fsck_blobs(&options->gitattributes_found, &options->gitattributes_done, + ret |= fsck_blobs(repo, &options->gitattributes_found, &options->gitattributes_done, FSCK_MSG_GITATTRIBUTES_MISSING, FSCK_MSG_GITATTRIBUTES_BLOB, options, ".gitattributes"); diff --git a/fsck.h b/fsck.h index 4bd54865fe..bfe9b3ffc9 100644 --- a/fsck.h +++ b/fsck.h @@ -255,7 +255,7 @@ int fsck_tag_standalone(const struct object_id *oid, const char *buffer, * after completing all fsck_object() calls in order to resolve any remaining * checks. */ -int fsck_finish(struct fsck_options *options); +int fsck_finish(struct repository *repo, struct fsck_options *options); /* * Check whether there are any checks that have been queued up and that still diff --git a/object-file.c b/object-file.c index c62e5496e0..ecbcc501dd 100644 --- a/object-file.c +++ b/object-file.c @@ -1285,7 +1285,7 @@ static int index_mem(struct index_state *istate, opts.error_func = hash_format_check_report; if (fsck_buffer(null_oid(istate->repo->hash_algo), type, buf, size, &opts)) die(_("refusing to create malformed object")); - fsck_finish(&opts); + fsck_finish(the_repository, &opts); } if (write_object)
-- 2.53.0.1055.ga2ffed1127.dirty