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 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")),
27 struct strbuf range1 = STRBUF_INIT, range2 = STRBUF_INIT;
29 git_config(git_diff_ui_config, NULL);
31 repo_diff_setup(the_repository, &diffopt);
33 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);
37 for (i = j = 1; i < argc && strcmp("--", argv[i]); ) {
38 int c = diff_opt_parse(&diffopt, argv + i, argc - i, prefix);
41 argv[j++] = argv[i++];
46 argv[j++] = argv[i++];
48 diff_setup_done(&diffopt);
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);
55 /* force color when --dual-color was used */
57 diffopt.use_color = 1;
60 if (!strstr(argv[0], ".."))
61 die(_("no .. in range: '%s'"), argv[0]);
62 strbuf_addstr(&range1, argv[0]);
64 if (!strstr(argv[1], ".."))
65 die(_("no .. in range: '%s'"), argv[1]);
66 strbuf_addstr(&range2, argv[1]);
67 } else if (argc == 3) {
68 strbuf_addf(&range1, "%s..%s", argv[0], argv[1]);
69 strbuf_addf(&range2, "%s..%s", argv[0], argv[2]);
70 } else if (argc == 1) {
71 const char *b = strstr(argv[0], "..."), *a = argv[0];
75 error(_("single arg format must be symmetric range"));
76 usage_with_options(builtin_range_diff_usage, options);
87 strbuf_addf(&range1, "%s..%.*s", b, a_len, a);
88 strbuf_addf(&range2, "%.*s..%s", a_len, a, b);
90 error(_("need two commit ranges"));
91 usage_with_options(builtin_range_diff_usage, options);
94 res = show_range_diff(range1.buf, range2.buf, creation_factor,
95 simple_color < 1, &diffopt);
97 strbuf_release(&range1);
98 strbuf_release(&range2);