dagop: extend filectxancestors() to walk multiple files
authorYuya Nishihara <yuya@tcha.org>
Thu, 22 Sep 2016 18:23:58 +0900
changeset 35276 205c3c6c1a51
parent 35275 b4b328ea6175
child 35277 6ba79cf34f5e
dagop: extend filectxancestors() to walk multiple files
mercurial/dagop.py
mercurial/revset.py
--- a/mercurial/dagop.py	Thu Sep 22 18:18:56 2016 +0900
+++ b/mercurial/dagop.py	Thu Sep 22 18:23:58 2016 +0900
@@ -75,8 +75,9 @@
                 if prev != node.nullrev:
                     heapq.heappush(pendingheap, (heapsign * prev, pdepth))
 
-def filectxancestors(fctx, followfirst=False):
-    """Like filectx.ancestors(), but includes the given fctx itself"""
+def filectxancestors(fctxs, followfirst=False):
+    """Like filectx.ancestors(), but can walk from multiple files/revisions,
+    and includes the given fctxs themselves"""
     visit = {}
     def addvisit(fctx):
         rev = fctx.rev()
@@ -89,7 +90,8 @@
     else:
         cut = None
 
-    addvisit(fctx)
+    for c in fctxs:
+        addvisit(c)
     while visit:
         rev = max(visit)
         c = visit[rev].pop()
--- a/mercurial/revset.py	Thu Sep 22 18:18:56 2016 +0900
+++ b/mercurial/revset.py	Thu Sep 22 18:23:58 2016 +0900
@@ -927,11 +927,9 @@
 
         files = c.manifest().walk(matcher)
 
-        s = set()
-        for fname in files:
-            fctx = c[fname].introfilectx()
-            a = dagop.filectxancestors(fctx, followfirst)
-            s = s.union(set(c.rev() for c in a))
+        fctxs = [c[f].introfilectx() for f in files]
+        a = dagop.filectxancestors(fctxs, followfirst)
+        s = set(c.rev() for c in a)
     else:
         s = dagop.revancestors(repo, baseset([c.rev()]), followfirst)