Patchwork [05,of,15,V3] hgweb: pass nodefunc to the revnav object

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 16, 2013, 1:32 p.m.
Message ID <283c1f260d7d851dac6c.1358343131@crater2.logilab.fr>
Download mbox | patch
Permalink /patch/647/
State Accepted
Commit 1da84a6b136ad58d4b1ea1f1cce2f883b22cf9bb
Delegated to: Kevin Bullock
Headers show

Comments

Pierre-Yves David - Jan. 16, 2013, 1:32 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1357840777 -3600
# Node ID 283c1f260d7d851dac6c7ae0dfcdd2f7e18cb248
# Parent  54a6788dab9ece15d3815d8abedba721fceba32c
hgweb: pass nodefunc to the revnav object

The issue between hgweb and filtering lay in this function. Moving it into the
object itself helps to abstract the erroneous bit.

Patch

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -240,11 +240,11 @@  def changelog(web, req, tmpl, shortlog=F
     start = max(0, pos - revcount + 1)
     end = min(count, start + revcount)
     pos = end - 1
     parity = paritygen(web.stripecount, offset=start - end)
 
-    changenav = webutil.revnav().gen(pos, revcount, count, web.repo.changectx)
+    changenav = webutil.revnav(web.repo.changectx).gen(pos, revcount, count)
 
     return tmpl(shortlog and 'shortlog' or 'changelog', changenav=changenav,
                 node=ctx.hex(), rev=pos, changesets=count,
                 entries=lambda **x: changelist(latestonly=False, **x),
                 latestentry=lambda **x: changelist(latestonly=True, **x),
@@ -770,11 +770,11 @@  def filelog(web, req, tmpl):
                       "branches": webutil.nodebranchdict(repo, iterfctx)})
         for e in reversed(l):
             yield e
 
     nodefunc = lambda x: fctx.filectx(fileid=x)
-    nav = webutil.revnav().gen(end - 1, revcount, count, nodefunc)
+    nav = webutil.revnav(nodefunc).gen(end - 1, revcount, count)
     return tmpl("filelog", file=f, node=fctx.hex(), nav=nav,
                 entries=lambda **x: entries(latestonly=False, **x),
                 latestentry=lambda **x: entries(latestonly=True, **x),
                 revcount=revcount, morevars=morevars, lessvars=lessvars)
 
@@ -849,11 +849,11 @@  def graph(web, req, tmpl):
     end = min(count, start + revcount)
     pos = end - 1
 
     uprev = min(max(0, count - 1), rev + revcount)
     downrev = max(0, rev - revcount)
-    changenav = webutil.revnav().gen(pos, revcount, count, web.repo.changectx)
+    changenav = webutil.revnav(web.repo.changectx).gen(pos, revcount, count)
 
     dag = graphmod.dagwalker(web.repo, range(start, end)[::-1])
     tree = list(graphmod.colored(dag, web.repo))
 
     def getcolumns(tree):
diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -39,17 +39,23 @@  def _navseq(step, firststep=None):
         yield 3 * step
         step *= 10
 
 class revnav(object):
 
-    def gen(self, pos, pagelen, limit, nodefunc):
+    def __init__(self, nodefunc):
+        """Navigation generation object
+
+        :nodefun: factory for a changectx from a revision
+        """
+        self.nodefunc = nodefunc
+
+    def gen(self, pos, pagelen, limit):
         """computes label and revision id for navigation link
 
         :pos: is the revision relative to which we generate navigation.
         :pagelen: the size of each navigation page
         :limit: how far shall we link
-        :nodefun: factory for a changectx from a revision
 
         The return is:
             - a single element tuple
             - containing a dictionary with a `before` and `after` key
             - values are generator functions taking arbitrary number of kwargs
@@ -61,17 +67,19 @@  class revnav(object):
 
         for f in _navseq(1, pagelen):
             if f > limit:
                 break
             if pos + f < limit:
-                navafter.append(("+%d" % f, hex(nodefunc(pos + f).node())))
+                navafter.append(("+%d" % f,
+                                 hex(self.nodefunc(pos + f).node())))
             if pos - f >= 0:
-                navbefore.insert(0, ("-%d" % f, hex(nodefunc(pos - f).node())))
+                navbefore.insert(0, ("-%d" % f,
+                                     hex(self.nodefunc(pos - f).node())))
 
         navafter.append(("tip", "tip"))
         try:
-            navbefore.insert(0, ("(0)", hex(nodefunc(0).node())))
+            navbefore.insert(0, ("(0)", hex(self.nodefunc(0).node())))
         except error.RepoError:
             pass
 
         data = lambda i: {"label": i[0], "node": i[1]}
         return ({'before': lambda **map: (data(i) for i in navbefore),