revset: avoid returning duplicates when returning ancestors
authorPierre-Yves David <pierre-yves.david@fb.com>
Wed, 26 Mar 2014 15:55:50 -0700
changeset 24940 6b54f749659b
parent 24939 85544a52ee84
child 24941 9c1942635c1f
revset: avoid returning duplicates when returning ancestors Before this patch, _revancestors were giving false result when a revision was duplicated in the input. Duplicated entry are rare but may happen when using the `%lx` notation internally. This series has no visible impact on the performance of the function according to benchmark.
mercurial/revset.py
tests/test-revset.t
--- a/mercurial/revset.py	Wed Mar 26 16:21:30 2014 -0700
+++ b/mercurial/revset.py	Wed Mar 26 15:55:50 2014 -0700
@@ -37,13 +37,13 @@
         seen = set()
         while h:
             current = -heapq.heappop(h)
+            if current == inputrev:
+                try:
+                    inputrev = irevs.next()
+                    heapq.heappush(h, -inputrev)
+                except StopIteration:
+                    pass
             if current not in seen:
-                if current == inputrev:
-                    try:
-                        inputrev = irevs.next()
-                        heapq.heappush(h, -inputrev)
-                    except StopIteration:
-                        pass
                 seen.add(current)
                 yield current
                 for parent in cl.parentrevs(current)[:cut]:
--- a/tests/test-revset.t	Wed Mar 26 16:21:30 2014 -0700
+++ b/tests/test-revset.t	Wed Mar 26 15:55:50 2014 -0700
@@ -1,5 +1,27 @@
   $ HGENCODING=utf-8
   $ export HGENCODING
+  $ cat > testrevset.py << EOF
+  > import mercurial.revset
+  > 
+  > baseset = mercurial.revset.baseset
+  > 
+  > def r3232(repo, subset, x):
+  >     """"simple revset that return [3,2,3,2]
+  > 
+  >     revisions duplicated on purpose.
+  >     """
+  >     if 3 not in subset:
+  >        if 2 in subset:
+  >            return baseset([2,2])
+  >        return baseset()
+  >     return baseset([3,3,2,2])
+  > 
+  > mercurial.revset.symbols['r3232'] = r3232
+  > EOF
+  $ cat >> $HGRCPATH << EOF
+  > [extensions]
+  > testrevset=$TESTTMP/testrevset.py
+  > EOF
 
   $ try() {
   >   hg debugrevspec --debug "$@"
@@ -340,6 +362,9 @@
   0
   $ log 'ancestor(1,2,3,4,5)'
   1
+
+test ancestors
+
   $ log 'ancestors(5)'
   0
   1
@@ -347,6 +372,12 @@
   5
   $ log 'ancestor(ancestors(5))'
   0
+  $ log '::r3232()'
+  0
+  1
+  2
+  3
+
   $ log 'author(bob)'
   2
   $ log 'author("re:bob|test")'