aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2026-03-23 16:02:53 +0100
committerJunio C Hamano <gitster@pobox.com>2026-03-23 08:33:10 -0700
commitf22360902621e0807a1c0a77476e3e4d323c708d (patch)
treead15abf7edc06866b913901a3de9aee6b31218a3 /builtin
parent17cabd369b5cb96bee9577f49247ef95d07058a7 (diff)
downloadgit-f22360902621e0807a1c0a77476e3e4d323c708d.tar.xz
fsck: initialize fsck options via a function
We initialize the `struct fsck_options` via a set of macros, often in global scope. In the next commit though we're about to introduce a new repository field to the options that must be initialized, and naturally we don't have a repo other than `the_repository` available in this scope. Refactor the code to instead intrdouce a new `fsck_options_init()` function that initializes the options for us and move initialization into function scope. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/fsck.c10
-rw-r--r--builtin/index-pack.c4
-rw-r--r--builtin/mktag.c3
-rw-r--r--builtin/refs.c4
-rw-r--r--builtin/unpack-objects.c4
5 files changed, 18 insertions, 7 deletions
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 9bab32effe..59e3b0f7ac 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -42,8 +42,8 @@ static int check_full = 1;
static int connectivity_only;
static int check_strict;
static int keep_cache_objects;
-static struct fsck_options fsck_walk_options = FSCK_OPTIONS_DEFAULT;
-static struct fsck_options fsck_obj_options = FSCK_OPTIONS_DEFAULT;
+static struct fsck_options fsck_walk_options;
+static struct fsck_options fsck_obj_options;
static int errors_found;
static int write_lost_and_found;
static int verbose;
@@ -224,7 +224,7 @@ static int mark_unreachable_referents(const struct object_id *oid,
struct object_info *oi UNUSED,
void *data UNUSED)
{
- struct fsck_options options = FSCK_OPTIONS_DEFAULT;
+ struct fsck_options options;
struct object *obj = lookup_object(the_repository, oid);
if (!obj || !(obj->flags & HAS_OBJ))
@@ -243,6 +243,7 @@ static int mark_unreachable_referents(const struct object_id *oid,
object_as_type(obj, type, 0);
}
+ fsck_options_init(&options, FSCK_OPTIONS_DEFAULT);
options.walk = mark_used;
fsck_walk(obj, NULL, &options);
if (obj->type == OBJ_TREE)
@@ -1004,7 +1005,10 @@ int cmd_fsck(int argc,
argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
+ fsck_options_init(&fsck_walk_options, FSCK_OPTIONS_DEFAULT);
fsck_walk_options.walk = mark_object;
+
+ fsck_options_init(&fsck_obj_options, FSCK_OPTIONS_DEFAULT);
fsck_obj_options.walk = mark_used;
fsck_obj_options.error_func = fsck_objects_error_func;
if (check_strict)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index d1e47279a8..c8d28bcf8e 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -136,7 +136,7 @@ static int nr_threads;
static int from_stdin;
static int strict;
static int do_fsck_object;
-static struct fsck_options fsck_options = FSCK_OPTIONS_MISSING_GITMODULES;
+static struct fsck_options fsck_options;
static int verbose;
static const char *progress_title;
static int show_resolving_progress;
@@ -1908,6 +1908,8 @@ int cmd_index_pack(int argc,
show_usage_if_asked(argc, argv, index_pack_usage);
disable_replace_refs();
+
+ fsck_options_init(&fsck_options, FSCK_OPTIONS_MISSING_GITMODULES);
fsck_options.walk = mark_link;
reset_pack_idx_option(&opts);
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 7cf6e1230a..9f37f9dede 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -16,7 +16,7 @@ static char const * const builtin_mktag_usage[] = {
};
static int option_strict = 1;
-static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
+static struct fsck_options fsck_options;
static int mktag_fsck_error_func(struct fsck_options *o UNUSED,
void *fsck_report UNUSED,
@@ -94,6 +94,7 @@ int cmd_mktag(int argc,
if (strbuf_read(&buf, 0, 0) < 0)
die_errno(_("could not read from stdin"));
+ fsck_options_init(&fsck_options, FSCK_OPTIONS_STRICT);
fsck_options.error_func = mktag_fsck_error_func;
fsck_set_msg_type_from_ids(&fsck_options, FSCK_MSG_EXTRA_HEADER_ENTRY,
FSCK_WARN);
diff --git a/builtin/refs.c b/builtin/refs.c
index 3064f888b2..1719ada549 100644
--- a/builtin/refs.c
+++ b/builtin/refs.c
@@ -80,7 +80,7 @@ out:
static int cmd_refs_verify(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
- struct fsck_options fsck_refs_options = FSCK_REFS_OPTIONS_DEFAULT;
+ struct fsck_options fsck_refs_options;
struct worktree **worktrees;
const char * const verify_usage[] = {
REFS_VERIFY_USAGE,
@@ -93,6 +93,8 @@ static int cmd_refs_verify(int argc, const char **argv, const char *prefix,
};
int ret = 0;
+ fsck_options_init(&fsck_refs_options, FSCK_OPTIONS_REFS);
+
argc = parse_options(argc, argv, prefix, options, verify_usage, 0);
if (argc)
usage(_("'git refs verify' takes no arguments"));
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 6fc64e9e4b..9e4bb9d25c 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -29,7 +29,7 @@ static unsigned int offset, len;
static off_t consumed_bytes;
static off_t max_input_size;
static struct git_hash_ctx ctx;
-static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;
+static struct fsck_options fsck_options;
static struct progress *progress;
/*
@@ -627,6 +627,8 @@ int cmd_unpack_objects(int argc,
show_usage_if_asked(argc, argv, unpack_usage);
+ fsck_options_init(&fsck_options, FSCK_OPTIONS_STRICT);
+
for (i = 1 ; i < argc; i++) {
const char *arg = argv[i];