summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-04-17 12:49:37 +0200
committerJunio C Hamano <gitster@pobox.com>2025-04-17 08:15:15 -0700
commitd012ceb5f3351af0589a0c82b07059bce8c7b24b (patch)
tree9ee63a9115fdc7ecdc08a693db067b0d5952f204 /diff.c
parent8f282bdff0b49744b45d619075b59a5e8b596613 (diff)
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>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/diff.c b/diff.c
index 08f5e00a2c..f2fcc7f3c2 100644
--- a/diff.c
+++ b/diff.c
@@ -5892,10 +5892,15 @@ struct option *add_diff_options(const struct option *opts,
OPT_CALLBACK_F(0, "diff-filter", options, N_("[(A|C|D|M|R|T|U|X|B)...[*]]"),
N_("select files by diff type"),
PARSE_OPT_NONEG, diff_opt_diff_filter),
- { OPTION_CALLBACK, 0, "output", options, N_("<file>"),
- N_("output to a specific file"),
- PARSE_OPT_NONEG, NULL, 0, diff_opt_output },
-
+ {
+ .type = OPTION_CALLBACK,
+ .long_name = "output",
+ .value = options,
+ .argh = N_("<file>"),
+ .help = N_("output to a specific file"),
+ .flags = PARSE_OPT_NONEG,
+ .ll_callback = diff_opt_output,
+ },
OPT_END()
};