]>
Commit | Line | Data |
---|---|---|
348ae56c JS |
1 | #include "cache.h" |
2 | #include "builtin.h" | |
3 | #include "parse-options.h" | |
d9c66f0b | 4 | #include "range-diff.h" |
c8c5e43a | 5 | #include "config.h" |
348ae56c JS |
6 | |
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>"), | |
11 | NULL | |
12 | }; | |
13 | ||
14 | int cmd_range_diff(int argc, const char **argv, const char *prefix) | |
15 | { | |
25668659 | 16 | int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT; |
c8c5e43a | 17 | struct diff_options diffopt = { NULL }; |
bd361918 | 18 | struct argv_array other_arg = ARGV_ARRAY_INIT; |
27526793 | 19 | int simple_color = -1; |
c380a48c | 20 | struct option range_diff_options[] = { |
348ae56c JS |
21 | OPT_INTEGER(0, "creation-factor", &creation_factor, |
22 | N_("Percentage by which creation is weighted")), | |
27526793 | 23 | OPT_BOOL(0, "no-dual-color", &simple_color, |
72f47be2 | 24 | N_("use simple diff colors")), |
bd361918 DL |
25 | OPT_PASSTHRU_ARGV(0, "notes", &other_arg, |
26 | N_("notes"), N_("passed to 'git log'"), | |
27 | PARSE_OPT_OPTARG), | |
348ae56c JS |
28 | OPT_END() |
29 | }; | |
c380a48c NTND |
30 | struct option *options; |
31 | int res = 0; | |
d9c66f0b | 32 | struct strbuf range1 = STRBUF_INIT, range2 = STRBUF_INIT; |
348ae56c | 33 | |
c8c5e43a JS |
34 | git_config(git_diff_ui_config, NULL); |
35 | ||
e6757652 | 36 | repo_diff_setup(the_repository, &diffopt); |
c8c5e43a | 37 | |
c380a48c | 38 | options = parse_options_concat(range_diff_options, diffopt.parseopts); |
d64db5b3 | 39 | argc = parse_options(argc, argv, prefix, options, |
c380a48c | 40 | builtin_range_diff_usage, 0); |
c8c5e43a | 41 | |
c8c5e43a JS |
42 | diff_setup_done(&diffopt); |
43 | ||
73a834e9 ES |
44 | /* force color when --dual-color was used */ |
45 | if (!simple_color) | |
46 | diffopt.use_color = 1; | |
31cf61a0 | 47 | |
d9c66f0b JS |
48 | if (argc == 2) { |
49 | if (!strstr(argv[0], "..")) | |
50 | die(_("no .. in range: '%s'"), argv[0]); | |
51 | strbuf_addstr(&range1, argv[0]); | |
52 | ||
53 | if (!strstr(argv[1], "..")) | |
54 | die(_("no .. in range: '%s'"), argv[1]); | |
55 | strbuf_addstr(&range2, argv[1]); | |
56 | } else if (argc == 3) { | |
57 | strbuf_addf(&range1, "%s..%s", argv[0], argv[1]); | |
58 | strbuf_addf(&range2, "%s..%s", argv[0], argv[2]); | |
59 | } else if (argc == 1) { | |
60 | const char *b = strstr(argv[0], "..."), *a = argv[0]; | |
61 | int a_len; | |
62 | ||
63 | if (!b) { | |
64 | error(_("single arg format must be symmetric range")); | |
65 | usage_with_options(builtin_range_diff_usage, options); | |
66 | } | |
67 | ||
68 | a_len = (int)(b - a); | |
69 | if (!a_len) { | |
70 | a = "HEAD"; | |
71 | a_len = strlen(a); | |
72 | } | |
73 | b += 3; | |
74 | if (!*b) | |
75 | b = "HEAD"; | |
76 | strbuf_addf(&range1, "%s..%.*s", b, a_len, a); | |
77 | strbuf_addf(&range2, "%.*s..%s", a_len, a, b); | |
78 | } else { | |
79 | error(_("need two commit ranges")); | |
80 | usage_with_options(builtin_range_diff_usage, options); | |
81 | } | |
c380a48c | 82 | FREE_AND_NULL(options); |
d9c66f0b | 83 | |
c8c5e43a | 84 | res = show_range_diff(range1.buf, range2.buf, creation_factor, |
bd361918 | 85 | simple_color < 1, &diffopt, &other_arg); |
d9c66f0b | 86 | |
abcf8573 | 87 | argv_array_clear(&other_arg); |
d9c66f0b JS |
88 | strbuf_release(&range1); |
89 | strbuf_release(&range2); | |
90 | ||
91 | return res; | |
348ae56c | 92 | } |