All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2 02/12] fsck: initialize fsck options via a function
Date: Mon, 23 Mar 2026 08:48:15 -0700	[thread overview]
Message-ID: <xmqqqzpa5yyo.fsf@gitster.g> (raw)
In-Reply-To: <20260323-b4-pks-fsck-without-the-repository-v2-2-e8dc79bca651@pks.im> (Patrick Steinhardt's message of "Mon, 23 Mar 2026 16:02:53 +0100")

Patrick Steinhardt <ps@pks.im> writes:

> +void fsck_options_init(struct fsck_options *options,
> +		       enum fsck_options_type type)
> +{
> +	static const struct fsck_options defaults[] = {
> +		[FSCK_OPTIONS_DEFAULT] = {
> +			.skip_oids = OIDSET_INIT,
> +			.gitmodules_found = OIDSET_INIT,
> +			.gitmodules_done = OIDSET_INIT,
> +			.gitattributes_found = OIDSET_INIT,
> +			.gitattributes_done = OIDSET_INIT,
> +			.error_func = fsck_objects_error_function
> +		},
> +		[FSCK_OPTIONS_STRICT] = {
> +			.strict = 1,
> +			.gitmodules_found = OIDSET_INIT,
> +			.gitmodules_done = OIDSET_INIT,
> +			.gitattributes_found = OIDSET_INIT,
> +			.gitattributes_done = OIDSET_INIT,
> +			.error_func = fsck_objects_error_function,
> +		},
> +		[FSCK_OPTIONS_MISSING_GITMODULES] = {
> +			.strict = 1,
> +			.gitmodules_found = OIDSET_INIT,
> +			.gitmodules_done = OIDSET_INIT,
> +			.gitattributes_found = OIDSET_INIT,
> +			.gitattributes_done = OIDSET_INIT,
> +			.error_func = fsck_objects_error_cb_print_missing_gitmodules,
> +		},
> +		[FSCK_OPTIONS_REFS] = {
> +			.error_func = fsck_refs_error_function,
> +		},
> +	};
> +
> +	switch (type) {
> +	case FSCK_OPTIONS_DEFAULT:
> +	case FSCK_OPTIONS_STRICT:
> +	case FSCK_OPTIONS_MISSING_GITMODULES:
> +	case FSCK_OPTIONS_REFS:
> +		memcpy(options, &defaults[type], sizeof(*options));
> +		break;
> +	default:
> +		BUG("unknown fsck options type %d", type);
> +	}
> +}

Wow, nice reorganization that migrates the earlier definitions from
the header file.

By reusing these FSCK_OPTIONS_* names as an enum elements, we will
let the compiler catch if any other branch adds new uses of these
names with their original meaning, which is a nice touch, too.

>  void fsck_options_clear(struct fsck_options *options)
>  {
>  	free(options->msg_type);
> diff --git a/fsck.h b/fsck.h
> index 65ecbb7fe1..9c973b53b2 100644
> --- a/fsck.h
> +++ b/fsck.h
> @@ -180,34 +180,6 @@ struct fsck_options {
>  	kh_oid_map_t *object_names;
>  };
>  
> -#define FSCK_OPTIONS_DEFAULT { \
> -	.skip_oids = OIDSET_INIT, \
> -	.gitmodules_found = OIDSET_INIT, \
> -	.gitmodules_done = OIDSET_INIT, \
> -	.gitattributes_found = OIDSET_INIT, \
> -	.gitattributes_done = OIDSET_INIT, \
> -	.error_func = fsck_objects_error_function \
> -}
> -#define FSCK_OPTIONS_STRICT { \
> -	.strict = 1, \
> -	.gitmodules_found = OIDSET_INIT, \
> -	.gitmodules_done = OIDSET_INIT, \
> -	.gitattributes_found = OIDSET_INIT, \
> -	.gitattributes_done = OIDSET_INIT, \
> -	.error_func = fsck_objects_error_function, \
> -}
> -#define FSCK_OPTIONS_MISSING_GITMODULES { \
> -	.strict = 1, \
> -	.gitmodules_found = OIDSET_INIT, \
> -	.gitmodules_done = OIDSET_INIT, \
> -	.gitattributes_found = OIDSET_INIT, \
> -	.gitattributes_done = OIDSET_INIT, \
> -	.error_func = fsck_objects_error_cb_print_missing_gitmodules, \
> -}
> -#define FSCK_REFS_OPTIONS_DEFAULT { \
> -	.error_func = fsck_refs_error_function, \
> -}
> -
>  /* descend in all linked child objects
>   * the return value is:
>   *    -1	error in processing the object
> @@ -255,6 +227,16 @@ int fsck_finish(struct fsck_options *options);
>   */
>  bool fsck_has_queued_checks(struct fsck_options *options);
>  
> +enum fsck_options_type {
> +	FSCK_OPTIONS_DEFAULT,
> +	FSCK_OPTIONS_STRICT,
> +	FSCK_OPTIONS_MISSING_GITMODULES,
> +	FSCK_OPTIONS_REFS,
> +};
> +
> +void fsck_options_init(struct fsck_options *options,
> +		       enum fsck_options_type type);
> +
>  /*
>   * Clear the fsck_options struct, freeing any allocated memory.
>   */
> diff --git a/object-file.c b/object-file.c
> index c62e5496e0..186b2ff764 100644
> --- a/object-file.c
> +++ b/object-file.c
> @@ -1279,8 +1279,9 @@ static int index_mem(struct index_state *istate,
>  		}
>  	}
>  	if (flags & INDEX_FORMAT_CHECK) {
> -		struct fsck_options opts = FSCK_OPTIONS_DEFAULT;
> +		struct fsck_options opts;
>  
> +		fsck_options_init(&opts, FSCK_OPTIONS_DEFAULT);
>  		opts.strict = 1;
>  		opts.error_func = hash_format_check_report;
>  		if (fsck_buffer(null_oid(istate->repo->hash_algo), type, buf, size, &opts))

  reply	other threads:[~2026-03-23 15:48 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-20 11:47 [PATCH 00/14] fsck: drop use of `the_repository` Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 01/14] fsck: drop `the_repository` in `fsck_walk()` Patrick Steinhardt
2026-03-20 23:09   ` Junio C Hamano
2026-03-23 12:22     ` Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 02/14] fsck: drop `the_repository` in `fsck_finish()` Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 03/14] fsck: refactor interface to parse fsck options Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 04/14] fsck: drop `the_repository` in `fsck_set_msg_types()` Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 05/14] fsck: stop relying on global state via `parse_oid_hex()` Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 06/14] builtin/fsck: fix trivial dependence on `the_repository` Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 07/14] builtin/fsck: stop using `the_repository` when snapshotting refs Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 08/14] builtin/fsck: stop using `the_repository` when checking refs Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 09/14] builtin/fsck: stop using `the_repository` when checking reflogs Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 10/14] builtin/fsck: stop using `the_repository` with loose objects Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 11/14] builtin/fsck: stop using `the_repository` when checking packed objects Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 12/14] builtin/fsck: stop using `the_repository` when marking objects Patrick Steinhardt
2026-03-20 11:47 ` [PATCH 13/14] fsck: provide repository in `struct fsck_report_object` Patrick Steinhardt
2026-03-20 23:13   ` Junio C Hamano
2026-03-20 11:47 ` [PATCH 14/14] builtin/fsck: stop using `the_repository` in error reporting Patrick Steinhardt
2026-03-23 15:02 ` [PATCH v2 00/12] fsck: drop use of `the_repository` Patrick Steinhardt
2026-03-23 15:02   ` [PATCH v2 01/12] fetch-pack: move fsck options into function scope Patrick Steinhardt
2026-03-23 15:43     ` Junio C Hamano
2026-03-23 15:02   ` [PATCH v2 02/12] fsck: initialize fsck options via a function Patrick Steinhardt
2026-03-23 15:48     ` Junio C Hamano [this message]
2026-03-23 15:02   ` [PATCH v2 03/12] fsck: store repository in fsck options Patrick Steinhardt
2026-03-23 15:02   ` [PATCH v2 04/12] fsck: drop USE_THE_REPOSITORY Patrick Steinhardt
2026-03-23 15:02   ` [PATCH v2 05/12] builtin/fsck: fix trivial dependence on `the_repository` Patrick Steinhardt
2026-03-23 15:02   ` [PATCH v2 06/12] builtin/fsck: stop using `the_repository` when snapshotting refs Patrick Steinhardt
2026-03-23 15:02   ` [PATCH v2 07/12] builtin/fsck: stop using `the_repository` when checking refs Patrick Steinhardt
2026-03-23 15:02   ` [PATCH v2 08/12] builtin/fsck: stop using `the_repository` when checking reflogs Patrick Steinhardt
2026-03-23 15:03   ` [PATCH v2 09/12] builtin/fsck: stop using `the_repository` with loose objects Patrick Steinhardt
2026-03-23 15:03   ` [PATCH v2 10/12] builtin/fsck: stop using `the_repository` when checking packed objects Patrick Steinhardt
2026-03-23 15:03   ` [PATCH v2 11/12] builtin/fsck: stop using `the_repository` when marking objects Patrick Steinhardt
2026-03-23 15:03   ` [PATCH v2 12/12] builtin/fsck: stop using `the_repository` in error reporting Patrick Steinhardt
2026-03-31 22:05   ` [PATCH v2 00/12] fsck: drop use of `the_repository` Junio C Hamano
2026-03-31 22:50     ` Patrick Steinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqqzpa5yyo.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.