comparison mercurial/hgweb/webutil.py @ 18409:e3f5cef11d6a

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. For the filerevnav version, we use an unfiltered changelog. Linkrev is currently broken with filtering and we need some failsafe to prevent traceback. This is the same approach as the one used in 518c1403838f. The use of filectx.changectx() allowed the previous code to use the 518c1403838f hack. This changeset may result in an incorrect behaviors, Navigation link may point to missing revision. However this bad navigation generation is much better than a plain crash
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Wed, 16 Jan 2013 13:18:22 +0100
parents f332a64fef51
children 6da1e979340a
comparison
equal deleted inserted replaced
18408:f332a64fef51 18409:e3f5cef11d6a
39 yield 3 * step 39 yield 3 * step
40 step *= 10 40 step *= 10
41 41
42 class revnav(object): 42 class revnav(object):
43 43
44 def __init__(self, nodefunc): 44 def __init__(self, repo):
45 """Navigation generation object 45 """Navigation generation object
46 46
47 :nodefun: factory for a changectx from a revision 47 :repo: repo object we generate nav for
48 """ 48 """
49 self.nodefunc = nodefunc 49 # used for hex generation
50 self._revlog = repo.changelog
50 51
51 def __nonzero__(self): 52 def __nonzero__(self):
52 """return True if any revision to navigate over""" 53 """return True if any revision to navigate over"""
53 try: 54 try:
54 self.nodefunc(0) 55 self._revlog.node(0)
55 return True 56 return True
56 except error.RepoError: 57 except error.RepoError:
57 return False 58 return False
58 59
59 def hex(self, rev): 60 def hex(self, rev):
60 return self.nodefunc(rev).hex() 61 return hex(self._revlog.node(rev))
61 62
62 def gen(self, pos, pagelen, limit): 63 def gen(self, pos, pagelen, limit):
63 """computes label and revision id for navigation link 64 """computes label and revision id for navigation link
64 65
65 :pos: is the revision relative to which we generate navigation. 66 :pos: is the revision relative to which we generate navigation.
92 data = lambda i: {"label": i[0], "node": i[1]} 93 data = lambda i: {"label": i[0], "node": i[1]}
93 return ({'before': lambda **map: (data(i) for i in navbefore), 94 return ({'before': lambda **map: (data(i) for i in navbefore),
94 'after': lambda **map: (data(i) for i in navafter)},) 95 'after': lambda **map: (data(i) for i in navafter)},)
95 96
96 class filerevnav(revnav): 97 class filerevnav(revnav):
97 pass 98
99 def __init__(self, repo, path):
100 """Navigation generation object
101
102 :repo: repo object we generate nav for
103 :path: path of the file we generate nav for
104 """
105 # used for iteration
106 self._changelog = repo.unfiltered().changelog
107 # used for hex generation
108 self._revlog = repo.file(path)
109
110 def hex(self, rev):
111 return hex(self._changelog.node(self._revlog.linkrev(rev)))
112
98 113
99 def _siblings(siblings=[], hiderev=None): 114 def _siblings(siblings=[], hiderev=None):
100 siblings = [s for s in siblings if s.node() != nullid] 115 siblings = [s for s in siblings if s.node() != nullid]
101 if len(siblings) == 1 and siblings[0].rev() == hiderev: 116 if len(siblings) == 1 and siblings[0].rev() == hiderev:
102 return 117 return