shelve: move mutableancestors to not be a closure
authorKostia Balytskyi <ikostia@fb.com>
Thu, 10 Nov 2016 03:24:07 -0800
changeset 30380 84e8cbdbdee4
parent 30379 684068d24658
child 30381 caba61934721
shelve: move mutableancestors to not be a closure There's no value in it being a closure and everyone who tries to read the outer function code will be distracted by it. IMO moving it out significantly improves readability, especially given how clear it is what mutableancestors function does from its name.
hgext/shelve.py
--- a/hgext/shelve.py	Thu Nov 10 03:22:55 2016 -0800
+++ b/hgext/shelve.py	Thu Nov 10 03:24:07 2016 -0800
@@ -273,24 +273,24 @@
         raise error.Abort(_("shelved change names may not start with '.'"))
     return name
 
-def _docreatecmd(ui, repo, pats, opts):
-    def mutableancestors(ctx):
-        """return all mutable ancestors for ctx (included)
+def mutableancestors(ctx):
+    """return all mutable ancestors for ctx (included)
 
-        Much faster than the revset ancestors(ctx) & draft()"""
-        seen = set([nodemod.nullrev])
-        visit = collections.deque()
-        visit.append(ctx)
-        while visit:
-            ctx = visit.popleft()
-            yield ctx.node()
-            for parent in ctx.parents():
-                rev = parent.rev()
-                if rev not in seen:
-                    seen.add(rev)
-                    if parent.mutable():
-                        visit.append(parent)
+    Much faster than the revset ancestors(ctx) & draft()"""
+    seen = set([nodemod.nullrev])
+    visit = collections.deque()
+    visit.append(ctx)
+    while visit:
+        ctx = visit.popleft()
+        yield ctx.node()
+        for parent in ctx.parents():
+            rev = parent.rev()
+            if rev not in seen:
+                seen.add(rev)
+                if parent.mutable():
+                    visit.append(parent)
 
+def _docreatecmd(ui, repo, pats, opts):
     wctx = repo[None]
     parents = wctx.parents()
     if len(parents) > 1: