changeset 33073:b04cf7a6e0f3

dagop: unnest inner generator of revdescendants() This just moves iterate() to module-level function.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 18 Jun 2017 17:02:03 +0900
parents 6d767d62b25e
children e999b59d6eb1
files mercurial/dagop.py
diffstat 1 files changed, 23 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dagop.py	Sun Jun 25 00:14:48 2017 +0900
+++ b/mercurial/dagop.py	Sun Jun 18 17:02:03 2017 +0900
@@ -84,34 +84,35 @@
     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>))