builtin/fsck: stop using `the_repository` when checking reflogs

We implicitly rely on `the_repository` when checking reflogs. Refactor this to instead inject the repository via the callback payload. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Mar 23, 2026 at 16:02 UTC 38e09ebfd444f04e7282e5a7109edb6800864d41
1 file changed +14 -10
builtin/fsck.c
+14 -10
@@ -468,13 +468,14 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
468
469 static int default_refs;
470
471 -static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
472 - timestamp_t timestamp)
471 +static void fsck_handle_reflog_oid(struct repository *repo,
472 + const char *refname, struct object_id *oid,
473 + timestamp_t timestamp)
474 {
475 struct object *obj;
476
477 if (!is_null_oid(oid)) {
477 - obj = lookup_object(the_repository, oid);
478 + obj = lookup_object(repo, oid);
479 if (obj && (obj->flags & HAS_OBJ)) {
480 if (timestamp)
481 fsck_put_object_name(&fsck_walk_options, oid,
@@ -482,7 +483,7 @@ static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
483 refname, timestamp);
484 obj->flags |= USED;
485 mark_object_reachable(obj);
485 - } else if (!is_promisor_object(the_repository, oid)) {
486 + } else if (!is_promisor_object(repo, oid)) {
487 error(_("%s: invalid reflog entry %s"),
488 refname, oid_to_hex(oid));
489 errors_found |= ERROR_REACHABLE;
@@ -494,8 +495,10 @@ static int fsck_handle_reflog_ent(const char *refname,
495 struct object_id *ooid, struct object_id *noid,
496 const char *email UNUSED,
497 timestamp_t timestamp, int tz UNUSED,
497 - const char *message UNUSED, void *cb_data UNUSED)
498 + const char *message UNUSED, void *cb_data)
499 {
500 + struct repository *repo = cb_data;
501 +
502 if (now && timestamp > now)
503 return 0;
504
@@ -503,19 +506,20 @@ static int fsck_handle_reflog_ent(const char *refname,
506 fprintf_ln(stderr, _("Checking reflog %s->%s"),
507 oid_to_hex(ooid), oid_to_hex(noid));
508
506 - fsck_handle_reflog_oid(refname, ooid, 0);
507 - fsck_handle_reflog_oid(refname, noid, timestamp);
509 + fsck_handle_reflog_oid(repo, refname, ooid, 0);
510 + fsck_handle_reflog_oid(repo, refname, noid, timestamp);
511 return 0;
512 }
513
514 static int fsck_handle_reflog(const char *logname, void *cb_data)
515 {
516 struct strbuf refname = STRBUF_INIT;
517 + struct worktree *wt = cb_data;
518
515 - strbuf_worktree_ref(cb_data, &refname, logname);
516 - refs_for_each_reflog_ent(get_main_ref_store(the_repository),
519 + strbuf_worktree_ref(wt, &refname, logname);
520 + refs_for_each_reflog_ent(get_main_ref_store(wt->repo),
521 refname.buf, fsck_handle_reflog_ent,
518 - NULL);
522 + wt->repo);
523 strbuf_release(&refname);
524 return 0;
525 }