context: be even more careful about result order in ancestors() (issue2642) stable
authorMatt Mackall <mpm@selenic.com>
Fri, 25 Feb 2011 15:31:32 -0600
branchstable
changeset 13481 4eb1e9d6a7c9
parent 13480 69418d4525d1
child 13491 9c5aae633d5f
context: be even more careful about result order in ancestors() (issue2642) The earlier patch could be confused by more complicated topologies.
mercurial/context.py
--- a/mercurial/context.py	Thu Feb 24 01:14:15 2011 +0530
+++ b/mercurial/context.py	Fri Feb 25 15:31:32 2011 -0600
@@ -550,19 +550,15 @@
         return None
 
     def ancestors(self):
-        seen = set()
-        visit = [self]
-        while visit:
-            parents = visit.pop(0).parents()
-            if len(parents) > 1 and parents[1].rev() > parents[0].rev():
-                # make sure we return ancestors in reverse revision order
-                parents = reversed(parents)
-            for parent in parents:
-                s = str(parent)
-                if s not in seen:
-                    visit.append(parent)
-                    seen.add(s)
-                    yield parent
+        visit = {}
+        c = self
+        while True:
+            for parent in c.parents():
+                visit[(parent.rev(), parent.node())] = parent
+            if not visit:
+                break
+            c = visit.pop(max(visit))
+            yield c
 
 class workingctx(changectx):
     """A workingctx object makes access to data related to