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

[PATCH v2 09/12] builtin/fsck: stop using `the_repository` with loose objects

From
Patrick Steinhardt <ps@pks.im>
Date
Mar 23, 2026, 15:03 UTC
Message-ID
<20260323-b4-pks-fsck-without-the-repository-v2-9-e8dc79bca651@pks.im>
In-Reply-To
<20260323-b4-pks-fsck-without-the-repository-v2-0-e8dc79bca651@pks.im>

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>
---
 builtin/fsck.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index be9dbba2da..e8bdec7cd0 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -711,27 +711,28 @@ static void process_refs(struct repository *repo, struct snapshot *snap)
 	}
 }
 
-struct for_each_loose_cb
-{
+struct for_each_loose_cb {
+	struct repository *repo;
 	struct progress *progress;
 };
 
 static int fsck_loose(const struct object_id *oid, const char *path,
-		      void *data UNUSED)
+		      void *cb_data)
 {
+	struct for_each_loose_cb *data = cb_data;
 	struct object *obj;
 	enum object_type type = OBJ_NONE;
 	unsigned long size;
 	void *contents = NULL;
 	int eaten;
 	struct object_info oi = OBJECT_INFO_INIT;
-	struct object_id real_oid = *null_oid(the_hash_algo);
+	struct object_id real_oid = *null_oid(data->repo->hash_algo);
 	int err = 0;
 
 	oi.sizep = &size;
 	oi.typep = &type;
 
-	if (read_loose_object(the_repository, path, oid, &real_oid, &contents, &oi) < 0) {
+	if (read_loose_object(data->repo, path, oid, &real_oid, &contents, &oi) < 0) {
 		if (contents && !oideq(&real_oid, oid))
 			err = error(_("%s: hash-path mismatch, found at: %s"),
 				    oid_to_hex(&real_oid), path);
@@ -748,7 +749,7 @@ static int fsck_loose(const struct object_id *oid, const char *path,
 	if (!contents && type != OBJ_BLOB)
 		BUG("read_loose_object streamed a non-blob");
 
-	obj = parse_object_buffer(the_repository, oid, type, size,
+	obj = parse_object_buffer(data->repo, oid, type, size,
 				  contents, &eaten);
 
 	if (!obj) {
@@ -790,6 +791,7 @@ static void fsck_source(struct repository *repo, struct odb_source *source)
 {
 	struct progress *progress = NULL;
 	struct for_each_loose_cb cb_data = {
+		.repo = source->odb->repo,
 		.progress = progress,
 	};
 
-- 
2.53.0.1118.gaef5881109.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 12 of 17 in “fsck: drop use of `the_repository`”
  1. 00/12 fsck: drop use of `the_repository`Patrick Steinhardt, Mar 23, 2026
  2. 01/12 fetch-pack: move fsck options into function scopePatrick Steinhardt, Mar 23, 2026
  3. Junio C HamanoMar 23, 2026
  4. 02/12 fsck: initialize fsck options via a functionPatrick Steinhardt, Mar 23, 2026
  5. Junio C HamanoMar 23, 2026
  6. 03/12 fsck: store repository in fsck optionsPatrick Steinhardt, Mar 23, 2026
  7. 04/12 fsck: drop USE_THE_REPOSITORYPatrick Steinhardt, Mar 23, 2026
  8. 05/12 builtin/fsck: fix trivial dependence on `the_repository`Patrick Steinhardt, Mar 23, 2026
  9. 06/12 builtin/fsck: stop using `the_repository` when snapshotting refsPatrick Steinhardt, Mar 23, 2026
  10. 07/12 builtin/fsck: stop using `the_repository` when checking refsPatrick Steinhardt, Mar 23, 2026
  11. 08/12 builtin/fsck: stop using `the_repository` when checking reflogsPatrick Steinhardt, Mar 23, 2026
  12. 09/12 builtin/fsck: stop using `the_repository` with loose objectsPatrick Steinhardt, Mar 23, 2026
  13. 10/12 builtin/fsck: stop using `the_repository` when checking packed objectsPatrick Steinhardt, Mar 23, 2026
  14. 11/12 builtin/fsck: stop using `the_repository` when marking objectsPatrick Steinhardt, Mar 23, 2026
  15. 12/12 builtin/fsck: stop using `the_repository` in error reportingPatrick Steinhardt, Mar 23, 2026
  16. Junio C HamanoMar 31, 2026
  17. Patrick SteinhardtMar 31, 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.