diff options
author | Johannes Schindelin <johannes.schindelin@gmx.de> | 2021-02-05 14:44:48 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-02-06 21:24:55 -0800 |
commit | 359f0d754ab709c5a1ff3267bc117fb8559c62c2 (patch) | |
tree | 05586b877349a8bc8466f2a7a733df04585cd14a /range-diff.c | |
parent | 679b5916cdafdcfa9fb36c31dbf53d7e4aa0af0b (diff) | |
download | git-359f0d754ab709c5a1ff3267bc117fb8559c62c2.tar.gz |
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: "<commit>^!" and "<commit>^-<n>".
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.
This also finally lets us reject arguments that _do_ contain `..` but
are not actually ranges, e.g. `HEAD^{/do.. match this}`.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'range-diff.c')
-rw-r--r-- | range-diff.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/range-diff.c b/range-diff.c index 9b93e08e84..a88612cb89 100644 --- a/range-diff.c +++ b/range-diff.c @@ -11,6 +11,7 @@ #include "pretty.h" #include "userdiff.h" #include "apply.h" +#include "revision.h" struct patch_util { /* For the search for an exact match */ @@ -567,5 +568,28 @@ int show_range_diff(const char *range1, const char *range2, int is_range_diff_range(const char *arg) { - return !!strstr(arg, ".."); + char *copy = xstrdup(arg); /* setup_revisions() modifies it */ + const char *argv[] = { "", copy, "--", NULL }; + int i, positive = 0, negative = 0; + struct rev_info revs; + + init_revisions(&revs, NULL); + if (setup_revisions(3, argv, &revs, NULL) == 1) { + for (i = 0; i < revs.pending.nr; i++) + if (revs.pending.objects[i].item->flags & UNINTERESTING) + negative++; + else + positive++; + for (i = 0; i < revs.pending.nr; i++) { + struct object *obj = revs.pending.objects[i].item; + + if (obj->type == OBJ_COMMIT) + clear_commit_marks((struct commit *)obj, + ALL_REV_FLAGS); + } + } + + free(copy); + object_array_clear(&revs.pending); + return negative > 0 && positive > 0; } |