From 7ed4ed239e787862cccfc9c713af69a4241a07f8 Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Wed, 5 Nov 2025 13:49:07 +0100 Subject: [PATCH 1/3] Add minimal mode to git-fsck(1) Some repositories might not be verifiable with all the checks in git-fsck(1). To allow the user to do the minimal checks on a repository, add option --minimal to git-fsck(1). This mode works with old repositories like the Linux kernel and Git itself. Signed-off-by: Toon Claes --- b4-submit-tracking --- # This section is used internally by b4 prep for tracking purposes. { "series": { "revision": 1, "change-id": "20251105-toon-critical-fsck-3930230823f1", "prefixes": [] } } -- GitLab From af3c1d704607ada6e2296de690a5d5d32b51a2f1 Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Wed, 5 Nov 2025 17:27:34 +0100 Subject: [PATCH 2/3] fsck: add --minimal mode git-fsck(1) already knows `--strict` mode, which is recommended for new repositories. But git-fsck(1) might fail on very old repositories like the Linux kernel and the Git repository itself. Add option --minimal, which those the bare minimum checks to verify the repository is valid and usable. Signed-off-by: Toon Claes --- Documentation/git-fsck.adoc | 9 ++++++++- builtin/fsck.c | 11 ++++++++++- fsck.c | 2 ++ fsck.h | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Documentation/git-fsck.adoc b/Documentation/git-fsck.adoc index 1751f692d42..f89b9677fe5 100644 --- a/Documentation/git-fsck.adoc +++ b/Documentation/git-fsck.adoc @@ -10,7 +10,7 @@ SYNOPSIS -------- [verse] 'git fsck' [--tags] [--root] [--unreachable] [--cache] [--no-reflogs] - [--[no-]full] [--strict] [--verbose] [--lost-found] + [--[no-]full] [--strict|--minimal] [--verbose] [--lost-found] [--[no-]dangling] [--[no-]progress] [--connectivity-only] [--[no-]name-objects] [--[no-]references] [...] @@ -83,6 +83,13 @@ care about this output and want to speed it up further. objects that trigger this check, but it is recommended to check new projects with this flag. +--minimal:: + Enable minimal checking, this only errors on checks that need to pass + for Git to properly function on the repository. + This can be used on existing repositories, including the Linux kernel + and Git itself. + Cannot be used together with `--strict`. + --verbose:: Be chatty. diff --git a/builtin/fsck.c b/builtin/fsck.c index b1a650c6731..d43eb42813f 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -41,6 +41,7 @@ static int include_reflogs = 1; static int check_full = 1; static int connectivity_only; static int check_strict; +static int check_minimal; 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; @@ -927,7 +928,7 @@ static void fsck_refs(struct repository *r) static char const * const fsck_usage[] = { N_("git fsck [--tags] [--root] [--unreachable] [--cache] [--no-reflogs]\n" - " [--[no-]full] [--strict] [--verbose] [--lost-found]\n" + " [--[no-]full] [--strict|--minimal] [--verbose] [--lost-found]\n" " [--[no-]dangling] [--[no-]progress] [--connectivity-only]\n" " [--[no-]name-objects] [--[no-]references] [...]"), NULL @@ -944,6 +945,7 @@ static struct option fsck_opts[] = { OPT_BOOL(0, "full", &check_full, N_("also consider packs and alternate objects")), OPT_BOOL(0, "connectivity-only", &connectivity_only, N_("check only connectivity")), OPT_BOOL(0, "strict", &check_strict, N_("enable more strict checking")), + OPT_BOOL(0, "minimal", &check_minimal, N_("enable minimal checking")), OPT_BOOL(0, "lost-found", &write_lost_and_found, N_("write dangling objects in .git/lost-found")), OPT_BOOL(0, "progress", &show_progress, N_("show progress")), @@ -972,10 +974,17 @@ int cmd_fsck(int argc, fsck_walk_options.walk = mark_object; fsck_obj_options.walk = mark_used; fsck_obj_options.error_func = fsck_objects_error_func; + + die_for_incompatible_opt2(check_strict, "--strict", + check_minimal, "--minimal"); if (check_strict) fsck_obj_options.strict = 1; + if (check_minimal) + fsck_obj_options.minimal = 1; + if (show_progress == -1) + show_progress = isatty(2); if (verbose) show_progress = 0; diff --git a/fsck.c b/fsck.c index 341e100d24e..299f060fd3f 100644 --- a/fsck.c +++ b/fsck.c @@ -111,6 +111,8 @@ static enum fsck_msg_type fsck_msg_type(enum fsck_msg_id msg_id, if (options->strict && msg_type == FSCK_WARN) msg_type = FSCK_ERROR; + if (options->minimal && msg_type == FSCK_ERROR) + msg_type = FSCK_WARN; return msg_type; } diff --git a/fsck.h b/fsck.h index cb6ef32f4f3..8cdf569fdc4 100644 --- a/fsck.h +++ b/fsck.h @@ -170,6 +170,7 @@ struct fsck_options { fsck_walk_func walk; fsck_error error_func; unsigned strict; + unsigned minimal; unsigned verbose; enum fsck_msg_type *msg_type; struct oidset skip_oids; -- GitLab From a5061b284a3a413309f796274463278a2dadd4d7 Mon Sep 17 00:00:00 2001 From: Toon Claes Date: Wed, 5 Nov 2025 17:30:01 +0100 Subject: [PATCH 3/3] refs: add option --minimal to verify subcommand Similar to git-fsck(1) option --minimal, add this option to the git-refs(1) subcommand to enable the user to do the minimal refs verification. Signed-off-by: Toon Claes --- builtin/fsck.c | 2 ++ builtin/refs.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index d43eb42813f..9c5cc774724 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -918,6 +918,8 @@ static void fsck_refs(struct repository *r) strvec_push(&refs_verify.args, "--verbose"); if (check_strict) strvec_push(&refs_verify.args, "--strict"); + if (check_minimal) + strvec_push(&refs_verify.args, "--minimal"); if (run_command(&refs_verify)) errors_found |= ERROR_REFS; diff --git a/builtin/refs.c b/builtin/refs.c index 3064f888b24..4ae3ea67553 100644 --- a/builtin/refs.c +++ b/builtin/refs.c @@ -14,7 +14,7 @@ N_("git refs migrate --ref-format= [--no-reflog] [--dry-run]") #define REFS_VERIFY_USAGE \ - N_("git refs verify [--strict] [--verbose]") + N_("git refs verify [--strict|--minimal] [--verbose]") #define REFS_EXISTS_USAGE \ N_("git refs exists ") @@ -89,6 +89,7 @@ static int cmd_refs_verify(int argc, const char **argv, const char *prefix, struct option options[] = { OPT_BOOL(0, "verbose", &fsck_refs_options.verbose, N_("be verbose")), OPT_BOOL(0, "strict", &fsck_refs_options.strict, N_("enable strict checking")), + OPT_BOOL(0, "minimal", &fsck_refs_options.minimal, N_("enable minimal checking")), OPT_END(), }; int ret = 0; @@ -97,6 +98,9 @@ static int cmd_refs_verify(int argc, const char **argv, const char *prefix, if (argc) usage(_("'git refs verify' takes no arguments")); + die_for_incompatible_opt2(fsck_refs_options.strict, "--strict", + fsck_refs_options.minimal, "--minimal"); + repo_config(the_repository, git_fsck_config, &fsck_refs_options); prepare_repo_settings(the_repository); -- GitLab