##// END OF EJS Templates
hgweb: move revnavgen into an object...
Pierre-Yves David -
r18403:bfaee31a default
parent child Browse files
Show More
@@ -242,7 +242,7 b' def changelog(web, req, tmpl, shortlog=F'
242 pos = end - 1
242 pos = end - 1
243 parity = paritygen(web.stripecount, offset=start - end)
243 parity = paritygen(web.stripecount, offset=start - end)
244
244
245 changenav = webutil.revnavgen(pos, revcount, count, web.repo.changectx)
245 changenav = webutil.revnav().gen(pos, revcount, count, web.repo.changectx)
246
246
247 return tmpl(shortlog and 'shortlog' or 'changelog', changenav=changenav,
247 return tmpl(shortlog and 'shortlog' or 'changelog', changenav=changenav,
248 node=ctx.hex(), rev=pos, changesets=count,
248 node=ctx.hex(), rev=pos, changesets=count,
@@ -772,7 +772,7 b' def filelog(web, req, tmpl):'
772 yield e
772 yield e
773
773
774 nodefunc = lambda x: fctx.filectx(fileid=x)
774 nodefunc = lambda x: fctx.filectx(fileid=x)
775 nav = webutil.revnavgen(end - 1, revcount, count, nodefunc)
775 nav = webutil.revnav().gen(end - 1, revcount, count, nodefunc)
776 return tmpl("filelog", file=f, node=fctx.hex(), nav=nav,
776 return tmpl("filelog", file=f, node=fctx.hex(), nav=nav,
777 entries=lambda **x: entries(latestonly=False, **x),
777 entries=lambda **x: entries(latestonly=False, **x),
778 latestentry=lambda **x: entries(latestonly=True, **x),
778 latestentry=lambda **x: entries(latestonly=True, **x),
@@ -851,7 +851,7 b' def graph(web, req, tmpl):'
851
851
852 uprev = min(max(0, count - 1), rev + revcount)
852 uprev = min(max(0, count - 1), rev + revcount)
853 downrev = max(0, rev - revcount)
853 downrev = max(0, rev - revcount)
854 changenav = webutil.revnavgen(pos, revcount, count, web.repo.changectx)
854 changenav = webutil.revnav().gen(pos, revcount, count, web.repo.changectx)
855
855
856 dag = graphmod.dagwalker(web.repo, range(start, end)[::-1])
856 dag = graphmod.dagwalker(web.repo, range(start, end)[::-1])
857 tree = list(graphmod.colored(dag, web.repo))
857 tree = list(graphmod.colored(dag, web.repo))
@@ -39,41 +39,43 b' def _navseq(step, firststep=None):'
39 yield 3 * step
39 yield 3 * step
40 step *= 10
40 step *= 10
41
41
42 def revnavgen(pos, pagelen, limit, nodefunc):
42 class revnav(object):
43 """computes label and revision id for navigation link
44
43
45 :pos: is the revision relative to which we generate navigation.
44 def gen(self, pos, pagelen, limit, nodefunc):
46 :pagelen: the size of each navigation page
45 """computes label and revision id for navigation link
47 :limit: how far shall we link
48 :nodefun: factory for a changectx from a revision
49
46
50 The return is:
47 :pos: is the revision relative to which we generate navigation.
51 - a single element tuple
48 :pagelen: the size of each navigation page
52 - containing a dictionary with a `before` and `after` key
49 :limit: how far shall we link
53 - values are generator functions taking an arbitrary number of kwargs
50 :nodefun: factory for a changectx from a revision
54 - yield items are dictionaries with `label` and `node` keys
55 """
56
51
57 navbefore = []
52 The return is:
58 navafter = []
53 - a single element tuple
54 - containing a dictionary with a `before` and `after` key
55 - values are generator functions taking arbitrary number of kwargs
56 - yield items are dictionaries with `label` and `node` keys
57 """
59
58
60 for f in _navseq(1, pagelen):
59 navbefore = []
61 if f > limit:
60 navafter = []
62 break
63 if pos + f < limit:
64 navafter.append(("+%d" % f, hex(nodefunc(pos + f).node())))
65 if pos - f >= 0:
66 navbefore.insert(0, ("-%d" % f, hex(nodefunc(pos - f).node())))
67
61
68 navafter.append(("tip", "tip"))
62 for f in _navseq(1, pagelen):
69 try:
63 if f > limit:
70 navbefore.insert(0, ("(0)", hex(nodefunc(0).node())))
64 break
71 except error.RepoError:
65 if pos + f < limit:
72 pass
66 navafter.append(("+%d" % f, hex(nodefunc(pos + f).node())))
67 if pos - f >= 0:
68 navbefore.insert(0, ("-%d" % f, hex(nodefunc(pos - f).node())))
73
69
74 data = lambda i: {"label": i[0], "node": i[1]}
70 navafter.append(("tip", "tip"))
75 return ({'before': lambda **map: (data(i) for i in navbefore),
71 try:
76 'after': lambda **map: (data(i) for i in navafter)},)
72 navbefore.insert(0, ("(0)", hex(nodefunc(0).node())))
73 except error.RepoError:
74 pass
75
76 data = lambda i: {"label": i[0], "node": i[1]}
77 return ({'before': lambda **map: (data(i) for i in navbefore),
78 'after': lambda **map: (data(i) for i in navafter)},)
77
79
78 def _siblings(siblings=[], hiderev=None):
80 def _siblings(siblings=[], hiderev=None):
79 siblings = [s for s in siblings if s.node() != nullid]
81 siblings = [s for s in siblings if s.node() != nullid]
General Comments 0
You need to be logged in to leave comments. Login now