Skip to content

Commit 3749853

Browse files
pks-tgitster
authored andcommitted
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>
1 parent f223609 commit 3749853

9 files changed

Lines changed: 21 additions & 14 deletions

File tree

builtin/fsck.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static int mark_unreachable_referents(const struct object_id *oid,
243243
object_as_type(obj, type, 0);
244244
}
245245

246-
fsck_options_init(&options, FSCK_OPTIONS_DEFAULT);
246+
fsck_options_init(&options, the_repository, FSCK_OPTIONS_DEFAULT);
247247
options.walk = mark_used;
248248
fsck_walk(obj, NULL, &options);
249249
if (obj->type == OBJ_TREE)
@@ -987,7 +987,7 @@ static struct option fsck_opts[] = {
987987
int cmd_fsck(int argc,
988988
const char **argv,
989989
const char *prefix,
990-
struct repository *repo UNUSED)
990+
struct repository *repo)
991991
{
992992
struct odb_source *source;
993993
struct snapshot snap = {
@@ -1005,10 +1005,10 @@ int cmd_fsck(int argc,
10051005

10061006
argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
10071007

1008-
fsck_options_init(&fsck_walk_options, FSCK_OPTIONS_DEFAULT);
1008+
fsck_options_init(&fsck_walk_options, repo, FSCK_OPTIONS_DEFAULT);
10091009
fsck_walk_options.walk = mark_object;
10101010

1011-
fsck_options_init(&fsck_obj_options, FSCK_OPTIONS_DEFAULT);
1011+
fsck_options_init(&fsck_obj_options, repo, FSCK_OPTIONS_DEFAULT);
10121012
fsck_obj_options.walk = mark_used;
10131013
fsck_obj_options.error_func = fsck_objects_error_func;
10141014
if (check_strict)

builtin/index-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,7 @@ int cmd_index_pack(int argc,
19091909

19101910
disable_replace_refs();
19111911

1912-
fsck_options_init(&fsck_options, FSCK_OPTIONS_MISSING_GITMODULES);
1912+
fsck_options_init(&fsck_options, the_repository, FSCK_OPTIONS_MISSING_GITMODULES);
19131913
fsck_options.walk = mark_link;
19141914

19151915
reset_pack_idx_option(&opts);

builtin/mktag.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
7575
int cmd_mktag(int argc,
7676
const char **argv,
7777
const char *prefix,
78-
struct repository *repo UNUSED)
78+
struct repository *repo)
7979
{
8080
static struct option builtin_mktag_options[] = {
8181
OPT_BOOL(0, "strict", &option_strict,
@@ -94,7 +94,7 @@ int cmd_mktag(int argc,
9494
if (strbuf_read(&buf, 0, 0) < 0)
9595
die_errno(_("could not read from stdin"));
9696

97-
fsck_options_init(&fsck_options, FSCK_OPTIONS_STRICT);
97+
fsck_options_init(&fsck_options, repo, FSCK_OPTIONS_STRICT);
9898
fsck_options.error_func = mktag_fsck_error_func;
9999
fsck_set_msg_type_from_ids(&fsck_options, FSCK_MSG_EXTRA_HEADER_ENTRY,
100100
FSCK_WARN);

builtin/refs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static int cmd_refs_migrate(int argc, const char **argv, const char *prefix,
7878
}
7979

8080
static int cmd_refs_verify(int argc, const char **argv, const char *prefix,
81-
struct repository *repo UNUSED)
81+
struct repository *repo)
8282
{
8383
struct fsck_options fsck_refs_options;
8484
struct worktree **worktrees;
@@ -93,7 +93,7 @@ static int cmd_refs_verify(int argc, const char **argv, const char *prefix,
9393
};
9494
int ret = 0;
9595

96-
fsck_options_init(&fsck_refs_options, FSCK_OPTIONS_REFS);
96+
fsck_options_init(&fsck_refs_options, repo, FSCK_OPTIONS_REFS);
9797

9898
argc = parse_options(argc, argv, prefix, options, verify_usage, 0);
9999
if (argc)

builtin/unpack-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ static void unpack_all(void)
613613
int cmd_unpack_objects(int argc,
614614
const char **argv,
615615
const char *prefix UNUSED,
616-
struct repository *repo UNUSED)
616+
struct repository *repo)
617617
{
618618
int i;
619619
struct object_id oid;
@@ -627,7 +627,7 @@ int cmd_unpack_objects(int argc,
627627

628628
show_usage_if_asked(argc, argv, unpack_usage);
629629

630-
fsck_options_init(&fsck_options, FSCK_OPTIONS_STRICT);
630+
fsck_options_init(&fsck_options, repo, FSCK_OPTIONS_STRICT);
631631

632632
for (i = 1 ; i < argc; i++) {
633633
const char *arg = argv[i];

fetch-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
12291229
} else
12301230
alternate_shallow_file = NULL;
12311231

1232-
fsck_options_init(&fsck_options, FSCK_OPTIONS_MISSING_GITMODULES);
1232+
fsck_options_init(&fsck_options, the_repository, FSCK_OPTIONS_MISSING_GITMODULES);
12331233
if (get_pack(args, fd, pack_lockfiles, NULL, sought, nr_sought,
12341234
&fsck_options.gitmodules_found))
12351235
die(_("git fetch-pack: fetch failed."));
@@ -1675,7 +1675,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
16751675
struct strvec index_pack_args = STRVEC_INIT;
16761676
const char *promisor_remote_config;
16771677

1678-
fsck_options_init(&fsck_options, FSCK_OPTIONS_MISSING_GITMODULES);
1678+
fsck_options_init(&fsck_options, the_repository, FSCK_OPTIONS_MISSING_GITMODULES);
16791679

16801680
if (server_feature_v2("promisor-remote", &promisor_remote_config))
16811681
promisor_remote_reply(promisor_remote_config, NULL);

fsck.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,7 @@ bool fsck_has_queued_checks(struct fsck_options *options)
13811381
}
13821382

13831383
void fsck_options_init(struct fsck_options *options,
1384+
struct repository *repo,
13841385
enum fsck_options_type type)
13851386
{
13861387
static const struct fsck_options defaults[] = {
@@ -1423,6 +1424,8 @@ void fsck_options_init(struct fsck_options *options,
14231424
default:
14241425
BUG("unknown fsck options type %d", type);
14251426
}
1427+
1428+
options->repo = repo;
14261429
}
14271430

14281431
void fsck_options_clear(struct fsck_options *options)

fsck.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ struct fsck_ref_report {
166166
const char *path;
167167
};
168168

169+
struct repository;
170+
169171
struct fsck_options {
172+
struct repository *repo;
170173
fsck_walk_func walk;
171174
fsck_error error_func;
172175
unsigned strict;
@@ -235,6 +238,7 @@ enum fsck_options_type {
235238
};
236239

237240
void fsck_options_init(struct fsck_options *options,
241+
struct repository *repo,
238242
enum fsck_options_type type);
239243

240244
/*

object-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ static int index_mem(struct index_state *istate,
12811281
if (flags & INDEX_FORMAT_CHECK) {
12821282
struct fsck_options opts;
12831283

1284-
fsck_options_init(&opts, FSCK_OPTIONS_DEFAULT);
1284+
fsck_options_init(&opts, the_repository, FSCK_OPTIONS_DEFAULT);
12851285
opts.strict = 1;
12861286
opts.error_func = hash_format_check_report;
12871287
if (fsck_buffer(null_oid(istate->repo->hash_algo), type, buf, size, &opts))

0 commit comments

Comments
 (0)