Patchwork [19,of,23,Series-D] hgweb: pass repo object to revnav construction

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

Comments

Pierre-Yves David - Jan. 11, 2013, 12:24 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1357842679 -3600
# Node ID d589ad7c9bf9b76b553a8c6246d8ca6e728a4a29
# Parent  850d6883d0c2c856ca663ee7053c0cc8e0f85688
hgweb: pass repo object to revnav construction

This adds the flexibility we will needs.

Patch

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(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(**x),
                 latestentry=lambda **x: changelist(lastest=True,**x),
@@ -773,12 +773,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(**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(web.repo.changectx).gen(pos, revcount, count)
+    changenav = webutil.revnav(web.repo).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
@@ -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.
@@ -96,11 +97,25 @@  class revnav(object):
 
         return ({'before':gen(navbefore),
                  'after': gen(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