Add '...' operator for revisions
'A...B' is a shortcut for 'A B --not $(git-merge-base --all A B)'. This XOR-like operation is called symmetric difference in set theory. The symbol '...' has been chosen because it's rather similar to the existing '..' operator and the somewhat more natural caret ('^') is already taken. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <junkio@cox.net>
Rene Scharfe committed
Jul 2, 2006 at 01:29 UTC
0d2c9d67d9e1a2fd87b2daeefffffaff0b3f3a49
2 files changed
+53
-9
Documentation/git-rev-list.txt
+14
@@ -15,6 +15,7 @@ SYNOPSIS
15
[ \--sparse ]
16
[ \--no-merges ]
17
[ \--remove-empty ]
18
+ [ \--not ]
19
[ \--all ]
20
[ \--topo-order ]
21
[ \--parents ]
@@ -37,6 +38,14 @@ not in 'baz'".
38
A special notation <commit1>..<commit2> can be used as a
39
short-hand for {caret}<commit1> <commit2>.
40
41
+Another special notation is <commit1>...<commit2> which is useful for
42
+merges. The resulting set of commits is the symmetric difference
43
+between the two operands. The following two commands are equivalent:
44
+
45
+------------
46
+$ git-rev-list A B --not $(git-merge-base --all A B)
47
+$ git-rev-list A...B
48
+------------
49
50
OPTIONS
51
-------
@@ -93,6 +102,11 @@ OPTIONS
102
--remove-empty::
103
Stop when a given path disappears from the tree.
104
105
+--not::
106
+ Reverses the meaning of the '{caret}' prefix (or lack
107
+ thereof) for all following revision specifiers, up to
108
+ the next `--not`.
109
+
110
--all::
111
Pretend as if all the refs in `$GIT_DIR/refs/` are
112
listed on the command line as <commit>.
revision.c
+39
-9
@@ -536,6 +536,18 @@ void init_revisions(struct rev_info *revs)
536
diff_setup(&revs->diffopt);
537
}
538
539
+static void add_pending_commit_list(struct rev_info *revs,
540
+ struct commit_list *commit_list,
541
+ unsigned int flags)
542
+{
543
+ while (commit_list) {
544
+ struct object *object = &commit_list->item->object;
545
+ object->flags |= flags;
546
+ add_pending_object(revs, object, sha1_to_hex(object->sha1));
547
+ commit_list = commit_list->next;
548
+ }
549
+}
550
+
551
/*
552
* Parse revision information, filling in the "rev_info" structure,
553
* and removing the used arguments from the argument list.
@@ -771,27 +783,45 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
783
unsigned char from_sha1[20];
784
const char *next = dotdot + 2;
785
const char *this = arg;
786
+ int symmetric = *next == '.';
787
+ unsigned int flags_exclude = flags ^ UNINTERESTING;
788
+
789
*dotdot = 0;
790
+ next += symmetric;
791
+
792
if (!*next)
793
next = "HEAD";
794
if (dotdot == arg)
795
this = "HEAD";
796
if (!get_sha1(this, from_sha1) &&
797
!get_sha1(next, sha1)) {
781
- struct object *exclude;
782
- struct object *include;
783
-
784
- exclude = get_reference(revs, this, from_sha1, flags ^ UNINTERESTING);
785
- include = get_reference(revs, next, sha1, flags);
786
- if (!exclude || !include)
787
- die("Invalid revision range %s..%s", arg, next);
798
+ struct commit *a, *b;
799
+ struct commit_list *exclude;
800
+
801
+ a = lookup_commit_reference(from_sha1);
802
+ b = lookup_commit_reference(sha1);
803
+ if (!a || !b) {
804
+ die(symmetric ?
805
+ "Invalid symmetric difference expression %s...%s" :
806
+ "Invalid revision range %s..%s",
807
+ arg, next);
808
+ }
809
810
if (!seen_dashdash) {
811
*dotdot = '.';
812
verify_non_filename(revs->prefix, arg);
813
}
793
- add_pending_object(revs, exclude, this);
794
- add_pending_object(revs, include, next);
814
+
815
+ if (symmetric) {
816
+ exclude = get_merge_bases_clean(a, b);
817
+ add_pending_commit_list(revs, exclude,
818
+ flags_exclude);
819
+ a->object.flags |= flags;
820
+ } else
821
+ a->object.flags |= flags_exclude;
822
+ b->object.flags |= flags;
823
+ add_pending_object(revs, &a->object, this);
824
+ add_pending_object(revs, &b->object, next);
825
continue;
826
}
827
*dotdot = '.';