Patchwork [3,of,8,shelve-ext,v2] shelve: move mutableancestors to not be a closure

login
register
mail settings
Submitter Kostia Balytskyi
Date Nov. 10, 2016, 11:37 a.m.
Message ID <98fdb6cda2b2cb384355.1478777847@dev1902.lla1.facebook.com>
Download mbox | patch
Permalink /patch/17440/
State Accepted
Headers show

Comments

Kostia Balytskyi - Nov. 10, 2016, 11:37 a.m.
# HG changeset patch
# User Kostia Balytskyi <ikostia@fb.com>
# Date 1478777047 28800
#      Thu Nov 10 03:24:07 2016 -0800
# Node ID 98fdb6cda2b2cb38435560134c52a4ebb8859b45
# Parent  dc50b5aa86a26417f3f6dee97ea762da3d891f1d
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.

Patch

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -273,24 +273,24 @@  def getshelvename(repo, parent, opts):
         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: