diff mercurial/ancestor.py @ 39491:a60dae060bc8

ancestors: ensure a consistent order even in the "inclusive" case It seems odds to first issue the "source" revs and then the other ancestors. In addition, doing so can break the other contract of always issuing a child before its parent. We update the code to apply the same logic to all yielded revision. No tests break so we seem in the clear except where we explicitly test the order.
author Boris Feld <boris.feld@octobus.net>
date Thu, 06 Sep 2018 19:37:38 -0400
parents b6db2e80a9ce
children 7eadc9407867
line wrap: on
line diff
--- a/mercurial/ancestor.py	Thu Sep 06 17:00:28 2018 -0400
+++ b/mercurial/ancestor.py	Thu Sep 06 19:37:38 2018 -0400
@@ -309,31 +309,30 @@
         revision number order. That order is also topological: a child is
         always emitted before its parent.
 
-        If inclusive is True, yield all the revs first (ignoring stoprev),
-        then yield all the ancestors of revs as when inclusive is False. If an
-        element in revs is an ancestor of a different rev it is not yielded
-        again."""
+        If inclusive is True, the source revisions are also yielded. The
+        reverse revision number order is still enforced."""
         seen = set()
         revs = self._initrevs
-        if self._inclusive:
-            for rev in revs:
-                yield rev
-            seen.update(revs)
 
         parentrevs = self._parentrevs
         stoprev = self._stoprev
-        visit = []
-        heapq.heapify(visit)
         schedule = heapq.heappush
         nextitem = heapq.heappop
         see = seen.add
         see(nullrev)
 
-        for r in revs:
-            for parent in parentrevs(r):
-                if parent not in seen:
-                    schedule(visit, -parent)
-                    see(parent)
+        if self._inclusive:
+            visit = [-r for r in revs]
+            seen.update(revs)
+            heapq.heapify(visit)
+        else:
+            visit = []
+            heapq.heapify(visit)
+            for r in revs:
+                for parent in parentrevs(r):
+                    if parent not in seen:
+                        schedule(visit, -parent)
+                        see(parent)
 
         while visit:
             current = -nextitem(visit)