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

[PATCH v2 07/12] builtin/fsck: stop using `the_repository` when checking refs

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

We implicitly rely on `the_repository` when checking refs. Refactor this to instead inject the repository via the callback payload.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/fsck.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/builtin/fsck.c b/builtin/fsck.c
index edbff16add..efc60862ae 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -574,11 +574,12 @@ static int snapshot_ref(const struct reference *ref, void *cb_data)
 	return 0;
 }
 
-static int fsck_handle_ref(const struct reference *ref, void *cb_data UNUSED)
+static int fsck_handle_ref(const struct reference *ref, void *cb_data)
 {
+	struct repository *repo = cb_data;
 	struct object *obj;
 
-	obj = parse_object(the_repository, ref->oid);
+	obj = parse_object(repo, ref->oid);
 	obj->flags |= USED;
 	fsck_put_object_name(&fsck_walk_options,
 			     ref->oid, "%s", ref->name);
@@ -665,7 +666,7 @@ static void free_snapshot_refs(struct snapshot *snap)
 	free(snap->ref);
 }
 
-static void process_refs(struct snapshot *snap)
+static void process_refs(struct repository *repo, struct snapshot *snap)
 {
 	struct worktree **worktrees, **p;
 
@@ -674,7 +675,7 @@ static void process_refs(struct snapshot *snap)
 			.name = snap->ref[i].refname,
 			.oid = &snap->ref[i].oid,
 		};
-		fsck_handle_ref(&ref, NULL);
+		fsck_handle_ref(&ref, repo);
 	}
 
 	if (include_reflogs) {
@@ -1095,7 +1096,7 @@ int cmd_fsck(int argc,
 	}
 
 	/* Process the snapshotted refs and the reflogs. */
-	process_refs(&snap);
+	process_refs(repo, &snap);
 
 	/* If not given any explicit objects, process index files too. */
 	if (!argc)
-- 
2.53.0.1118.gaef5881109.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 10 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.