[PATCH 09 of 23 Series-D] hgweb: move the `seq` closure into a dedicated function

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Jan 10 18:23:54 CST 2013


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1357839775 -3600
# Node ID 35401f390daa6e095af3bf0d1b8098ee0eea7b5c
# Parent  d1d55dc1217fcfad2d5e5875547fd680978e2ba0
hgweb: move the `seq` closure into a dedicated function

There is not reason for it to be a closure. And this function could use a major
reworks.

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -22,10 +22,21 @@ def up(p):
     up = os.path.dirname(p)
     if up == "/":
         return "/"
     return up + "/"
 
+def _navseq(factor, limit=None):
+    if limit:
+        yield limit
+        if limit >= 20 and limit <= 40:
+            yield 50
+    else:
+        yield 1 * factor
+        yield 3 * factor
+    for f in _navseq(factor * 10):
+        yield f
+
 class revnav(object):
 
     def __init__(self, nodefunc):
         """Navigation generation object
 
@@ -44,26 +55,16 @@ class revnav(object):
             - a single element tuple
             - containing a dictionary with a `before` and `after` key
             - values are generator function taking arbitrary number of kwargs
             - yield items are dictionnary with `label` and `node` key
         """
-        def seq(factor, limit=None):
-            if limit:
-                yield limit
-                if limit >= 20 and limit <= 40:
-                    yield 50
-            else:
-                yield 1 * factor
-                yield 3 * factor
-            for f in seq(factor * 10):
-                yield f
 
         navbefore = []
         navafter = []
 
         last = 0
-        for f in seq(1, pagelen):
+        for f in _navseq(1, pagelen):
             if f < pagelen or f <= last:
                 continue
             if f > limit:
                 break
             last = f


More information about the Mercurial-devel mailing list