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>maint
parent
f223609026
commit
3749853908
|
|
@ -243,7 +243,7 @@ static int mark_unreachable_referents(const struct object_id *oid,
|
||||||
object_as_type(obj, type, 0);
|
object_as_type(obj, type, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fsck_options_init(&options, FSCK_OPTIONS_DEFAULT);
|
fsck_options_init(&options, the_repository, FSCK_OPTIONS_DEFAULT);
|
||||||
options.walk = mark_used;
|
options.walk = mark_used;
|
||||||
fsck_walk(obj, NULL, &options);
|
fsck_walk(obj, NULL, &options);
|
||||||
if (obj->type == OBJ_TREE)
|
if (obj->type == OBJ_TREE)
|
||||||
|
|
@ -987,7 +987,7 @@ static struct option fsck_opts[] = {
|
||||||
int cmd_fsck(int argc,
|
int cmd_fsck(int argc,
|
||||||
const char **argv,
|
const char **argv,
|
||||||
const char *prefix,
|
const char *prefix,
|
||||||
struct repository *repo UNUSED)
|
struct repository *repo)
|
||||||
{
|
{
|
||||||
struct odb_source *source;
|
struct odb_source *source;
|
||||||
struct snapshot snap = {
|
struct snapshot snap = {
|
||||||
|
|
@ -1005,10 +1005,10 @@ int cmd_fsck(int argc,
|
||||||
|
|
||||||
argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
|
argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
|
||||||
|
|
||||||
fsck_options_init(&fsck_walk_options, FSCK_OPTIONS_DEFAULT);
|
fsck_options_init(&fsck_walk_options, repo, FSCK_OPTIONS_DEFAULT);
|
||||||
fsck_walk_options.walk = mark_object;
|
fsck_walk_options.walk = mark_object;
|
||||||
|
|
||||||
fsck_options_init(&fsck_obj_options, FSCK_OPTIONS_DEFAULT);
|
fsck_options_init(&fsck_obj_options, repo, FSCK_OPTIONS_DEFAULT);
|
||||||
fsck_obj_options.walk = mark_used;
|
fsck_obj_options.walk = mark_used;
|
||||||
fsck_obj_options.error_func = fsck_objects_error_func;
|
fsck_obj_options.error_func = fsck_objects_error_func;
|
||||||
if (check_strict)
|
if (check_strict)
|
||||||
|
|
|
||||||
|
|
@ -1909,7 +1909,7 @@ int cmd_index_pack(int argc,
|
||||||
|
|
||||||
disable_replace_refs();
|
disable_replace_refs();
|
||||||
|
|
||||||
fsck_options_init(&fsck_options, FSCK_OPTIONS_MISSING_GITMODULES);
|
fsck_options_init(&fsck_options, the_repository, FSCK_OPTIONS_MISSING_GITMODULES);
|
||||||
fsck_options.walk = mark_link;
|
fsck_options.walk = mark_link;
|
||||||
|
|
||||||
reset_pack_idx_option(&opts);
|
reset_pack_idx_option(&opts);
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
|
||||||
int cmd_mktag(int argc,
|
int cmd_mktag(int argc,
|
||||||
const char **argv,
|
const char **argv,
|
||||||
const char *prefix,
|
const char *prefix,
|
||||||
struct repository *repo UNUSED)
|
struct repository *repo)
|
||||||
{
|
{
|
||||||
static struct option builtin_mktag_options[] = {
|
static struct option builtin_mktag_options[] = {
|
||||||
OPT_BOOL(0, "strict", &option_strict,
|
OPT_BOOL(0, "strict", &option_strict,
|
||||||
|
|
@ -94,7 +94,7 @@ int cmd_mktag(int argc,
|
||||||
if (strbuf_read(&buf, 0, 0) < 0)
|
if (strbuf_read(&buf, 0, 0) < 0)
|
||||||
die_errno(_("could not read from stdin"));
|
die_errno(_("could not read from stdin"));
|
||||||
|
|
||||||
fsck_options_init(&fsck_options, FSCK_OPTIONS_STRICT);
|
fsck_options_init(&fsck_options, repo, FSCK_OPTIONS_STRICT);
|
||||||
fsck_options.error_func = mktag_fsck_error_func;
|
fsck_options.error_func = mktag_fsck_error_func;
|
||||||
fsck_set_msg_type_from_ids(&fsck_options, FSCK_MSG_EXTRA_HEADER_ENTRY,
|
fsck_set_msg_type_from_ids(&fsck_options, FSCK_MSG_EXTRA_HEADER_ENTRY,
|
||||||
FSCK_WARN);
|
FSCK_WARN);
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ out:
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmd_refs_verify(int argc, const char **argv, const char *prefix,
|
static int cmd_refs_verify(int argc, const char **argv, const char *prefix,
|
||||||
struct repository *repo UNUSED)
|
struct repository *repo)
|
||||||
{
|
{
|
||||||
struct fsck_options fsck_refs_options;
|
struct fsck_options fsck_refs_options;
|
||||||
struct worktree **worktrees;
|
struct worktree **worktrees;
|
||||||
|
|
@ -93,7 +93,7 @@ static int cmd_refs_verify(int argc, const char **argv, const char *prefix,
|
||||||
};
|
};
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
fsck_options_init(&fsck_refs_options, FSCK_OPTIONS_REFS);
|
fsck_options_init(&fsck_refs_options, repo, FSCK_OPTIONS_REFS);
|
||||||
|
|
||||||
argc = parse_options(argc, argv, prefix, options, verify_usage, 0);
|
argc = parse_options(argc, argv, prefix, options, verify_usage, 0);
|
||||||
if (argc)
|
if (argc)
|
||||||
|
|
|
||||||
|
|
@ -613,7 +613,7 @@ static void unpack_all(void)
|
||||||
int cmd_unpack_objects(int argc,
|
int cmd_unpack_objects(int argc,
|
||||||
const char **argv,
|
const char **argv,
|
||||||
const char *prefix UNUSED,
|
const char *prefix UNUSED,
|
||||||
struct repository *repo UNUSED)
|
struct repository *repo)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct object_id oid;
|
struct object_id oid;
|
||||||
|
|
@ -627,7 +627,7 @@ int cmd_unpack_objects(int argc,
|
||||||
|
|
||||||
show_usage_if_asked(argc, argv, unpack_usage);
|
show_usage_if_asked(argc, argv, unpack_usage);
|
||||||
|
|
||||||
fsck_options_init(&fsck_options, FSCK_OPTIONS_STRICT);
|
fsck_options_init(&fsck_options, repo, FSCK_OPTIONS_STRICT);
|
||||||
|
|
||||||
for (i = 1 ; i < argc; i++) {
|
for (i = 1 ; i < argc; i++) {
|
||||||
const char *arg = argv[i];
|
const char *arg = argv[i];
|
||||||
|
|
|
||||||
|
|
@ -1229,7 +1229,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
|
||||||
} else
|
} else
|
||||||
alternate_shallow_file = NULL;
|
alternate_shallow_file = NULL;
|
||||||
|
|
||||||
fsck_options_init(&fsck_options, FSCK_OPTIONS_MISSING_GITMODULES);
|
fsck_options_init(&fsck_options, the_repository, FSCK_OPTIONS_MISSING_GITMODULES);
|
||||||
if (get_pack(args, fd, pack_lockfiles, NULL, sought, nr_sought,
|
if (get_pack(args, fd, pack_lockfiles, NULL, sought, nr_sought,
|
||||||
&fsck_options.gitmodules_found))
|
&fsck_options.gitmodules_found))
|
||||||
die(_("git fetch-pack: fetch failed."));
|
die(_("git fetch-pack: fetch failed."));
|
||||||
|
|
@ -1675,7 +1675,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
|
||||||
struct strvec index_pack_args = STRVEC_INIT;
|
struct strvec index_pack_args = STRVEC_INIT;
|
||||||
const char *promisor_remote_config;
|
const char *promisor_remote_config;
|
||||||
|
|
||||||
fsck_options_init(&fsck_options, FSCK_OPTIONS_MISSING_GITMODULES);
|
fsck_options_init(&fsck_options, the_repository, FSCK_OPTIONS_MISSING_GITMODULES);
|
||||||
|
|
||||||
if (server_feature_v2("promisor-remote", &promisor_remote_config))
|
if (server_feature_v2("promisor-remote", &promisor_remote_config))
|
||||||
promisor_remote_reply(promisor_remote_config, NULL);
|
promisor_remote_reply(promisor_remote_config, NULL);
|
||||||
|
|
|
||||||
3
fsck.c
3
fsck.c
|
|
@ -1381,6 +1381,7 @@ bool fsck_has_queued_checks(struct fsck_options *options)
|
||||||
}
|
}
|
||||||
|
|
||||||
void fsck_options_init(struct fsck_options *options,
|
void fsck_options_init(struct fsck_options *options,
|
||||||
|
struct repository *repo,
|
||||||
enum fsck_options_type type)
|
enum fsck_options_type type)
|
||||||
{
|
{
|
||||||
static const struct fsck_options defaults[] = {
|
static const struct fsck_options defaults[] = {
|
||||||
|
|
@ -1423,6 +1424,8 @@ void fsck_options_init(struct fsck_options *options,
|
||||||
default:
|
default:
|
||||||
BUG("unknown fsck options type %d", type);
|
BUG("unknown fsck options type %d", type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options->repo = repo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fsck_options_clear(struct fsck_options *options)
|
void fsck_options_clear(struct fsck_options *options)
|
||||||
|
|
|
||||||
4
fsck.h
4
fsck.h
|
|
@ -166,7 +166,10 @@ struct fsck_ref_report {
|
||||||
const char *path;
|
const char *path;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct repository;
|
||||||
|
|
||||||
struct fsck_options {
|
struct fsck_options {
|
||||||
|
struct repository *repo;
|
||||||
fsck_walk_func walk;
|
fsck_walk_func walk;
|
||||||
fsck_error error_func;
|
fsck_error error_func;
|
||||||
unsigned strict;
|
unsigned strict;
|
||||||
|
|
@ -235,6 +238,7 @@ enum fsck_options_type {
|
||||||
};
|
};
|
||||||
|
|
||||||
void fsck_options_init(struct fsck_options *options,
|
void fsck_options_init(struct fsck_options *options,
|
||||||
|
struct repository *repo,
|
||||||
enum fsck_options_type type);
|
enum fsck_options_type type);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -1281,7 +1281,7 @@ static int index_mem(struct index_state *istate,
|
||||||
if (flags & INDEX_FORMAT_CHECK) {
|
if (flags & INDEX_FORMAT_CHECK) {
|
||||||
struct fsck_options opts;
|
struct fsck_options opts;
|
||||||
|
|
||||||
fsck_options_init(&opts, FSCK_OPTIONS_DEFAULT);
|
fsck_options_init(&opts, the_repository, FSCK_OPTIONS_DEFAULT);
|
||||||
opts.strict = 1;
|
opts.strict = 1;
|
||||||
opts.error_func = hash_format_check_report;
|
opts.error_func = hash_format_check_report;
|
||||||
if (fsck_buffer(null_oid(istate->repo->hash_algo), type, buf, size, &opts))
|
if (fsck_buffer(null_oid(istate->repo->hash_algo), type, buf, size, &opts))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue