Skip to content

Commit edd6a31

Browse files
dschogitster
authored andcommitted
range-diff: reorder argument handling
In d9c66f0 (range-diff: first rudimentary implementation, 2018-08-13), we introduced the argument handling of the `range-diff` command, special-casing three different stanzas based on the argument count. The somewhat unorthodox order (first handling the case of 2 arguments, then 3, then 1) was chosen for clarity: the natural argument number is 2 because that is how many revision ranges are used internally. The code to handle three arguments is relatively trivial, so it was added next. And finally, the code to ungarble a single symmetric range into two separate ones was added, because it was the most complicated (the most inelegant part being about interpreting empty sides of the symmetric range as `HEAD`). In preparation for allowing pathspecs in `git range-diff` invocations, where we no longer have the luxury of using the number of arguments to disambiguate between these three different ways to specify the commit ranges, we need to order these cases by argument count, in descending order. This patch is best viewed with `--color-moved`. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 795ea87 commit edd6a31

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

builtin/range-diff.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix)
5555
if (!simple_color)
5656
diffopt.use_color = 1;
5757

58-
if (argc == 2) {
58+
if (argc == 3) {
59+
strbuf_addf(&range1, "%s..%s", argv[0], argv[1]);
60+
strbuf_addf(&range2, "%s..%s", argv[0], argv[2]);
61+
} else if (argc == 2) {
5962
if (!is_range_diff_range(argv[0]))
6063
die(_("not a commit range: '%s'"), argv[0]);
6164
strbuf_addstr(&range1, argv[0]);
6265

6366
if (!is_range_diff_range(argv[1]))
6467
die(_("not a commit range: '%s'"), argv[1]);
6568
strbuf_addstr(&range2, argv[1]);
66-
} else if (argc == 3) {
67-
strbuf_addf(&range1, "%s..%s", argv[0], argv[1]);
68-
strbuf_addf(&range2, "%s..%s", argv[0], argv[2]);
6969
} else if (argc == 1) {
7070
const char *b = strstr(argv[0], "..."), *a = argv[0];
7171
int a_len;

0 commit comments

Comments
 (0)