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 |