Patchwork [8,of,8] dagop: extend filectxancestors() to walk multiple files

login
register
mail settings
Submitter Yuya Nishihara
Date Dec. 6, 2017, 3:05 p.m.
Message ID <08c1712189f71ca0298c.1512572752@mimosa>
Download mbox | patch
Permalink /patch/25977/
State Accepted
Headers show

Comments

Yuya Nishihara - Dec. 6, 2017, 3:05 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1474536238 -32400
#      Thu Sep 22 18:23:58 2016 +0900
# Node ID 08c1712189f71ca0298c27c3d16f0f8785f83387
# Parent  332685a30e1bc26b600c8d446820e87536c59c00
dagop: extend filectxancestors() to walk multiple files
Augie Fackler - Dec. 6, 2017, 10:30 p.m.
On Thu, Dec 07, 2017 at 12:05:52AM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1474536238 -32400
> #      Thu Sep 22 18:23:58 2016 +0900
> # Node ID 08c1712189f71ca0298c27c3d16f0f8785f83387
> # Parent  332685a30e1bc26b600c8d446820e87536c59c00
> dagop: extend filectxancestors() to walk multiple files

queued, thanks

Patch

diff --git a/mercurial/dagop.py b/mercurial/dagop.py
--- a/mercurial/dagop.py
+++ b/mercurial/dagop.py
@@ -75,8 +75,9 @@  def _walkrevtree(pfunc, revs, startdepth
                 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 @@  def filectxancestors(fctx, followfirst=F
     else:
         cut = None
 
-    addvisit(fctx)
+    for c in fctxs:
+        addvisit(c)
     while visit:
         rev = max(visit)
         c = visit[rev].pop()
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -927,11 +927,9 @@  def _follow(repo, subset, x, name, follo
 
         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)