Submitter | Pierre-Yves David |
---|---|
Date | Jan. 14, 2013, 8:35 p.m. |
Message ID | <d37dda282ef4a22805c8.1358195736@yamac.lan> |
Download | mbox | patch |
Permalink | /patch/600/ |
State | Superseded |
Headers | show |
Comments
On 14 janv. 2013, at 22:05, Kevin Bullock wrote: > On Jan 14, 2013, at 2:35 PM, Pierre-Yves David wrote: > >> # HG changeset patch >> # User Pierre-Yves David <pierre-yves.david@logilab.fr> >> # Date 1357839775 -3600 >> # Node ID d37dda282ef4a22805c8c2e22bb7e5be5cfabbda >> # Parent 5b869199ef7c34866bce802b43d1764b02e505ab >> 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. > > Eh? It's not a closure (no variables bound from the enclosing scope). Did you mean "generator"? hum yeah it is actually a just a generator here. (There is a lot of actual closure in this code, got me confused when writing the message)
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