Skip to content

Commit 38e09eb

Browse files
pks-tgitster
authored andcommitted
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>
1 parent 3ea7794 commit 38e09eb

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

builtin/fsck.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -468,21 +468,22 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
468468

469469
static int default_refs;
470470

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)
473474
{
474475
struct object *obj;
475476

476477
if (!is_null_oid(oid)) {
477-
obj = lookup_object(the_repository, oid);
478+
obj = lookup_object(repo, oid);
478479
if (obj && (obj->flags & HAS_OBJ)) {
479480
if (timestamp)
480481
fsck_put_object_name(&fsck_walk_options, oid,
481482
"%s@{%"PRItime"}",
482483
refname, timestamp);
483484
obj->flags |= USED;
484485
mark_object_reachable(obj);
485-
} else if (!is_promisor_object(the_repository, oid)) {
486+
} else if (!is_promisor_object(repo, oid)) {
486487
error(_("%s: invalid reflog entry %s"),
487488
refname, oid_to_hex(oid));
488489
errors_found |= ERROR_REACHABLE;
@@ -494,28 +495,31 @@ static int fsck_handle_reflog_ent(const char *refname,
494495
struct object_id *ooid, struct object_id *noid,
495496
const char *email UNUSED,
496497
timestamp_t timestamp, int tz UNUSED,
497-
const char *message UNUSED, void *cb_data UNUSED)
498+
const char *message UNUSED, void *cb_data)
498499
{
500+
struct repository *repo = cb_data;
501+
499502
if (now && timestamp > now)
500503
return 0;
501504

502505
if (verbose)
503506
fprintf_ln(stderr, _("Checking reflog %s->%s"),
504507
oid_to_hex(ooid), oid_to_hex(noid));
505508

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);
508511
return 0;
509512
}
510513

511514
static int fsck_handle_reflog(const char *logname, void *cb_data)
512515
{
513516
struct strbuf refname = STRBUF_INIT;
517+
struct worktree *wt = cb_data;
514518

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),
517521
refname.buf, fsck_handle_reflog_ent,
518-
NULL);
522+
wt->repo);
519523
strbuf_release(&refname);
520524
return 0;
521525
}

0 commit comments

Comments
 (0)