Patchwork [2,of,9] dagop: unnest inner generator of revdescendants()

login
register
mail settings
Submitter Yuya Nishihara
Date June 25, 2017, 3:26 a.m.
Message ID <d00125578b5af1d0c4a8.1498361171@mimosa>
Download mbox | patch
Permalink /patch/21683/
State Accepted
Headers show

Comments

Yuya Nishihara - June 25, 2017, 3:26 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1497772923 -32400
#      Sun Jun 18 17:02:03 2017 +0900
# Node ID d00125578b5af1d0c4a8c6666257ed202ba7eb4b
# Parent  cbf00411cd3e5c2db0ccdf73aaa35ea965c36648
dagop: unnest inner generator of revdescendants()

This just moves iterate() to module-level function.

Patch

diff --git a/mercurial/dagop.py b/mercurial/dagop.py
--- a/mercurial/dagop.py
+++ b/mercurial/dagop.py
@@ -84,34 +84,35 @@  def revancestors(repo, revs, followfirst
     gen = _genrevancestors(repo, revs, followfirst, startdepth, stopdepth)
     return generatorset(gen, iterasc=False)
 
-def revdescendants(repo, revs, followfirst):
-    """Like revlog.descendants() but supports followfirst."""
+def _genrevdescendants(repo, revs, followfirst):
     if followfirst:
         cut = 1
     else:
         cut = None
 
-    def iterate():
-        cl = repo.changelog
-        # XXX this should be 'parentset.min()' assuming 'parentset' is a
-        # smartset (and if it is not, it should.)
-        first = min(revs)
-        nullrev = node.nullrev
-        if first == nullrev:
-            # Are there nodes with a null first parent and a non-null
-            # second one? Maybe. Do we care? Probably not.
-            for i in cl:
-                yield i
-        else:
-            seen = set(revs)
-            for i in cl.revs(first + 1):
-                for x in cl.parentrevs(i)[:cut]:
-                    if x != nullrev and x in seen:
-                        seen.add(i)
-                        yield i
-                        break
+    cl = repo.changelog
+    # XXX this should be 'parentset.min()' assuming 'parentset' is a
+    # smartset (and if it is not, it should.)
+    first = min(revs)
+    nullrev = node.nullrev
+    if first == nullrev:
+        # Are there nodes with a null first parent and a non-null
+        # second one? Maybe. Do we care? Probably not.
+        for i in cl:
+            yield i
+    else:
+        seen = set(revs)
+        for i in cl.revs(first + 1):
+            for x in cl.parentrevs(i)[:cut]:
+                if x != nullrev and x in seen:
+                    seen.add(i)
+                    yield i
+                    break
 
-    return generatorset(iterate(), iterasc=True)
+def revdescendants(repo, revs, followfirst):
+    """Like revlog.descendants() but supports followfirst."""
+    gen = _genrevdescendants(repo, revs, followfirst)
+    return generatorset(gen, iterasc=True)
 
 def _reachablerootspure(repo, minroot, roots, heads, includepath):
     """return (heads(::<roots> and ::<heads>))