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

[PATCH 08/14] builtin/fsck: stop using `the_repository` when checking refs

From
Patrick Steinhardt <ps@pks.im>
Date
Mar 20, 2026, 11:47 UTC
Message-ID
<20260320-b4-pks-fsck-without-the-repository-v1-8-6594f997926b@pks.im>
In-Reply-To
<20260320-b4-pks-fsck-without-the-repository-v1-0-6594f997926b@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 00476bb921..63cd58e58b 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -573,11 +573,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);
@@ -664,7 +665,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;
 
@@ -673,7 +674,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) {
@@ -1092,7 +1093,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.1055.ga2ffed1127.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 11 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.