git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 02/12] fsck: initialize fsck options via a function

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 23, 2026, 15:48 UTC
Message-ID
<xmqqqzpa5yyo.fsf@gitster.g>
In-Reply-To
<20260323-b4-pks-fsck-without-the-repository-v2-2-e8dc79bca651@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 44 quoted lines
> +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.

Show 74 quoted lines
>  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))
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 5 of 17 in “fsck: drop use of `the_repository`”
  1. 00/12 fsck: drop use of `the_repository`Patrick Steinhardt, Mar 23, 2026
  2. 01/12 fetch-pack: move fsck options into function scopePatrick Steinhardt, Mar 23, 2026
  3. Junio C HamanoMar 23, 2026
  4. 02/12 fsck: initialize fsck options via a functionPatrick Steinhardt, Mar 23, 2026
  5. Junio C HamanoMar 23, 2026
  6. 03/12 fsck: store repository in fsck optionsPatrick Steinhardt, Mar 23, 2026
  7. 04/12 fsck: drop USE_THE_REPOSITORYPatrick Steinhardt, Mar 23, 2026
  8. 05/12 builtin/fsck: fix trivial dependence on `the_repository`Patrick Steinhardt, Mar 23, 2026
  9. 06/12 builtin/fsck: stop using `the_repository` when snapshotting refsPatrick Steinhardt, Mar 23, 2026
  10. 07/12 builtin/fsck: stop using `the_repository` when checking refsPatrick Steinhardt, Mar 23, 2026
  11. 08/12 builtin/fsck: stop using `the_repository` when checking reflogsPatrick Steinhardt, Mar 23, 2026
  12. 09/12 builtin/fsck: stop using `the_repository` with loose objectsPatrick Steinhardt, Mar 23, 2026
  13. 10/12 builtin/fsck: stop using `the_repository` when checking packed objectsPatrick Steinhardt, Mar 23, 2026
  14. 11/12 builtin/fsck: stop using `the_repository` when marking objectsPatrick Steinhardt, Mar 23, 2026
  15. 12/12 builtin/fsck: stop using `the_repository` in error reportingPatrick Steinhardt, Mar 23, 2026
  16. Junio C HamanoMar 31, 2026
  17. Patrick SteinhardtMar 31, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.