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 static struct strbuf *output_prefix_cb(struct diff_options *opt, void *data)
19 int cmd_range_diff(int argc, const char **argv, const char *prefix)
21 int creation_factor = 60;
22 struct diff_options diffopt = { NULL };
23 int simple_color = -1;
24 struct option options[] = {
25 OPT_INTEGER(0, "creation-factor", &creation_factor,
26 N_("Percentage by which creation is weighted")),
27 OPT_BOOL(0, "no-dual-color", &simple_color,
28 N_("color both diff and diff-between-diffs")),
32 struct strbuf four_spaces = STRBUF_INIT;
33 struct strbuf range1 = STRBUF_INIT, range2 = STRBUF_INIT;
35 git_config(git_diff_ui_config, NULL);
38 diffopt.output_format = DIFF_FORMAT_PATCH;
39 diffopt.flags.suppress_diff_headers = 1;
40 diffopt.output_prefix = output_prefix_cb;
41 strbuf_addstr(&four_spaces, " ");
42 diffopt.output_prefix_data = &four_spaces;
44 argc = parse_options(argc, argv, NULL, options,
45 builtin_range_diff_usage, PARSE_OPT_KEEP_UNKNOWN |
46 PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);
48 for (i = j = 1; i < argc && strcmp("--", argv[i]); ) {
49 int c = diff_opt_parse(&diffopt, argv + i, argc - i, prefix);
52 argv[j++] = argv[i++];
57 argv[j++] = argv[i++];
59 diff_setup_done(&diffopt);
61 /* Make sure that there are no unparsed options */
62 argc = parse_options(argc, argv, NULL,
63 options + ARRAY_SIZE(options) - 1, /* OPT_END */
64 builtin_range_diff_usage, 0);
66 if (simple_color < 1) {
68 /* force color when --dual-color was used */
69 diffopt.use_color = 1;
70 diffopt.flags.dual_color_diffed_diffs = 1;
74 if (!strstr(argv[0], ".."))
75 die(_("no .. in range: '%s'"), argv[0]);
76 strbuf_addstr(&range1, argv[0]);
78 if (!strstr(argv[1], ".."))
79 die(_("no .. in range: '%s'"), argv[1]);
80 strbuf_addstr(&range2, argv[1]);
81 } else if (argc == 3) {
82 strbuf_addf(&range1, "%s..%s", argv[0], argv[1]);
83 strbuf_addf(&range2, "%s..%s", argv[0], argv[2]);
84 } else if (argc == 1) {
85 const char *b = strstr(argv[0], "..."), *a = argv[0];
89 error(_("single arg format must be symmetric range"));
90 usage_with_options(builtin_range_diff_usage, options);
101 strbuf_addf(&range1, "%s..%.*s", b, a_len, a);
102 strbuf_addf(&range2, "%.*s..%s", a_len, a, b);
104 error(_("need two commit ranges"));
105 usage_with_options(builtin_range_diff_usage, options);
108 res = show_range_diff(range1.buf, range2.buf, creation_factor,
111 strbuf_release(&range1);
112 strbuf_release(&range2);
113 strbuf_release(&four_spaces);