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>
Nguyễn Thái Ngọc Duy committed
Mar 24, 2019 at 15:20 UTC
c380a48c8b40331dd6466d6b565af6d44c7b11bf
1 file changed
+6
-20
builtin/range-diff.c
+6
-20
@@ -16,42 +16,27 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
16
int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT;
17
struct diff_options diffopt = { NULL };
18
int simple_color = -1;
19
- struct option options[] = {
19
+ struct option range_diff_options[] = {
20
OPT_INTEGER(0, "creation-factor", &creation_factor,
21
N_("Percentage by which creation is weighted")),
22
OPT_BOOL(0, "no-dual-color", &simple_color,
23
N_("use simple diff colors")),
24
OPT_END()
25
};
26
- int i, j, res = 0;
26
+ struct option *options;
27
+ int res = 0;
28
struct strbuf range1 = STRBUF_INIT, range2 = STRBUF_INIT;
29
30
git_config(git_diff_ui_config, NULL);
31
32
repo_diff_setup(the_repository, &diffopt);
33
34
+ options = parse_options_concat(range_diff_options, diffopt.parseopts);
35
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);
37
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;
38
diff_setup_done(&diffopt);
39
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
-
40
/* force color when --dual-color was used */
41
if (!simple_color)
42
diffopt.use_color = 1;
@@ -90,6 +75,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
75
error(_("need two commit ranges"));
76
usage_with_options(builtin_range_diff_usage, options);
77
}
78
+ FREE_AND_NULL(options);
79
80
res = show_range_diff(range1.buf, range2.buf, creation_factor,
81
simple_color < 1, &diffopt);