Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/webutil.py @ 18404:1da84a6b136a
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.
author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
---|---|
date | Thu, 10 Jan 2013 18:59:37 +0100 |
parents | bfaee31a83d2 |
children | 1eaf0d017b2c |
comparison
equal
deleted
inserted
replaced
18403:bfaee31a83d2 | 18404:1da84a6b136a |
---|---|
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 gen(self, pos, pagelen, limit, nodefunc): | 44 def __init__(self, nodefunc): |
45 """Navigation generation object | |
46 | |
47 :nodefun: factory for a changectx from a revision | |
48 """ | |
49 self.nodefunc = nodefunc | |
50 | |
51 def gen(self, pos, pagelen, limit): | |
45 """computes label and revision id for navigation link | 52 """computes label and revision id for navigation link |
46 | 53 |
47 :pos: is the revision relative to which we generate navigation. | 54 :pos: is the revision relative to which we generate navigation. |
48 :pagelen: the size of each navigation page | 55 :pagelen: the size of each navigation page |
49 :limit: how far shall we link | 56 :limit: how far shall we link |
50 :nodefun: factory for a changectx from a revision | |
51 | 57 |
52 The return is: | 58 The return is: |
53 - a single element tuple | 59 - a single element tuple |
54 - containing a dictionary with a `before` and `after` key | 60 - containing a dictionary with a `before` and `after` key |
55 - values are generator functions taking arbitrary number of kwargs | 61 - values are generator functions taking arbitrary number of kwargs |
61 | 67 |
62 for f in _navseq(1, pagelen): | 68 for f in _navseq(1, pagelen): |
63 if f > limit: | 69 if f > limit: |
64 break | 70 break |
65 if pos + f < limit: | 71 if pos + f < limit: |
66 navafter.append(("+%d" % f, hex(nodefunc(pos + f).node()))) | 72 navafter.append(("+%d" % f, |
73 hex(self.nodefunc(pos + f).node()))) | |
67 if pos - f >= 0: | 74 if pos - f >= 0: |
68 navbefore.insert(0, ("-%d" % f, hex(nodefunc(pos - f).node()))) | 75 navbefore.insert(0, ("-%d" % f, |
76 hex(self.nodefunc(pos - f).node()))) | |
69 | 77 |
70 navafter.append(("tip", "tip")) | 78 navafter.append(("tip", "tip")) |
71 try: | 79 try: |
72 navbefore.insert(0, ("(0)", hex(nodefunc(0).node()))) | 80 navbefore.insert(0, ("(0)", hex(self.nodefunc(0).node()))) |
73 except error.RepoError: | 81 except error.RepoError: |
74 pass | 82 pass |
75 | 83 |
76 data = lambda i: {"label": i[0], "node": i[1]} | 84 data = lambda i: {"label": i[0], "node": i[1]} |
77 return ({'before': lambda **map: (data(i) for i in navbefore), | 85 return ({'before': lambda **map: (data(i) for i in navbefore), |