git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[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
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 5 of 18 in “fsck: drop use of `the_repository`”
  1. 00/14 fsck: drop use of `the_repository`Patrick Steinhardt, Mar 20, 2026
  2. 01/14 fsck: drop `the_repository` in `fsck_walk()`Patrick Steinhardt, Mar 20, 2026
  3. Junio C HamanoMar 20, 2026
  4. Patrick SteinhardtMar 23, 2026
  5. 02/14 fsck: drop `the_repository` in `fsck_finish()`Patrick Steinhardt, Mar 20, 2026
  6. 03/14 fsck: refactor interface to parse fsck optionsPatrick Steinhardt, Mar 20, 2026
  7. 04/14 fsck: drop `the_repository` in `fsck_set_msg_types()`Patrick Steinhardt, Mar 20, 2026
  8. 05/14 fsck: stop relying on global state via `parse_oid_hex()`Patrick Steinhardt, Mar 20, 2026
  9. 06/14 builtin/fsck: fix trivial dependence on `the_repository`Patrick Steinhardt, Mar 20, 2026
  10. 07/14 builtin/fsck: stop using `the_repository` when snapshotting refsPatrick Steinhardt, Mar 20, 2026
  11. 08/14 builtin/fsck: stop using `the_repository` when checking refsPatrick Steinhardt, Mar 20, 2026
  12. 09/14 builtin/fsck: stop using `the_repository` when checking reflogsPatrick Steinhardt, Mar 20, 2026
  13. 10/14 builtin/fsck: stop using `the_repository` with loose objectsPatrick Steinhardt, Mar 20, 2026
  14. 11/14 builtin/fsck: stop using `the_repository` when checking packed objectsPatrick Steinhardt, Mar 20, 2026
  15. 12/14 builtin/fsck: stop using `the_repository` when marking objectsPatrick Steinhardt, Mar 20, 2026
  16. 13/14 fsck: provide repository in `struct fsck_report_object`Patrick Steinhardt, Mar 20, 2026
  17. Junio C HamanoMar 20, 2026
  18. 14/14 builtin/fsck: stop using `the_repository` in error reportingPatrick Steinhardt, Mar 20, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.