##// END OF EJS Templates
fix bug introduced by 2540521dc7c1 (thanks pychecker)
Benoit Boissinot -
r6413:407dcc0c default
parent child Browse files
Show More
@@ -1,143 +1,143 b''
1 1 # hgweb/webutil.py - utility library for the web interface.
2 2 #
3 3 # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net>
4 4 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
5 5 #
6 6 # This software may be used and distributed according to the terms
7 7 # of the GNU General Public License, incorporated herein by reference.
8 8
9 9 import os
10 10 from mercurial.node import hex, nullid
11 11 from mercurial.repo import RepoError
12 12 from mercurial import util
13 13
14 14 def up(p):
15 15 if p[0] != "/":
16 16 p = "/" + p
17 17 if p[-1] == "/":
18 18 p = p[:-1]
19 19 up = os.path.dirname(p)
20 20 if up == "/":
21 21 return "/"
22 22 return up + "/"
23 23
24 24 def revnavgen(pos, pagelen, limit, nodefunc):
25 25 def seq(factor, limit=None):
26 26 if limit:
27 27 yield limit
28 28 if limit >= 20 and limit <= 40:
29 29 yield 50
30 30 else:
31 31 yield 1 * factor
32 32 yield 3 * factor
33 33 for f in seq(factor * 10):
34 34 yield f
35 35
36 36 def nav(**map):
37 37 l = []
38 38 last = 0
39 39 for f in seq(1, pagelen):
40 40 if f < pagelen or f <= last:
41 41 continue
42 42 if f > limit:
43 43 break
44 44 last = f
45 45 if pos + f < limit:
46 46 l.append(("+%d" % f, hex(nodefunc(pos + f).node())))
47 47 if pos - f >= 0:
48 48 l.insert(0, ("-%d" % f, hex(nodefunc(pos - f).node())))
49 49
50 50 try:
51 51 yield {"label": "(0)", "node": hex(nodefunc('0').node())}
52 52
53 53 for label, node in l:
54 54 yield {"label": label, "node": node}
55 55
56 56 yield {"label": "tip", "node": "tip"}
57 57 except RepoError:
58 58 pass
59 59
60 60 return nav
61 61
62 62 def siblings(siblings=[], hiderev=None, **args):
63 63 siblings = [s for s in siblings if s.node() != nullid]
64 64 if len(siblings) == 1 and siblings[0].rev() == hiderev:
65 65 return
66 66 for s in siblings:
67 67 d = {'node': hex(s.node()), 'rev': s.rev()}
68 68 if hasattr(s, 'path'):
69 69 d['file'] = s.path()
70 70 d.update(args)
71 71 yield d
72 72
73 73 def renamelink(fl, node):
74 74 r = fl.renamed(node)
75 75 if r:
76 76 return [dict(file=r[0], node=hex(r[1]))]
77 77 return []
78 78
79 79 def nodetagsdict(repo, node):
80 80 return [{"name": i} for i in repo.nodetags(node)]
81 81
82 82 def nodebranchdict(repo, ctx):
83 83 branches = []
84 84 branch = ctx.branch()
85 85 # If this is an empty repo, ctx.node() == nullid,
86 86 # ctx.branch() == 'default', but branchtags() is
87 87 # an empty dict. Using dict.get avoids a traceback.
88 88 if repo.branchtags().get(branch) == ctx.node():
89 89 branches.append({"name": branch})
90 90 return branches
91 91
92 92 def nodeinbranch(repo, ctx):
93 93 branches = []
94 94 branch = ctx.branch()
95 95 if branch != 'default' and repo.branchtags().get(branch) != ctx.node():
96 96 branches.append({"name": branch})
97 97 return branches
98 98
99 99 def nodebranchnodefault(ctx):
100 100 branches = []
101 101 branch = ctx.branch()
102 102 if branch != 'default':
103 103 branches.append({"name": branch})
104 104 return branches
105 105
106 106 def showtag(repo, tmpl, t1, node=nullid, **args):
107 107 for t in repo.nodetags(node):
108 108 yield tmpl(t1, tag=t, **args)
109 109
110 110 def cleanpath(repo, path):
111 111 path = path.lstrip('/')
112 112 return util.canonpath(repo.root, '', path)
113 113
114 114 def changectx(repo, req):
115 115 if 'node' in req.form:
116 116 changeid = req.form['node'][0]
117 117 elif 'manifest' in req.form:
118 118 changeid = req.form['manifest'][0]
119 119 else:
120 changeid = self.repo.changelog.count() - 1
120 changeid = repo.changelog.count() - 1
121 121
122 122 try:
123 123 ctx = repo.changectx(changeid)
124 124 except RepoError:
125 125 man = repo.manifest
126 126 mn = man.lookup(changeid)
127 127 ctx = repo.changectx(man.linkrev(mn))
128 128
129 129 return ctx
130 130
131 131 def filectx(repo, req):
132 132 path = cleanpath(repo, req.form['file'][0])
133 133 if 'node' in req.form:
134 134 changeid = req.form['node'][0]
135 135 else:
136 136 changeid = req.form['filenode'][0]
137 137 try:
138 138 ctx = repo.changectx(changeid)
139 139 fctx = ctx.filectx(path)
140 140 except RepoError:
141 141 fctx = repo.filectx(path, fileid=changeid)
142 142
143 143 return fctx
General Comments 0
You need to be logged in to leave comments. Login now