3 #include "parse-options.h"
4 #include "range-diff.h"
7 static const char * const builtin_range_diff_usage
[] = {
8 N_("git range-diff [<options>] <old-base>..<old-tip> <new-base>..<new-tip>"),
9 N_("git range-diff [<options>] <old-tip>...<new-tip>"),
10 N_("git range-diff [<options>] <base> <old-tip> <new-tip>"),
14 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 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")),
26 struct option
*options
;
28 struct strbuf range1
= STRBUF_INIT
, range2
= STRBUF_INIT
;
30 git_config(git_diff_ui_config
, NULL
);
32 repo_diff_setup(the_repository
, &diffopt
);
34 options
= parse_options_concat(range_diff_options
, diffopt
.parseopts
);
35 argc
= parse_options(argc
, argv
, prefix
, options
,
36 builtin_range_diff_usage
, 0);
38 diff_setup_done(&diffopt
);
40 /* force color when --dual-color was used */
42 diffopt
.use_color
= 1;
45 if (!strstr(argv
[0], ".."))
46 die(_("no .. in range: '%s'"), argv
[0]);
47 strbuf_addstr(&range1
, argv
[0]);
49 if (!strstr(argv
[1], ".."))
50 die(_("no .. in range: '%s'"), argv
[1]);
51 strbuf_addstr(&range2
, argv
[1]);
52 } else if (argc
== 3) {
53 strbuf_addf(&range1
, "%s..%s", argv
[0], argv
[1]);
54 strbuf_addf(&range2
, "%s..%s", argv
[0], argv
[2]);
55 } else if (argc
== 1) {
56 const char *b
= strstr(argv
[0], "..."), *a
= argv
[0];
60 error(_("single arg format must be symmetric range"));
61 usage_with_options(builtin_range_diff_usage
, options
);
72 strbuf_addf(&range1
, "%s..%.*s", b
, a_len
, a
);
73 strbuf_addf(&range2
, "%.*s..%s", a_len
, a
, b
);
75 error(_("need two commit ranges"));
76 usage_with_options(builtin_range_diff_usage
, options
);
78 FREE_AND_NULL(options
);
80 res
= show_range_diff(range1
.buf
, range2
.buf
, creation_factor
,
81 simple_color
< 1, &diffopt
);
83 strbuf_release(&range1
);
84 strbuf_release(&range2
);