aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2026-03-23 16:02:59 +0100
committerJunio C Hamano <gitster@pobox.com>2026-03-23 08:33:10 -0700
commit38e09ebfd444f04e7282e5a7109edb6800864d41 (patch)
tree51d00ba2531b1bd6c97d0637bfc12360def99a4a
parent3ea779432d28b0229ef2a64e6a73a9018ad4c940 (diff)
downloadgit-38e09ebfd444f04e7282e5a7109edb6800864d41.tar.xz
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>
-rw-r--r--builtin/fsck.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/builtin/fsck.c b/builtin/fsck.c
index efc60862ae..be9dbba2da 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -468,13 +468,14 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
static int default_refs;
-static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,
- timestamp_t timestamp)
+static void fsck_handle_reflog_oid(struct repository *repo,
+ const char *refname, struct object_id *oid,
+ timestamp_t timestamp)
{
struct object *obj;
if (!is_null_oid(oid)) {
- obj = lookup_object(the_repository, oid);
+ obj = lookup_object(repo, oid);
if (obj && (obj->flags & HAS_OBJ)) {
if (timestamp)
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,
refname, timestamp);
obj->flags |= USED;
mark_object_reachable(obj);
- } else if (!is_promisor_object(the_repository, oid)) {
+ } else if (!is_promisor_object(repo, oid)) {
error(_("%s: invalid reflog entry %s"),
refname, oid_to_hex(oid));
errors_found |= ERROR_REACHABLE;
@@ -494,8 +495,10 @@ static int fsck_handle_reflog_ent(const char *refname,
struct object_id *ooid, struct object_id *noid,
const char *email UNUSED,
timestamp_t timestamp, int tz UNUSED,
- const char *message UNUSED, void *cb_data UNUSED)
+ const char *message UNUSED, void *cb_data)
{
+ struct repository *repo = cb_data;
+
if (now && timestamp > now)
return 0;
@@ -503,19 +506,20 @@ static int fsck_handle_reflog_ent(const char *refname,
fprintf_ln(stderr, _("Checking reflog %s->%s"),
oid_to_hex(ooid), oid_to_hex(noid));
- fsck_handle_reflog_oid(refname, ooid, 0);
- fsck_handle_reflog_oid(refname, noid, timestamp);
+ fsck_handle_reflog_oid(repo, refname, ooid, 0);
+ fsck_handle_reflog_oid(repo, refname, noid, timestamp);
return 0;
}
static int fsck_handle_reflog(const char *logname, void *cb_data)
{
struct strbuf refname = STRBUF_INIT;
+ struct worktree *wt = cb_data;
- strbuf_worktree_ref(cb_data, &refname, logname);
- refs_for_each_reflog_ent(get_main_ref_store(the_repository),
+ strbuf_worktree_ref(wt, &refname, logname);
+ refs_for_each_reflog_ent(get_main_ref_store(wt->repo),
refname.buf, fsck_handle_reflog_ent,
- NULL);
+ wt->repo);
strbuf_release(&refname);
return 0;
}