Show More
@@ -1,140 +1,143 | |||||
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 | d['user'] = s.user() | |||
|
69 | d['date'] = s.date() | |||
|
70 | d['description'] = s.description() | |||
68 | if hasattr(s, 'path'): |
|
71 | if hasattr(s, 'path'): | |
69 | d['file'] = s.path() |
|
72 | d['file'] = s.path() | |
70 | d.update(args) |
|
73 | d.update(args) | |
71 | yield d |
|
74 | yield d | |
72 |
|
75 | |||
73 | def renamelink(fctx): |
|
76 | def renamelink(fctx): | |
74 | r = fctx.renamed() |
|
77 | r = fctx.renamed() | |
75 | if r: |
|
78 | if r: | |
76 | return [dict(file=r[0], node=hex(r[1]))] |
|
79 | return [dict(file=r[0], node=hex(r[1]))] | |
77 | return [] |
|
80 | return [] | |
78 |
|
81 | |||
79 | def nodetagsdict(repo, node): |
|
82 | def nodetagsdict(repo, node): | |
80 | return [{"name": i} for i in repo.nodetags(node)] |
|
83 | return [{"name": i} for i in repo.nodetags(node)] | |
81 |
|
84 | |||
82 | def nodebranchdict(repo, ctx): |
|
85 | def nodebranchdict(repo, ctx): | |
83 | branches = [] |
|
86 | branches = [] | |
84 | branch = ctx.branch() |
|
87 | branch = ctx.branch() | |
85 | # If this is an empty repo, ctx.node() == nullid, |
|
88 | # If this is an empty repo, ctx.node() == nullid, | |
86 | # ctx.branch() == 'default', but branchtags() is |
|
89 | # ctx.branch() == 'default', but branchtags() is | |
87 | # an empty dict. Using dict.get avoids a traceback. |
|
90 | # an empty dict. Using dict.get avoids a traceback. | |
88 | if repo.branchtags().get(branch) == ctx.node(): |
|
91 | if repo.branchtags().get(branch) == ctx.node(): | |
89 | branches.append({"name": branch}) |
|
92 | branches.append({"name": branch}) | |
90 | return branches |
|
93 | return branches | |
91 |
|
94 | |||
92 | def nodeinbranch(repo, ctx): |
|
95 | def nodeinbranch(repo, ctx): | |
93 | branches = [] |
|
96 | branches = [] | |
94 | branch = ctx.branch() |
|
97 | branch = ctx.branch() | |
95 | if branch != 'default' and repo.branchtags().get(branch) != ctx.node(): |
|
98 | if branch != 'default' and repo.branchtags().get(branch) != ctx.node(): | |
96 | branches.append({"name": branch}) |
|
99 | branches.append({"name": branch}) | |
97 | return branches |
|
100 | return branches | |
98 |
|
101 | |||
99 | def nodebranchnodefault(ctx): |
|
102 | def nodebranchnodefault(ctx): | |
100 | branches = [] |
|
103 | branches = [] | |
101 | branch = ctx.branch() |
|
104 | branch = ctx.branch() | |
102 | if branch != 'default': |
|
105 | if branch != 'default': | |
103 | branches.append({"name": branch}) |
|
106 | branches.append({"name": branch}) | |
104 | return branches |
|
107 | return branches | |
105 |
|
108 | |||
106 | def showtag(repo, tmpl, t1, node=nullid, **args): |
|
109 | def showtag(repo, tmpl, t1, node=nullid, **args): | |
107 | for t in repo.nodetags(node): |
|
110 | for t in repo.nodetags(node): | |
108 | yield tmpl(t1, tag=t, **args) |
|
111 | yield tmpl(t1, tag=t, **args) | |
109 |
|
112 | |||
110 | def cleanpath(repo, path): |
|
113 | def cleanpath(repo, path): | |
111 | path = path.lstrip('/') |
|
114 | path = path.lstrip('/') | |
112 | return util.canonpath(repo.root, '', path) |
|
115 | return util.canonpath(repo.root, '', path) | |
113 |
|
116 | |||
114 | def changectx(repo, req): |
|
117 | def changectx(repo, req): | |
115 | changeid = "tip" |
|
118 | changeid = "tip" | |
116 | if 'node' in req.form: |
|
119 | if 'node' in req.form: | |
117 | changeid = req.form['node'][0] |
|
120 | changeid = req.form['node'][0] | |
118 | elif 'manifest' in req.form: |
|
121 | elif 'manifest' in req.form: | |
119 | changeid = req.form['manifest'][0] |
|
122 | changeid = req.form['manifest'][0] | |
120 |
|
123 | |||
121 | try: |
|
124 | try: | |
122 | ctx = repo[changeid] |
|
125 | ctx = repo[changeid] | |
123 | except RepoError: |
|
126 | except RepoError: | |
124 | man = repo.manifest |
|
127 | man = repo.manifest | |
125 | ctx = repo[man.linkrev(man.lookup(changeid))] |
|
128 | ctx = repo[man.linkrev(man.lookup(changeid))] | |
126 |
|
129 | |||
127 | return ctx |
|
130 | return ctx | |
128 |
|
131 | |||
129 | def filectx(repo, req): |
|
132 | def filectx(repo, req): | |
130 | path = cleanpath(repo, req.form['file'][0]) |
|
133 | path = cleanpath(repo, req.form['file'][0]) | |
131 | if 'node' in req.form: |
|
134 | if 'node' in req.form: | |
132 | changeid = req.form['node'][0] |
|
135 | changeid = req.form['node'][0] | |
133 | else: |
|
136 | else: | |
134 | changeid = req.form['filenode'][0] |
|
137 | changeid = req.form['filenode'][0] | |
135 | try: |
|
138 | try: | |
136 | fctx = repo[changeid][path] |
|
139 | fctx = repo[changeid][path] | |
137 | except RepoError: |
|
140 | except RepoError: | |
138 | fctx = repo.filectx(path, fileid=changeid) |
|
141 | fctx = repo.filectx(path, fileid=changeid) | |
139 |
|
142 | |||
140 | return fctx |
|
143 | return fctx |
General Comments 0
You need to be logged in to leave comments.
Login now