Patchwork [14,of,22,V2-Series-D] hgweb: pass repo object to revnav construction

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 14, 2013, 8:35 p.m.
Message ID <70aa9a56ce5815fad55a.1358195746@yamac.lan>
Download mbox | patch
Permalink /patch/611/
State Superseded
Commit e3f5cef11d6a8eafdbaefa9b6c3d0e91fc3273fc
Headers show

Comments

Pierre-Yves David - Jan. 14, 2013, 8:35 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1358181531 -3600
# Node ID 70aa9a56ce5815fad55ad3f5a72c12287e1bd577
# Parent  ac76bc6f90545c3252d8cc1e8109e75de22aea4c
hgweb: pass repo object to revnav construction

For compatibility with changelog filtering we need access to the changelog, a
simple nodefunc is not sufficient, only the changelog and repo have access the
filteredrevs information.

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(web.repo.changectx).gen(pos, revcount, count)
+    changenav = webutil.revnav(web.repo).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),
@@ -769,12 +769,12 @@  def filelog(web, req, tmpl):
                       "inbranch": webutil.nodeinbranch(repo, iterfctx),
                       "branches": webutil.nodebranchdict(repo, iterfctx)})
         for e in reversed(l):
             yield e
 
-    nodefunc = lambda x: fctx.filectx(fileid=x)
-    nav = webutil.filerevnav(nodefunc).gen(end - 1, revcount, count)
+    revnav = webutil.filerevnav(web.repo, fctx.path())
+    nav = revnav.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)
 
@@ -850,11 +850,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(web.repo.changectx).gen(pos, revcount, count)
+    changenav = webutil.revnav(web.repo).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,27 +39,28 @@  def _navseq(step, firststep=None):
         yield 3 * step
         step *= 10
 
 class revnav(object):
 
-    def __init__(self, nodefunc):
+    def __init__(self, repo):
         """Navigation generation object
 
-        :nodefun: factory for a changectx from a revision
+        :repo: repo object we generate nav for
         """
-        self.nodefunc = nodefunc
+        # used for hex generation
+        self.cl = repo.changelog
 
     def __nonzero__(self):
         """return True if any revision to navigate over"""
         try:
-            self.nodefunc(0)
+            self.cl.node(0)
             return True
         except error.RepoError:
             return False
 
     def hex(self, rev):
-        return self.nodefunc(rev).hex()
+        return hex(self.cl.node(rev))
 
     def gen(self, pos, pagelen, limit):
         """computes label and revision id for navigation link
 
         :pos: is the revision relative to which we generate navigation.
@@ -92,11 +93,25 @@  class revnav(object):
         data = lambda i: {"label": i[0], "node": i[1]}
         return ({'before': lambda **map: (data(i) for i in navbefore),
                  'after':  lambda **map: (data(i) for i in navafter)},)
 
 class filerevnav(revnav):
-    pass
+
+    def __init__(self, repo, path):
+        """Navigation generation object
+
+        :repo: repo object we generate nav for
+        :path: path of the file we generate nav for
+        """
+        # used for iteration
+        self._hl = repo.changelog
+        # used for hex generation
+        self.cl = repo.file(path)
+
+    def hex(self, rev):
+        return hex(self._hl.node(self.cl.linkrev(rev)))
+
 
 def _siblings(siblings=[], hiderev=None):
     siblings = [s for s in siblings if s.node() != nullid]
     if len(siblings) == 1 and siblings[0].rev() == hiderev:
         return