]> git.ipfire.org Git - thirdparty/git.git/commit
global: use designated initializers for options
authorPatrick Steinhardt <ps@pks.im>
Thu, 17 Apr 2025 10:49:37 +0000 (12:49 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 17 Apr 2025 15:15:15 +0000 (08:15 -0700)
commitd012ceb5f3351af0589a0c82b07059bce8c7b24b
tree9ee63a9115fdc7ecdc08a693db067b0d5952f204
parent8f282bdff0b49744b45d619075b59a5e8b596613
global: use designated initializers for options

While we expose macros for most of our different option types understood
by the "parse-options" subsystem, not every combination of fields that
has one as that would otherwise quickly lead to an explosion of macros.
Instead, we just initialize structures manually for those variants of
fields that don't have a macro.

Callsites that open-code these structure initialization don't use
designated initializers though and instead just provide values for each
of the fields that they want to initialize. This has three significant
downsides:

  - Callsites need to specify all values up to the last field that they
    care about. This often includes fields that should simply be left at
    their default zero-initialized state, which adds distraction.

  - Any reader not deeply familiar with the layout of the structure
    has a hard time figuring out what the respective initializers mean.

  - Reordering or introducing new fields in the middle of the structure
    is impossible without adapting all callsites.

Convert all sites to instead use designated initializers, which we have
started using in our codebase quite a while ago. This allows us to skip
any default-initialized fields, gives the reader context by specifying
the field names and allows us to reorder or introduce new fields where
we want to.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
24 files changed:
archive.c
builtin/am.c
builtin/clone.c
builtin/commit-tree.c
builtin/commit.c
builtin/config.c
builtin/describe.c
builtin/fetch.c
builtin/fmt-merge-msg.c
builtin/gc.c
builtin/grep.c
builtin/init-db.c
builtin/ls-remote.c
builtin/merge.c
builtin/read-tree.c
builtin/rebase.c
builtin/revert.c
builtin/show-branch.c
builtin/tag.c
builtin/update-index.c
builtin/write-tree.c
diff.c
ref-filter.h
t/helper/test-parse-options.c