[PATCH 08 of 23 Series-D] hgweb: pass nodefunc to the revnav object

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


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1357840777 -3600
# Node ID d1d55dc1217fcfad2d5e5875547fd680978e2ba0
# Parent  171cc6997b2a2fc3e0b47e7320c4f118757814a9
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.

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -243,11 +243,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(**x),
                 latestentry=lambda **x: changelist(lastest=True,**x),
@@ -774,11 +774,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(**x),
                 latestentry=lambda **x: entries(lastest=True, **x),
                 revcount=revcount, morevars=morevars, lessvars=lessvars)
 
@@ -854,11 +854,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)
 
     tree = []
     if start < end:
         revs = list(web.repo.changelog.revs(end - 1, start))
         dag = graphmod.dagwalker(web.repo, revs)
diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -24,17 +24,23 @@ def up(p):
         return "/"
     return up + "/"
 
 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 since of each navigation pages
         :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 function taking arbitrary number of kwargs
@@ -60,17 +66,19 @@ class revnav(object):
                 continue
             if f > limit:
                 break
             last = f
             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
 
         def gen(l):
             def f(**map):


More information about the Mercurial-devel mailing list