From: Patrick Steinhardt Date: Fri, 20 Mar 2026 11:47:08 GMT Subject: [PATCH 03/14] fsck: refactor interface to parse fsck options Message-ID: <20260320-b4-pks-fsck-without-the-repository-v1-3-6594f997926b@pks.im> In-Reply-To: <20260320-b4-pks-fsck-without-the-repository-v1-0-6594f997926b@pks.im> The function `git_fsck_config()` is supposed to be used as a callback function for `repo_config()`. It expects the caller to provide a repository as callback payload, which is easy to miss. Furthermore, in the next commit we're about to refactor the function to not rely on global state anymore, which will require callers to pass a different payload. Prepare for this change by refactoring the interface to be fully self-contained. Like this, callers know exactly which parameters are expected. Signed-off-by: Patrick Steinhardt --- builtin/fsck.c | 2 +- builtin/mktag.c | 3 ++- builtin/refs.c | 2 +- fsck.c | 11 +++++++++-- fsck.h | 9 ++++----- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/builtin/fsck.c b/builtin/fsck.c index 8f994010da..fd689a1e14 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -1023,7 +1023,7 @@ int cmd_fsck(int argc, if (name_objects) fsck_enable_object_names(&fsck_walk_options); - repo_config(the_repository, git_fsck_config, &fsck_obj_options); + fsck_options_parse_config(&fsck_obj_options, the_repository); prepare_repo_settings(the_repository); if (check_references) diff --git a/builtin/mktag.c b/builtin/mktag.c index 7cf6e1230a..2cf843c195 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -98,7 +98,8 @@ int cmd_mktag(int argc, fsck_set_msg_type_from_ids(&fsck_options, FSCK_MSG_EXTRA_HEADER_ENTRY, FSCK_WARN); /* config might set fsck.extraHeaderEntry=* again */ - repo_config(the_repository, git_fsck_config, &fsck_options); + fsck_options_parse_config(&fsck_options, the_repository); + if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options, &tagged_oid, &tagged_type)) die(_("tag on stdin did not pass our strict fsck check")); diff --git a/builtin/refs.c b/builtin/refs.c index 3064f888b2..c0a3b475e9 100644 --- a/builtin/refs.c +++ b/builtin/refs.c @@ -97,7 +97,7 @@ static int cmd_refs_verify(int argc, const char **argv, const char *prefix, if (argc) usage(_("'git refs verify' takes no arguments")); - repo_config(the_repository, git_fsck_config, &fsck_refs_options); + fsck_options_parse_config(&fsck_refs_options, the_repository); prepare_repo_settings(the_repository); worktrees = get_worktrees_without_reading_head(); diff --git a/fsck.c b/fsck.c index 1f7d568acf..a7ebab9581 100644 --- a/fsck.c +++ b/fsck.c @@ -1404,8 +1404,9 @@ void fsck_options_clear(struct fsck_options *options) kh_clear_oid_map(options->object_names); } -int git_fsck_config(const char *var, const char *value, - const struct config_context *ctx, void *cb) +static int fsck_options_parse_config_key(const char *var, const char *value, + const struct config_context *ctx, + void *cb) { struct fsck_options *options = cb; const char *msg_id; @@ -1435,6 +1436,12 @@ int git_fsck_config(const char *var, const char *value, return git_default_config(var, value, ctx, cb); } +void fsck_options_parse_config(struct fsck_options *options, + struct repository *repo) +{ + repo_config(repo, fsck_options_parse_config_key, options); +} + /* * Custom error callbacks that are used in more than one place. */ diff --git a/fsck.h b/fsck.h index bfe9b3ffc9..7d0d876103 100644 --- a/fsck.h +++ b/fsck.h @@ -304,12 +304,11 @@ void fsck_put_object_name(struct fsck_options *options, const char *fsck_describe_object(struct fsck_options *options, const struct object_id *oid); -struct key_value_info; /* - * repo_config() callback for use by fsck-y tools that want to support - * fsck. fsck.skipList etc. + * Parse fsck options from the gitconfig. This covers settings like for example + * fsck. fsck.skipList. */ -int git_fsck_config(const char *var, const char *value, - const struct config_context *ctx, void *cb); +void fsck_options_parse_config(struct fsck_options *options, + struct repository *repo); #endif -- 2.53.0.1055.ga2ffed1127.dirty