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