Skip to content

Commit c380a48

Browse files
pcloudsgitster
authored andcommitted
range-diff: use parse_options() instead of diff_opt_parse()
Diff's internal option parsing is now done with 'struct option', which makes it possible to combine all diff options to range-diff and parse everything all at once. Parsing code becomes simpler, and we get a looong 'git range-diff -h' Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent bb98729 commit c380a48

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

builtin/range-diff.c

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,27 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
1616
int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT;
1717
struct diff_options diffopt = { NULL };
1818
int simple_color = -1;
19-
struct option options[] = {
19+
struct option range_diff_options[] = {
2020
OPT_INTEGER(0, "creation-factor", &creation_factor,
2121
N_("Percentage by which creation is weighted")),
2222
OPT_BOOL(0, "no-dual-color", &simple_color,
2323
N_("use simple diff colors")),
2424
OPT_END()
2525
};
26-
int i, j, res = 0;
26+
struct option *options;
27+
int res = 0;
2728
struct strbuf range1 = STRBUF_INIT, range2 = STRBUF_INIT;
2829

2930
git_config(git_diff_ui_config, NULL);
3031

3132
repo_diff_setup(the_repository, &diffopt);
3233

34+
options = parse_options_concat(range_diff_options, diffopt.parseopts);
3335
argc = parse_options(argc, argv, NULL, options,
34-
builtin_range_diff_usage, PARSE_OPT_KEEP_UNKNOWN |
35-
PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);
36-
37-
for (i = j = 1; i < argc && strcmp("--", argv[i]); ) {
38-
int c = diff_opt_parse(&diffopt, argv + i, argc - i, prefix);
36+
builtin_range_diff_usage, 0);
3937

40-
if (!c)
41-
argv[j++] = argv[i++];
42-
else
43-
i += c;
44-
}
45-
while (i < argc)
46-
argv[j++] = argv[i++];
47-
argc = j;
4838
diff_setup_done(&diffopt);
4939

50-
/* Make sure that there are no unparsed options */
51-
argc = parse_options(argc, argv, NULL,
52-
options + ARRAY_SIZE(options) - 1, /* OPT_END */
53-
builtin_range_diff_usage, 0);
54-
5540
/* force color when --dual-color was used */
5641
if (!simple_color)
5742
diffopt.use_color = 1;
@@ -90,6 +75,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
9075
error(_("need two commit ranges"));
9176
usage_with_options(builtin_range_diff_usage, options);
9277
}
78+
FREE_AND_NULL(options);
9379

9480
res = show_range_diff(range1.buf, range2.buf, creation_factor,
9581
simple_color < 1, &diffopt);

0 commit comments

Comments
 (0)