diff mercurial/dagop.py @ 35279:0d27685b4a2f

dagop: copy basefilectx.ancestors() to free function The primary goal of this series is to make follow() support multiple start revisions. dagop.filectxancestors() will be extended to take multiple filectxs. basefilectx.ancestors() is not forwarded to this function because doing that would resurrect the performance issue fixed by 24b57c3899f8.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 22 Sep 2016 17:16:53 +0900
parents c6c8a52e28c9
children d90c534099b1
line wrap: on
line diff
--- a/mercurial/dagop.py	Thu Sep 22 15:52:09 2016 +0900
+++ b/mercurial/dagop.py	Thu Sep 22 17:16:53 2016 +0900
@@ -75,6 +75,23 @@
                 if prev != node.nullrev:
                     heapq.heappush(pendingheap, (heapsign * prev, pdepth))
 
+def filectxancestors(fctx, followfirst=False):
+    """Like filectx.ancestors()"""
+    visit = {}
+    c = fctx
+    if followfirst:
+        cut = 1
+    else:
+        cut = None
+
+    while True:
+        for parent in c.parents()[:cut]:
+            visit[(parent.linkrev(), parent.filenode())] = parent
+        if not visit:
+            break
+        c = visit.pop(max(visit))
+        yield c
+
 def _genrevancestors(repo, revs, followfirst, startdepth, stopdepth, cutfunc):
     if followfirst:
         cut = 1