diff: factor out add_diff_options()

Add a function for appending the parseopts member of struct diff_options to a struct option array. Use it in two sites instead of accessing the parseopts member directly. Decoupling callers from diff internals like that allows us to change the latter. 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:49 UTC c5630c4868c74aab2fc4e8a4ef4bfc9c51534e0e
4 files changed +9 -3
builtin/range-diff.c
+1 -1
@@ -47,7 +47,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
47
48 repo_diff_setup(the_repository, &diffopt);
49
50 - options = parse_options_concat(range_diff_options, diffopt.parseopts);
50 + options = add_diff_options(range_diff_options, &diffopt);
51 argc = parse_options(argc, argv, prefix, options,
52 builtin_range_diff_usage, PARSE_OPT_KEEP_DASHDASH);
53
diff-no-index.c
+1 -2
@@ -255,8 +255,7 @@ int diff_no_index(struct rev_info *revs,
255 };
256 struct option *options;
257
258 - options = parse_options_concat(no_index_options,
259 - revs->diffopt.parseopts);
258 + options = add_diff_options(no_index_options, &revs->diffopt);
259 argc = parse_options(argc, argv, revs->prefix, options,
260 diff_no_index_usage, 0);
261 if (argc != 2) {
diff.c
+6
@@ -5397,6 +5397,12 @@ static int diff_opt_rotate_to(const struct option *opt, const char *arg, int uns
5397 return 0;
5398 }
5399
5400 +struct option *add_diff_options(const struct option *opts,
5401 + struct diff_options *options)
5402 +{
5403 + return parse_options_concat(opts, options->parseopts);
5404 +}
5405 +
5406 static void prep_parse_options(struct diff_options *options)
5407 {
5408 struct option parseopts[] = {
diff.h
+1
@@ -539,6 +539,7 @@ int git_diff_ui_config(const char *var, const char *value, void *cb);
539 #define diff_setup(diffopts) repo_diff_setup(the_repository, diffopts)
540 #endif
541 void repo_diff_setup(struct repository *, struct diff_options *);
542 +struct option *add_diff_options(const struct option *, struct diff_options *);
543 int diff_opt_parse(struct diff_options *, const char **, int, const char *);
544 void diff_setup_done(struct diff_options *);
545 int git_config_rename(const char *var, const char *value);