fsck: store repository in fsck options
The fsck subsystem relies on `the_repository` quite a bit. While we could of course explicitly pass a repository down the callchain, we already have a `struct fsck_options` that we pass to almost all functions. Extend the options to also store the repository to make it readily available. Suggested-by: Junio C Hamano <gitster@pobox.com> 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
374985390871cb67c02b1608b693480e89567b9a
9 files changed
+21
-14
builtin/fsck.c
+4
-4
@@ -243,7 +243,7 @@ static int mark_unreachable_referents(const struct object_id *oid,
243
object_as_type(obj, type, 0);
244
}
245
246
- fsck_options_init(&options, FSCK_OPTIONS_DEFAULT);
246
+ fsck_options_init(&options, the_repository, FSCK_OPTIONS_DEFAULT);
247
options.walk = mark_used;
248
fsck_walk(obj, NULL, &options);
249
if (obj->type == OBJ_TREE)
@@ -987,7 +987,7 @@ static struct option fsck_opts[] = {
987
int cmd_fsck(int argc,
988
const char **argv,
989
const char *prefix,
990
- struct repository *repo UNUSED)
990
+ struct repository *repo)
991
{
992
struct odb_source *source;
993
struct snapshot snap = {
@@ -1005,10 +1005,10 @@ int cmd_fsck(int argc,
1005
1006
argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
1007
1008
- fsck_options_init(&fsck_walk_options, FSCK_OPTIONS_DEFAULT);
1008
+ fsck_options_init(&fsck_walk_options, repo, FSCK_OPTIONS_DEFAULT);
1009
fsck_walk_options.walk = mark_object;
1010
1011
- fsck_options_init(&fsck_obj_options, FSCK_OPTIONS_DEFAULT);
1011
+ fsck_options_init(&fsck_obj_options, repo, FSCK_OPTIONS_DEFAULT);
1012
fsck_obj_options.walk = mark_used;
1013
fsck_obj_options.error_func = fsck_objects_error_func;
1014
if (check_strict)
builtin/index-pack.c
+1
-1
@@ -1909,7 +1909,7 @@ int cmd_index_pack(int argc,
1909
1910
disable_replace_refs();
1911
1912
- fsck_options_init(&fsck_options, FSCK_OPTIONS_MISSING_GITMODULES);
1912
+ fsck_options_init(&fsck_options, the_repository, FSCK_OPTIONS_MISSING_GITMODULES);
1913
fsck_options.walk = mark_link;
1914
1915
reset_pack_idx_option(&opts);
builtin/mktag.c
+2
-2
@@ -75,7 +75,7 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
75
int cmd_mktag(int argc,
76
const char **argv,
77
const char *prefix,
78
- struct repository *repo UNUSED)
78
+ struct repository *repo)
79
{
80
static struct option builtin_mktag_options[] = {
81
OPT_BOOL(0, "strict", &option_strict,
@@ -94,7 +94,7 @@ int cmd_mktag(int argc,
94
if (strbuf_read(&buf, 0, 0) < 0)
95
die_errno(_("could not read from stdin"));
96
97
- fsck_options_init(&fsck_options, FSCK_OPTIONS_STRICT);
97
+ fsck_options_init(&fsck_options, repo, FSCK_OPTIONS_STRICT);
98
fsck_options.error_func = mktag_fsck_error_func;
99
fsck_set_msg_type_from_ids(&fsck_options, FSCK_MSG_EXTRA_HEADER_ENTRY,
100
FSCK_WARN);
builtin/refs.c
+2
-2
@@ -78,7 +78,7 @@ out:
78
}
79
80
static int cmd_refs_verify(int argc, const char **argv, const char *prefix,
81
- struct repository *repo UNUSED)
81
+ struct repository *repo)
82
{
83
struct fsck_options fsck_refs_options;
84
struct worktree **worktrees;
@@ -93,7 +93,7 @@ static int cmd_refs_verify(int argc, const char **argv, const char *prefix,
93
};
94
int ret = 0;
95
96
- fsck_options_init(&fsck_refs_options, FSCK_OPTIONS_REFS);
96
+ fsck_options_init(&fsck_refs_options, repo, FSCK_OPTIONS_REFS);
97
98
argc = parse_options(argc, argv, prefix, options, verify_usage, 0);
99
if (argc)
builtin/unpack-objects.c
+2
-2
@@ -613,7 +613,7 @@ static void unpack_all(void)
613
int cmd_unpack_objects(int argc,
614
const char **argv,
615
const char *prefix UNUSED,
616
- struct repository *repo UNUSED)
616
+ struct repository *repo)
617
{
618
int i;
619
struct object_id oid;
@@ -627,7 +627,7 @@ int cmd_unpack_objects(int argc,
627
628
show_usage_if_asked(argc, argv, unpack_usage);
629
630
- fsck_options_init(&fsck_options, FSCK_OPTIONS_STRICT);
630
+ fsck_options_init(&fsck_options, repo, FSCK_OPTIONS_STRICT);
631
632
for (i = 1 ; i < argc; i++) {
633
const char *arg = argv[i];
fetch-pack.c
+2
-2
@@ -1229,7 +1229,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
1229
} else
1230
alternate_shallow_file = NULL;
1231
1232
- fsck_options_init(&fsck_options, FSCK_OPTIONS_MISSING_GITMODULES);
1232
+ fsck_options_init(&fsck_options, the_repository, FSCK_OPTIONS_MISSING_GITMODULES);
1233
if (get_pack(args, fd, pack_lockfiles, NULL, sought, nr_sought,
1234
&fsck_options.gitmodules_found))
1235
die(_("git fetch-pack: fetch failed."));
@@ -1675,7 +1675,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
1675
struct strvec index_pack_args = STRVEC_INIT;
1676
const char *promisor_remote_config;
1677
1678
- fsck_options_init(&fsck_options, FSCK_OPTIONS_MISSING_GITMODULES);
1678
+ fsck_options_init(&fsck_options, the_repository, FSCK_OPTIONS_MISSING_GITMODULES);
1679
1680
if (server_feature_v2("promisor-remote", &promisor_remote_config))
1681
promisor_remote_reply(promisor_remote_config, NULL);
fsck.c
+3
@@ -1381,6 +1381,7 @@ bool fsck_has_queued_checks(struct fsck_options *options)
1381
}
1382
1383
void fsck_options_init(struct fsck_options *options,
1384
+ struct repository *repo,
1385
enum fsck_options_type type)
1386
{
1387
static const struct fsck_options defaults[] = {
@@ -1423,6 +1424,8 @@ void fsck_options_init(struct fsck_options *options,
1424
default:
1425
BUG("unknown fsck options type %d", type);
1426
}
1427
+
1428
+ options->repo = repo;
1429
}
1430
1431
void fsck_options_clear(struct fsck_options *options)
fsck.h
+4
@@ -166,7 +166,10 @@ struct fsck_ref_report {
166
const char *path;
167
};
168
169
+struct repository;
170
+
171
struct fsck_options {
172
+ struct repository *repo;
173
fsck_walk_func walk;
174
fsck_error error_func;
175
unsigned strict;
@@ -235,6 +238,7 @@ enum fsck_options_type {
238
};
239
240
void fsck_options_init(struct fsck_options *options,
241
+ struct repository *repo,
242
enum fsck_options_type type);
243
244
/*
object-file.c
+1
-1
@@ -1281,7 +1281,7 @@ static int index_mem(struct index_state *istate,
1281
if (flags & INDEX_FORMAT_CHECK) {
1282
struct fsck_options opts;
1283
1284
- fsck_options_init(&opts, FSCK_OPTIONS_DEFAULT);
1284
+ fsck_options_init(&opts, the_repository, FSCK_OPTIONS_DEFAULT);
1285
opts.strict = 1;
1286
opts.error_func = hash_format_check_report;
1287
if (fsck_buffer(null_oid(istate->repo->hash_algo), type, buf, size, &opts))