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

[PATCH 10/14] builtin/fsck: stop using `the_repository` with loose objects

From
Patrick Steinhardt <ps@pks.im>
Date
Mar 20, 2026, 11:47 UTC
Message-ID
<20260320-b4-pks-fsck-without-the-repository-v1-10-6594f997926b@pks.im>
In-Reply-To
<20260320-b4-pks-fsck-without-the-repository-v1-0-6594f997926b@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 | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index ea441b072e..83299c583e 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -400,7 +400,9 @@ static void check_connectivity(struct repository *repo)
 	}
 }
 
-static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
+static int fsck_obj(struct repository *repo,
+		    struct object *obj,
+		    void *buffer, unsigned long size)
 {
 	int err;
 
@@ -413,9 +415,9 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size)
 			   printable_type(&obj->oid, obj->type),
 			   describe_object(&obj->oid));
 
-	if (fsck_walk(the_repository, obj, NULL, &fsck_obj_options))
+	if (fsck_walk(repo, obj, NULL, &fsck_obj_options))
 		objerror(obj, _("broken links"));
-	err = fsck_object(the_repository, obj, buffer, size, &fsck_obj_options);
+	err = fsck_object(repo, obj, buffer, size, &fsck_obj_options);
 	if (err)
 		goto out;
 
@@ -462,7 +464,7 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
 	}
 	obj->flags &= ~(REACHABLE | SEEN);
 	obj->flags |= HAS_OBJ;
-	return fsck_obj(obj, buffer, size);
+	return fsck_obj(the_repository, obj, buffer, size);
 }
 
 static int default_refs;
@@ -710,27 +712,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);
@@ -747,7 +750,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) {
@@ -761,7 +764,7 @@ static int fsck_loose(const struct object_id *oid, const char *path,
 
 	obj->flags &= ~(REACHABLE | SEEN);
 	obj->flags |= HAS_OBJ;
-	if (fsck_obj(obj, contents, size))
+	if (fsck_obj(data->repo, obj, contents, size))
 		errors_found |= ERROR_OBJECT;
 
 	if (!eaten)
@@ -789,6 +792,7 @@ static void fsck_source(struct odb_source *source)
 {
 	struct progress *progress = NULL;
 	struct for_each_loose_cb cb_data = {
+		.repo = source->odb->repo,
 		.progress = progress,
 	};
 
-- 
2.53.0.1055.ga2ffed1127.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 13 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.