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

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 11, 2013, 12:23 a.m.
Message ID <35401f390daa6e095af3.1357863834@yamac.lan>
Download mbox | patch
Permalink /patch/545/
State Superseded
Headers show

Comments

Pierre-Yves David - Jan. 11, 2013, 12:23 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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.

Patch

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