Skip to content

Commit

Permalink
range-diff/format-patch: handle commit ranges other than A..B
Browse files Browse the repository at this point in the history
In the `SPECIFYING RANGES` section of gitrevisions[7], two ways are
described to specify commit ranges that `range-diff` does not yet
accept: "<commit>^!" and "<commit>^-<n>".

Let's accept them.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Jan 27, 2021
1 parent b98fa94 commit 6408a2b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
13 changes: 12 additions & 1 deletion range-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,5 +567,16 @@ int show_range_diff(const char *range1, const char *range2,

int is_range_diff_range(const char *arg)
{
return !!strstr(arg, "..");
static regex_t *regex;

if (strstr(arg, ".."))
return 1;

if (!regex) {
regex = xmalloc(sizeof(*regex));
if (regcomp(regex, "\\^(!|-[0-9]*)$", REG_EXTENDED) < 0)
BUG("could not compile range-diff regex");
}

return !regexec(regex, arg, 0, NULL, 0);
}
8 changes: 8 additions & 0 deletions t/t3206-range-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ test_expect_success 'simple A B C (unmodified)' '
test_cmp expect actual
'

test_expect_success 'A^! and A^-<n> (unmodified)' '
git range-diff --no-color topic^! unmodified^-1 >actual &&
cat >expect <<-EOF &&
1: $(test_oid t4) = 1: $(test_oid u4) s/12/B/
EOF
test_cmp expect actual
'

test_expect_success 'trivial reordering' '
git range-diff --no-color master topic reordered >actual &&
cat >expect <<-EOF &&
Expand Down

0 comments on commit 6408a2b

Please sign in to comment.