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 = 60;
17 struct diff_options diffopt = { NULL };
18 struct option options[] = {
19 OPT_INTEGER(0, "creation-factor", &creation_factor,
20 N_("Percentage by which creation is weighted")),
24 struct strbuf range1 = STRBUF_INIT, range2 = STRBUF_INIT;
26 git_config(git_diff_ui_config, NULL);
29 diffopt.output_format = DIFF_FORMAT_PATCH;
31 argc = parse_options(argc, argv, NULL, options,
32 builtin_range_diff_usage, PARSE_OPT_KEEP_UNKNOWN |
33 PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);
35 for (i = j = 1; i < argc && strcmp("--", argv[i]); ) {
36 int c = diff_opt_parse(&diffopt, argv + i, argc - i, prefix);
39 argv[j++] = argv[i++];
44 argv[j++] = argv[i++];
46 diff_setup_done(&diffopt);
48 /* Make sure that there are no unparsed options */
49 argc = parse_options(argc, argv, NULL,
50 options + ARRAY_SIZE(options) - 1, /* OPT_END */
51 builtin_range_diff_usage, 0);
54 if (!strstr(argv[0], ".."))
55 die(_("no .. in range: '%s'"), argv[0]);
56 strbuf_addstr(&range1, argv[0]);
58 if (!strstr(argv[1], ".."))
59 die(_("no .. in range: '%s'"), argv[1]);
60 strbuf_addstr(&range2, argv[1]);
61 } else if (argc == 3) {
62 strbuf_addf(&range1, "%s..%s", argv[0], argv[1]);
63 strbuf_addf(&range2, "%s..%s", argv[0], argv[2]);
64 } else if (argc == 1) {
65 const char *b = strstr(argv[0], "..."), *a = argv[0];
69 error(_("single arg format must be symmetric range"));
70 usage_with_options(builtin_range_diff_usage, options);
81 strbuf_addf(&range1, "%s..%.*s", b, a_len, a);
82 strbuf_addf(&range2, "%.*s..%s", a_len, a, b);
84 error(_("need two commit ranges"));
85 usage_with_options(builtin_range_diff_usage, options);
88 res = show_range_diff(range1.buf, range2.buf, creation_factor,
91 strbuf_release(&range1);
92 strbuf_release(&range2);