]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/range-diff.c
Fix typos in translatable strings for v2.21.0
[thirdparty/git.git] / builtin / range-diff.c
CommitLineData
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
7static const char * const builtin_range_diff_usage[] = {
8N_("git range-diff [<options>] <old-base>..<old-tip> <new-base>..<new-tip>"),
9N_("git range-diff [<options>] <old-tip>...<new-tip>"),
10N_("git range-diff [<options>] <base> <old-tip> <new-tip>"),
11NULL
12};
13
14int 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 };
27526793 18 int simple_color = -1;
348ae56c
JS
19 struct option options[] = {
20 OPT_INTEGER(0, "creation-factor", &creation_factor,
21 N_("Percentage by which creation is weighted")),
27526793 22 OPT_BOOL(0, "no-dual-color", &simple_color,
72f47be2 23 N_("use simple diff colors")),
348ae56c
JS
24 OPT_END()
25 };
c8c5e43a 26 int i, j, res = 0;
d9c66f0b 27 struct strbuf range1 = STRBUF_INIT, range2 = STRBUF_INIT;
348ae56c 28
c8c5e43a
JS
29 git_config(git_diff_ui_config, NULL);
30
e6757652 31 repo_diff_setup(the_repository, &diffopt);
c8c5e43a 32
348ae56c 33 argc = parse_options(argc, argv, NULL, options,
c8c5e43a
JS
34 builtin_range_diff_usage, PARSE_OPT_KEEP_UNKNOWN |
35 PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);
36
37 for (i = j = 1; i < argc && strcmp("--", argv[i]); ) {
38 int c = diff_opt_parse(&diffopt, argv + i, argc - i, prefix);
39
40 if (!c)
41 argv[j++] = argv[i++];
42 else
43 i += c;
44 }
45 while (i < argc)
46 argv[j++] = argv[i++];
47 argc = j;
48 diff_setup_done(&diffopt);
49
50 /* Make sure that there are no unparsed options */
51 argc = parse_options(argc, argv, NULL,
52 options + ARRAY_SIZE(options) - 1, /* OPT_END */
348ae56c
JS
53 builtin_range_diff_usage, 0);
54
73a834e9
ES
55 /* force color when --dual-color was used */
56 if (!simple_color)
57 diffopt.use_color = 1;
31cf61a0 58
d9c66f0b
JS
59 if (argc == 2) {
60 if (!strstr(argv[0], ".."))
61 die(_("no .. in range: '%s'"), argv[0]);
62 strbuf_addstr(&range1, argv[0]);
63
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];
72 int a_len;
73
74 if (!b) {
75 error(_("single arg format must be symmetric range"));
76 usage_with_options(builtin_range_diff_usage, options);
77 }
78
79 a_len = (int)(b - a);
80 if (!a_len) {
81 a = "HEAD";
82 a_len = strlen(a);
83 }
84 b += 3;
85 if (!*b)
86 b = "HEAD";
87 strbuf_addf(&range1, "%s..%.*s", b, a_len, a);
88 strbuf_addf(&range2, "%.*s..%s", a_len, a, b);
89 } else {
90 error(_("need two commit ranges"));
91 usage_with_options(builtin_range_diff_usage, options);
92 }
93
c8c5e43a 94 res = show_range_diff(range1.buf, range2.buf, creation_factor,
73a834e9 95 simple_color < 1, &diffopt);
d9c66f0b
JS
96
97 strbuf_release(&range1);
98 strbuf_release(&range2);
99
100 return res;
348ae56c 101}