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 struct option options
[] = {
24 OPT_INTEGER(0, "creation-factor", &creation_factor
,
25 N_("Percentage by which creation is weighted")),
29 struct strbuf four_spaces
= STRBUF_INIT
;
30 struct strbuf range1
= STRBUF_INIT
, range2
= STRBUF_INIT
;
32 git_config(git_diff_ui_config
, NULL
);
35 diffopt
.output_format
= DIFF_FORMAT_PATCH
;
36 diffopt
.output_prefix
= output_prefix_cb
;
37 strbuf_addstr(&four_spaces
, " ");
38 diffopt
.output_prefix_data
= &four_spaces
;
40 argc
= parse_options(argc
, argv
, NULL
, options
,
41 builtin_range_diff_usage
, PARSE_OPT_KEEP_UNKNOWN
|
42 PARSE_OPT_KEEP_DASHDASH
| PARSE_OPT_KEEP_ARGV0
);
44 for (i
= j
= 1; i
< argc
&& strcmp("--", argv
[i
]); ) {
45 int c
= diff_opt_parse(&diffopt
, argv
+ i
, argc
- i
, prefix
);
48 argv
[j
++] = argv
[i
++];
53 argv
[j
++] = argv
[i
++];
55 diff_setup_done(&diffopt
);
57 /* Make sure that there are no unparsed options */
58 argc
= parse_options(argc
, argv
, NULL
,
59 options
+ ARRAY_SIZE(options
) - 1, /* OPT_END */
60 builtin_range_diff_usage
, 0);
63 if (!strstr(argv
[0], ".."))
64 die(_("no .. in range: '%s'"), argv
[0]);
65 strbuf_addstr(&range1
, argv
[0]);
67 if (!strstr(argv
[1], ".."))
68 die(_("no .. in range: '%s'"), argv
[1]);
69 strbuf_addstr(&range2
, argv
[1]);
70 } else if (argc
== 3) {
71 strbuf_addf(&range1
, "%s..%s", argv
[0], argv
[1]);
72 strbuf_addf(&range2
, "%s..%s", argv
[0], argv
[2]);
73 } else if (argc
== 1) {
74 const char *b
= strstr(argv
[0], "..."), *a
= argv
[0];
78 error(_("single arg format must be symmetric range"));
79 usage_with_options(builtin_range_diff_usage
, options
);
90 strbuf_addf(&range1
, "%s..%.*s", b
, a_len
, a
);
91 strbuf_addf(&range2
, "%.*s..%s", a_len
, a
, b
);
93 error(_("need two commit ranges"));
94 usage_with_options(builtin_range_diff_usage
, options
);
97 res
= show_range_diff(range1
.buf
, range2
.buf
, creation_factor
,
100 strbuf_release(&range1
);
101 strbuf_release(&range2
);
102 strbuf_release(&four_spaces
);