From 6408a2bc250752472af1cffc38f8c3365497a7c9 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 20 Jan 2021 22:24:06 +0100 Subject: [PATCH] range-diff/format-patch: handle commit ranges other than A..B In the `SPECIFYING RANGES` section of gitrevisions[7], two ways are described to specify commit ranges that `range-diff` does not yet accept: "^!" and "^-". Let's accept them. Signed-off-by: Johannes Schindelin --- range-diff.c | 13 ++++++++++++- t/t3206-range-diff.sh | 8 ++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/range-diff.c b/range-diff.c index 9b93e08e840747..ab5dbb752d4559 100644 --- a/range-diff.c +++ b/range-diff.c @@ -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); } diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh index 6eb344be0312a4..e217cecac9ed27 100755 --- a/t/t3206-range-diff.sh +++ b/t/t3206-range-diff.sh @@ -150,6 +150,14 @@ test_expect_success 'simple A B C (unmodified)' ' test_cmp expect actual ' +test_expect_success 'A^! and A^- (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 &&