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