[PATCH v4 0/3] Range diff with ranges lacking dotdot
- From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Feb 4, 2021, 09:31 UTC
- Message-ID
- <pull.841.v4.git.1612431093.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.841.v3.git.1611765444.gitgitgadget@gmail.com>
In https://lore.kernel.org/git/20200306091933.mx2jmurmdnsjua4b@pengutronix.de/, it was reported that git range-diff does not handle commit ranges like rev^!. This patch series fixes that.
Changes since v3:
* The revision machinery is now used directly to validate the commit ranges.
Changes since v2:
* Move the helper function from revision.c to range-diff.c and rename it. * Use a regex to make it easier to understand what we're trying to match. * Fix the documentation that claimed that we used git merge-base internally when git range-diff parses ...-style arguments, which is not the case.
Changes since v1:
* In addition to git range-diff, git format-patch --range-diff gets the same improvement. * The comment talking about ^@ was removed. * The parsing was made a bit safer (e.g. catching ! by its own as an invalid range).
Johannes Schindelin (3): range-diff/format-patch: refactor check for commit range range-diff/format-patch: handle commit ranges other than A..B range-diff(docs): explain how to specify commit ranges
Documentation/git-range-diff.txt | 12 ++++++++++++ builtin/log.c | 2 +- builtin/range-diff.c | 9 +++++---- range-diff.c | 22 ++++++++++++++++++++++ range-diff.h | 8 ++++++++ t/t3206-range-diff.sh | 8 ++++++++ 6 files changed, 56 insertions(+), 5 deletions(-)
base-commit: 71ca53e8125e36efbda17293c50027d31681a41f Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-841%2Fdscho%2Frange-diff-with-ranges-lacking-dotdot-v4 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-841/dscho/range-diff-with-ranges-lacking-dotdot-v4 Pull-Request: https://github.com/gitgitgadget/git/pull/841
Range-diff vs v3:
1: b98fa94b8703 = 1: b98fa94b8703 range-diff/format-patch: refactor check for commit range
2: 0880ca587e63 ! 2: 448e6a64fa15 range-diff/format-patch: handle commit ranges other than A..B
@@ Commit message
described to specify commit ranges that `range-diff` does not yet
accept: "<commit>^!" and "<commit>^-<n>".
- Let's accept them.
+ Let's accept them, by parsing them via the revision machinery and
+ looking for at least one interesting and one uninteresting revision in
+ the resulting `pending` array.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
## range-diff.c ##
+@@
+ #include "pretty.h"
+ #include "userdiff.h"
+ #include "apply.h"
++#include "revision.h"
+
+ struct patch_util {
+ /* For the search for an exact match */
@@ range-diff.c: 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;
++ char *copy = xstrdup(arg); /* setup_revisions() modifies it */
++ const char *argv[] = { "", copy, "--", NULL };
++ int i, positive = 0, negative = 0;
++ struct rev_info revs;
+
-+ /* match `<rev>^!` and `<rev>^-<n>` */
-+ if (!regex) {
-+ regex = xmalloc(sizeof(*regex));
-+ if (regcomp(regex, "\\^(!|-[0-9]*)$", REG_EXTENDED) < 0)
-+ BUG("could not compile range-diff regex");
++ init_revisions(&revs, NULL);
++ if (setup_revisions(3, argv, &revs, 0) == 1) {
++ for (i = 0; i < revs.pending.nr; i++)
++ if (revs.pending.objects[i].item->flags & UNINTERESTING)
++ negative++;
++ else
++ positive++;
+ }
+
-+ return !regexec(regex, arg, 0, NULL, 0);
++ free(copy);
++ object_array_clear(&revs.pending);
++ return negative > 0 && positive > 0;
}
## t/t3206-range-diff.sh ##
3: 5ab9321a34ca = 3: 295fdc1cd32c range-diff(docs): explain how to specify commit ranges-- gitgitgadget