diff: use add_diff_options() in diff_opt_parse()
Prepare the removal of the parseopts member of struct diff_options by using the API function add_diff_options() instead of accessing it directly to get the command line option definitions. Building the copy by concatenating with an empty option array is slightly awkward, but simpler than a non-concat version of add_diff_options() would be to use in places that need concatenation. Suggested-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Dec 1, 2022 at 23:51 UTC
6c6048fa7f1cf7b9ae79beb0f57fd03dd4021bb4
1 file changed
+5
-1
diff.c
+5
-1
@@ -5680,15 +5680,19 @@ static void prep_parse_options(struct diff_options *options)
5680
int diff_opt_parse(struct diff_options *options,
5681
const char **av, int ac, const char *prefix)
5682
{
5683
+ struct option no_options[] = { OPT_END() };
5684
+ struct option *parseopts = add_diff_options(no_options, options);
5685
+
5686
if (!prefix)
5687
prefix = "";
5688
5686
- ac = parse_options(ac, av, prefix, options->parseopts, NULL,
5689
+ ac = parse_options(ac, av, prefix, parseopts, NULL,
5690
PARSE_OPT_KEEP_DASHDASH |
5691
PARSE_OPT_KEEP_UNKNOWN_OPT |
5692
PARSE_OPT_NO_INTERNAL_HELP |
5693
PARSE_OPT_ONE_SHOT |
5694
PARSE_OPT_STOP_AT_NON_OPTION);
5695
+ free(parseopts);
5696
5697
return ac;
5698
}