Commit

e25440bad1c9158703daeb22de07d4663872b71d

builtin/fsck: de-globalize option handling

In subsequent commits we're about to rework some of the option handling
in git-fsck(1) a bit. It is currently a bit of a mess though due to lots
of global state that makes it hard to see which flags are used where
exactly.

Refactor the code by moving the fsck options into `cmd_fsck()`. This
allows us to convert some of the options into function-local variables.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt <ps@pks.im> · 2026-09-11 13:27 UTC · committed by Junio C Hamano

Browse files
1 file changed, +22 −23
modified builtin/fsck.c
@@ -37,10 +37,8 @@ static int show_root;
37 37 static int show_tags;
38 38 static int show_unreachable;
39 39 static int include_reflogs = 1;
40 - static int check_full = 1;
41 40 static int connectivity_only;
42 41 static int check_strict;
43 - static int keep_cache_objects;
44 42 static struct fsck_options fsck_walk_options;
45 43 static struct fsck_options fsck_obj_options;
46 44 static int errors_found;
@@ -48,8 +46,6 @@ static int write_lost_and_found;
48 46 static int verbose;
49 47 static int show_progress = -1;
50 48 static int show_dangling = 1;
51 - static int name_objects;
52 - static int check_references = 1;
53 49 static timestamp_t now;
54 50 #define ERROR_OBJECT 01
55 51 #define ERROR_REACHABLE 02
@@ -964,30 +960,33 @@ static char const * const fsck_usage[] = {
964 960 NULL
965 961 };
966 962
967 - static struct option fsck_opts[] = {
968 - OPT__VERBOSE(&verbose, N_("be verbose")),
969 - OPT_BOOL(0, "unreachable", &show_unreachable, N_("show unreachable objects")),
970 - OPT_BOOL(0, "dangling", &show_dangling, N_("show dangling objects")),
971 - OPT_BOOL(0, "tags", &show_tags, N_("report tags")),
972 - OPT_BOOL(0, "root", &show_root, N_("report root nodes")),
973 - OPT_BOOL(0, "cache", &keep_cache_objects, N_("make index objects head nodes")),
974 - OPT_BOOL(0, "reflogs", &include_reflogs, N_("make reflogs head nodes (default)")),
975 - OPT_BOOL(0, "full", &check_full, N_("also consider packs and alternate objects")),
976 - OPT_BOOL(0, "connectivity-only", &connectivity_only, N_("check only connectivity")),
977 - OPT_BOOL(0, "strict", &check_strict, N_("enable more strict checking")),
978 - OPT_BOOL(0, "lost-found", &write_lost_and_found,
979 - N_("write dangling objects in .git/lost-found")),
980 - OPT_BOOL(0, "progress", &show_progress, N_("show progress")),
981 - OPT_BOOL(0, "name-objects", &name_objects, N_("show verbose names for reachable objects")),
982 - OPT_BOOL(0, "references", &check_references, N_("check reference database consistency")),
983 - OPT_END(),
984 - };
985 -
986 963 int cmd_fsck(int argc,
987 964 const char **argv,
988 965 const char *prefix,
989 966 struct repository *repo)
990 967 {
968 + int check_full = 1;
969 + int keep_cache_objects = 0;
970 + int name_objects = 0;
971 + int check_references = 1;
972 + struct option fsck_opts[] = {
973 + OPT__VERBOSE(&verbose, N_("be verbose")),
974 + OPT_BOOL(0, "unreachable", &show_unreachable, N_("show unreachable objects")),
975 + OPT_BOOL(0, "dangling", &show_dangling, N_("show dangling objects")),
976 + OPT_BOOL(0, "tags", &show_tags, N_("report tags")),
977 + OPT_BOOL(0, "root", &show_root, N_("report root nodes")),
978 + OPT_BOOL(0, "cache", &keep_cache_objects, N_("make index objects head nodes")),
979 + OPT_BOOL(0, "reflogs", &include_reflogs, N_("make reflogs head nodes (default)")),
980 + OPT_BOOL(0, "full", &check_full, N_("also consider packs and alternate objects")),
981 + OPT_BOOL(0, "connectivity-only", &connectivity_only, N_("check only connectivity")),
982 + OPT_BOOL(0, "strict", &check_strict, N_("enable more strict checking")),
983 + OPT_BOOL(0, "lost-found", &write_lost_and_found,
984 + N_("write dangling objects in .git/lost-found")),
985 + OPT_BOOL(0, "progress", &show_progress, N_("show progress")),
986 + OPT_BOOL(0, "name-objects", &name_objects, N_("show verbose names for reachable objects")),
987 + OPT_BOOL(0, "references", &check_references, N_("check reference database consistency")),
988 + OPT_END(),
989 + };
991 990 struct odb_source *source;
992 991 struct snapshot snap = {
993 992 .nr = 0,