Show More
@@ -1,987 +1,976 | |||
|
1 | 1 | # hgweb.py - web interface to a mercurial repository |
|
2 | 2 | # |
|
3 | 3 | # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
|
4 | 4 | # Copyright 2005 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, cgi, time, re, difflib, socket, sys, zlib |
|
10 | 10 | from mercurial.hg import * |
|
11 | 11 | from mercurial.ui import * |
|
12 | 12 | |
|
13 | 13 | def templatepath(): |
|
14 | 14 | for f in "templates", "../templates": |
|
15 | 15 | p = os.path.join(os.path.dirname(__file__), f) |
|
16 | 16 | if os.path.isdir(p): |
|
17 | 17 | return p |
|
18 | 18 | |
|
19 | 19 | def age(t): |
|
20 | 20 | def plural(t, c): |
|
21 | 21 | if c == 1: |
|
22 | 22 | return t |
|
23 | 23 | return t + "s" |
|
24 | 24 | def fmt(t, c): |
|
25 | 25 | return "%d %s" % (c, plural(t, c)) |
|
26 | 26 | |
|
27 | 27 | now = time.time() |
|
28 | 28 | delta = max(1, int(now - t)) |
|
29 | 29 | |
|
30 | 30 | scales = [["second", 1], |
|
31 | 31 | ["minute", 60], |
|
32 | 32 | ["hour", 3600], |
|
33 | 33 | ["day", 3600 * 24], |
|
34 | 34 | ["week", 3600 * 24 * 7], |
|
35 | 35 | ["month", 3600 * 24 * 30], |
|
36 | 36 | ["year", 3600 * 24 * 365]] |
|
37 | 37 | |
|
38 | 38 | scales.reverse() |
|
39 | 39 | |
|
40 | 40 | for t, s in scales: |
|
41 | 41 | n = delta / s |
|
42 | 42 | if n >= 2 or s == 1: |
|
43 | 43 | return fmt(t, n) |
|
44 | 44 | |
|
45 | 45 | def nl2br(text): |
|
46 | 46 | return text.replace('\n', '<br/>\n') |
|
47 | 47 | |
|
48 | 48 | def obfuscate(text): |
|
49 | 49 | return ''.join(['&#%d;' % ord(c) for c in text]) |
|
50 | 50 | |
|
51 | 51 | def up(p): |
|
52 | 52 | if p[0] != "/": |
|
53 | 53 | p = "/" + p |
|
54 | 54 | if p[-1] == "/": |
|
55 | 55 | p = p[:-1] |
|
56 | 56 | up = os.path.dirname(p) |
|
57 | 57 | if up == "/": |
|
58 | 58 | return "/" |
|
59 | 59 | return up + "/" |
|
60 | 60 | |
|
61 | 61 | def httphdr(type, file="", size=0): |
|
62 | 62 | sys.stdout.write('Content-type: %s\n' % type) |
|
63 | 63 | if file: |
|
64 | 64 | sys.stdout.write('Content-disposition: attachment; filename=%s\n' |
|
65 | 65 | % file) |
|
66 | 66 | if size > 0: |
|
67 | 67 | sys.stdout.write('Content-length: %d\n' % size) |
|
68 | 68 | sys.stdout.write('\n') |
|
69 | 69 | |
|
70 | 70 | def write(*things): |
|
71 | 71 | for thing in things: |
|
72 | 72 | if hasattr(thing, "__iter__"): |
|
73 | 73 | for part in thing: |
|
74 | 74 | write(part) |
|
75 | 75 | else: |
|
76 | 76 | sys.stdout.write(str(thing)) |
|
77 | 77 | |
|
78 | 78 | class templater: |
|
79 | 79 | def __init__(self, mapfile, filters={}, defaults={}): |
|
80 | 80 | self.cache = {} |
|
81 | 81 | self.map = {} |
|
82 | 82 | self.base = os.path.dirname(mapfile) |
|
83 | 83 | self.filters = filters |
|
84 | 84 | self.defaults = defaults |
|
85 | 85 | |
|
86 | 86 | for l in file(mapfile): |
|
87 | 87 | m = re.match(r'(\S+)\s*=\s*"(.*)"$', l) |
|
88 | 88 | if m: |
|
89 | 89 | self.cache[m.group(1)] = m.group(2) |
|
90 | 90 | else: |
|
91 | 91 | m = re.match(r'(\S+)\s*=\s*(\S+)', l) |
|
92 | 92 | if m: |
|
93 | 93 | self.map[m.group(1)] = os.path.join(self.base, m.group(2)) |
|
94 | 94 | else: |
|
95 | 95 | raise LookupError("unknown map entry '%s'" % l) |
|
96 | 96 | |
|
97 | 97 | def __call__(self, t, **map): |
|
98 | 98 | m = self.defaults.copy() |
|
99 | 99 | m.update(map) |
|
100 | 100 | try: |
|
101 | 101 | tmpl = self.cache[t] |
|
102 | 102 | except KeyError: |
|
103 | 103 | tmpl = self.cache[t] = file(self.map[t]).read() |
|
104 | 104 | return self.template(tmpl, self.filters, **m) |
|
105 | 105 | |
|
106 | 106 | def template(self, tmpl, filters={}, **map): |
|
107 | 107 | while tmpl: |
|
108 | 108 | m = re.search(r"#([a-zA-Z0-9]+)((%[a-zA-Z0-9]+)*)((\|[a-zA-Z0-9]+)*)#", tmpl) |
|
109 | 109 | if m: |
|
110 | 110 | yield tmpl[:m.start(0)] |
|
111 | 111 | v = map.get(m.group(1), "") |
|
112 | 112 | v = callable(v) and v(**map) or v |
|
113 | 113 | |
|
114 | 114 | format = m.group(2) |
|
115 | 115 | fl = m.group(4) |
|
116 | 116 | |
|
117 | 117 | if format: |
|
118 | 118 | q = v.__iter__ |
|
119 | 119 | for i in q(): |
|
120 | 120 | lm = map.copy() |
|
121 | 121 | lm.update(i) |
|
122 | 122 | yield self(format[1:], **lm) |
|
123 | 123 | |
|
124 | 124 | v = "" |
|
125 | 125 | |
|
126 | 126 | elif fl: |
|
127 | 127 | for f in fl.split("|")[1:]: |
|
128 | 128 | v = filters[f](v) |
|
129 | 129 | |
|
130 | 130 | yield v |
|
131 | 131 | tmpl = tmpl[m.end(0):] |
|
132 | 132 | else: |
|
133 | 133 | yield tmpl |
|
134 | 134 | return |
|
135 | 135 | |
|
136 | 136 | def rfc822date(x): |
|
137 | 137 | return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(x)) |
|
138 | 138 | |
|
139 | 139 | common_filters = { |
|
140 | 140 | "escape": cgi.escape, |
|
141 | 141 | "age": age, |
|
142 | 142 | "date": (lambda x: time.asctime(time.gmtime(x))), |
|
143 | 143 | "addbreaks": nl2br, |
|
144 | 144 | "obfuscate": obfuscate, |
|
145 | 145 | "short": (lambda x: x[:12]), |
|
146 | 146 | "firstline": (lambda x: x.splitlines(1)[0]), |
|
147 | 147 | "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--"), |
|
148 | 148 | "rfc822date": rfc822date, |
|
149 | 149 | } |
|
150 | 150 | |
|
151 | 151 | class hgweb: |
|
152 | 152 | def __init__(self, repo, name=None): |
|
153 | 153 | if type(repo) == type(""): |
|
154 | 154 | self.repo = repository(ui(), repo) |
|
155 | 155 | else: |
|
156 | 156 | self.repo = repo |
|
157 | 157 | |
|
158 | 158 | self.mtime = -1 |
|
159 | 159 | self.reponame = name or self.repo.ui.config("web", "name", |
|
160 | 160 | self.repo.root) |
|
161 |
self. |
|
|
161 | self.archives = 'zip', 'gz', 'bz2' | |
|
162 | 162 | |
|
163 | 163 | def refresh(self): |
|
164 | 164 | s = os.stat(os.path.join(self.repo.root, ".hg", "00changelog.i")) |
|
165 | 165 | if s.st_mtime != self.mtime: |
|
166 | 166 | self.mtime = s.st_mtime |
|
167 | 167 | self.repo = repository(self.repo.ui, self.repo.root) |
|
168 | 168 | self.maxchanges = self.repo.ui.config("web", "maxchanges", 10) |
|
169 | 169 | self.maxfiles = self.repo.ui.config("web", "maxchanges", 10) |
|
170 | 170 | self.allowpull = self.repo.ui.configbool("web", "allowpull", True) |
|
171 | self.allowedtarballs = [] | |
|
172 | for i in self.supportedtarballs: | |
|
173 | if self.repo.ui.configbool("web", i, True): | |
|
174 | self.allowedtarballs.append(i) | |
|
175 | 171 | |
|
176 | 172 | def date(self, cs): |
|
177 | 173 | return time.asctime(time.gmtime(float(cs[2].split(' ')[0]))) |
|
178 | 174 | |
|
179 | 175 | def listfiles(self, files, mf): |
|
180 | 176 | for f in files[:self.maxfiles]: |
|
181 | 177 | yield self.t("filenodelink", node=hex(mf[f]), file=f) |
|
182 | 178 | if len(files) > self.maxfiles: |
|
183 | 179 | yield self.t("fileellipses") |
|
184 | 180 | |
|
185 | 181 | def listfilediffs(self, files, changeset): |
|
186 | 182 | for f in files[:self.maxfiles]: |
|
187 | 183 | yield self.t("filedifflink", node=hex(changeset), file=f) |
|
188 | 184 | if len(files) > self.maxfiles: |
|
189 | 185 | yield self.t("fileellipses") |
|
190 | 186 | |
|
191 | 187 | def parents(self, t1, nodes=[], rev=None,**args): |
|
192 | 188 | if not rev: |
|
193 | 189 | rev = lambda x: "" |
|
194 | 190 | for node in nodes: |
|
195 | 191 | if node != nullid: |
|
196 | 192 | yield self.t(t1, node=hex(node), rev=rev(node), **args) |
|
197 | 193 | |
|
198 | 194 | def showtag(self, t1, node=nullid, **args): |
|
199 | 195 | for t in self.repo.nodetags(node): |
|
200 | 196 | yield self.t(t1, tag=t, **args) |
|
201 | 197 | |
|
202 | 198 | def diff(self, node1, node2, files): |
|
203 | 199 | def filterfiles(list, files): |
|
204 | 200 | l = [x for x in list if x in files] |
|
205 | 201 | |
|
206 | 202 | for f in files: |
|
207 | 203 | if f[-1] != os.sep: |
|
208 | 204 | f += os.sep |
|
209 | 205 | l += [x for x in list if x.startswith(f)] |
|
210 | 206 | return l |
|
211 | 207 | |
|
212 | 208 | parity = [0] |
|
213 | 209 | def diffblock(diff, f, fn): |
|
214 | 210 | yield self.t("diffblock", |
|
215 | 211 | lines=prettyprintlines(diff), |
|
216 | 212 | parity=parity[0], |
|
217 | 213 | file=f, |
|
218 | 214 | filenode=hex(fn or nullid)) |
|
219 | 215 | parity[0] = 1 - parity[0] |
|
220 | 216 | |
|
221 | 217 | def prettyprintlines(diff): |
|
222 | 218 | for l in diff.splitlines(1): |
|
223 | 219 | if l.startswith('+'): |
|
224 | 220 | yield self.t("difflineplus", line=l) |
|
225 | 221 | elif l.startswith('-'): |
|
226 | 222 | yield self.t("difflineminus", line=l) |
|
227 | 223 | elif l.startswith('@'): |
|
228 | 224 | yield self.t("difflineat", line=l) |
|
229 | 225 | else: |
|
230 | 226 | yield self.t("diffline", line=l) |
|
231 | 227 | |
|
232 | 228 | r = self.repo |
|
233 | 229 | cl = r.changelog |
|
234 | 230 | mf = r.manifest |
|
235 | 231 | change1 = cl.read(node1) |
|
236 | 232 | change2 = cl.read(node2) |
|
237 | 233 | mmap1 = mf.read(change1[0]) |
|
238 | 234 | mmap2 = mf.read(change2[0]) |
|
239 | 235 | date1 = self.date(change1) |
|
240 | 236 | date2 = self.date(change2) |
|
241 | 237 | |
|
242 | 238 | c, a, d, u = r.changes(node1, node2) |
|
243 | 239 | if files: |
|
244 | 240 | c, a, d = map(lambda x: filterfiles(x, files), (c, a, d)) |
|
245 | 241 | |
|
246 | 242 | for f in c: |
|
247 | 243 | to = r.file(f).read(mmap1[f]) |
|
248 | 244 | tn = r.file(f).read(mmap2[f]) |
|
249 | 245 | yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn) |
|
250 | 246 | for f in a: |
|
251 | 247 | to = None |
|
252 | 248 | tn = r.file(f).read(mmap2[f]) |
|
253 | 249 | yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn) |
|
254 | 250 | for f in d: |
|
255 | 251 | to = r.file(f).read(mmap1[f]) |
|
256 | 252 | tn = None |
|
257 | 253 | yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn) |
|
258 | 254 | |
|
259 | 255 | def changelog(self, pos): |
|
260 | 256 | def changenav(**map): |
|
261 | 257 | def seq(factor=1): |
|
262 | 258 | yield 1 * factor |
|
263 | 259 | yield 3 * factor |
|
264 | 260 | #yield 5 * factor |
|
265 | 261 | for f in seq(factor * 10): |
|
266 | 262 | yield f |
|
267 | 263 | |
|
268 | 264 | l = [] |
|
269 | 265 | for f in seq(): |
|
270 | 266 | if f < self.maxchanges / 2: |
|
271 | 267 | continue |
|
272 | 268 | if f > count: |
|
273 | 269 | break |
|
274 | 270 | r = "%d" % f |
|
275 | 271 | if pos + f < count: |
|
276 | 272 | l.append(("+" + r, pos + f)) |
|
277 | 273 | if pos - f >= 0: |
|
278 | 274 | l.insert(0, ("-" + r, pos - f)) |
|
279 | 275 | |
|
280 | 276 | yield {"rev": 0, "label": "(0)"} |
|
281 | 277 | |
|
282 | 278 | for label, rev in l: |
|
283 | 279 | yield {"label": label, "rev": rev} |
|
284 | 280 | |
|
285 | 281 | yield {"label": "tip", "rev": ""} |
|
286 | 282 | |
|
287 | 283 | def changelist(**map): |
|
288 | 284 | parity = (start - end) & 1 |
|
289 | 285 | cl = self.repo.changelog |
|
290 | 286 | l = [] # build a list in forward order for efficiency |
|
291 | 287 | for i in range(start, end): |
|
292 | 288 | n = cl.node(i) |
|
293 | 289 | changes = cl.read(n) |
|
294 | 290 | hn = hex(n) |
|
295 | 291 | t = float(changes[2].split(' ')[0]) |
|
296 | 292 | |
|
297 | 293 | l.insert(0, {"parity": parity, |
|
298 | 294 | "author": changes[1], |
|
299 | 295 | "parent": self.parents("changelogparent", |
|
300 | 296 | cl.parents(n), cl.rev), |
|
301 | 297 | "changelogtag": self.showtag("changelogtag",n), |
|
302 | 298 | "manifest": hex(changes[0]), |
|
303 | 299 | "desc": changes[4], |
|
304 | 300 | "date": t, |
|
305 | 301 | "files": self.listfilediffs(changes[3], n), |
|
306 | 302 | "rev": i, |
|
307 | 303 | "node": hn}) |
|
308 | 304 | parity = 1 - parity |
|
309 | 305 | |
|
310 | 306 | for e in l: |
|
311 | 307 | yield e |
|
312 | 308 | |
|
313 | 309 | cl = self.repo.changelog |
|
314 | 310 | mf = cl.read(cl.tip())[0] |
|
315 | 311 | count = cl.count() |
|
316 | 312 | start = max(0, pos - self.maxchanges + 1) |
|
317 | 313 | end = min(count, start + self.maxchanges) |
|
318 | 314 | pos = end - 1 |
|
319 | 315 | |
|
320 | 316 | yield self.t('changelog', |
|
321 | 317 | changenav=changenav, |
|
322 | 318 | manifest=hex(mf), |
|
323 | 319 | rev=pos, changesets=count, entries=changelist) |
|
324 | 320 | |
|
325 | 321 | def search(self, query): |
|
326 | 322 | |
|
327 | 323 | def changelist(**map): |
|
328 | 324 | cl = self.repo.changelog |
|
329 | 325 | count = 0 |
|
330 | 326 | qw = query.lower().split() |
|
331 | 327 | |
|
332 | 328 | def revgen(): |
|
333 | 329 | for i in range(cl.count() - 1, 0, -100): |
|
334 | 330 | l = [] |
|
335 | 331 | for j in range(max(0, i - 100), i): |
|
336 | 332 | n = cl.node(j) |
|
337 | 333 | changes = cl.read(n) |
|
338 | 334 | l.append((n, j, changes)) |
|
339 | 335 | l.reverse() |
|
340 | 336 | for e in l: |
|
341 | 337 | yield e |
|
342 | 338 | |
|
343 | 339 | for n, i, changes in revgen(): |
|
344 | 340 | miss = 0 |
|
345 | 341 | for q in qw: |
|
346 | 342 | if not (q in changes[1].lower() or |
|
347 | 343 | q in changes[4].lower() or |
|
348 | 344 | q in " ".join(changes[3][:20]).lower()): |
|
349 | 345 | miss = 1 |
|
350 | 346 | break |
|
351 | 347 | if miss: |
|
352 | 348 | continue |
|
353 | 349 | |
|
354 | 350 | count += 1 |
|
355 | 351 | hn = hex(n) |
|
356 | 352 | t = float(changes[2].split(' ')[0]) |
|
357 | 353 | |
|
358 | 354 | yield self.t('searchentry', |
|
359 | 355 | parity=count & 1, |
|
360 | 356 | author=changes[1], |
|
361 | 357 | parent=self.parents("changelogparent", |
|
362 | 358 | cl.parents(n), cl.rev), |
|
363 | 359 | changelogtag=self.showtag("changelogtag",n), |
|
364 | 360 | manifest=hex(changes[0]), |
|
365 | 361 | desc=changes[4], |
|
366 | 362 | date=t, |
|
367 | 363 | files=self.listfilediffs(changes[3], n), |
|
368 | 364 | rev=i, |
|
369 | 365 | node=hn) |
|
370 | 366 | |
|
371 | 367 | if count >= self.maxchanges: |
|
372 | 368 | break |
|
373 | 369 | |
|
374 | 370 | cl = self.repo.changelog |
|
375 | 371 | mf = cl.read(cl.tip())[0] |
|
376 | 372 | |
|
377 | 373 | yield self.t('search', |
|
378 | 374 | query=query, |
|
379 | 375 | manifest=hex(mf), |
|
380 | 376 | entries=changelist) |
|
381 | 377 | |
|
382 | 378 | def changeset(self, nodeid): |
|
383 | 379 | n = bin(nodeid) |
|
384 | 380 | cl = self.repo.changelog |
|
385 | 381 | changes = cl.read(n) |
|
386 | 382 | p1 = cl.parents(n)[0] |
|
387 | 383 | t = float(changes[2].split(' ')[0]) |
|
388 | 384 | |
|
389 | 385 | files = [] |
|
390 | 386 | mf = self.repo.manifest.read(changes[0]) |
|
391 | 387 | for f in changes[3]: |
|
392 | 388 | files.append(self.t("filenodelink", |
|
393 | 389 | filenode=hex(mf.get(f, nullid)), file=f)) |
|
394 | 390 | |
|
395 | 391 | def diff(**map): |
|
396 | 392 | yield self.diff(p1, n, None) |
|
397 | 393 | |
|
398 |
def |
|
|
399 |
for i in self.a |
|
|
400 | yield {"type" : i, | |
|
401 | "manifest" : hex(changes[0])} | |
|
394 | def archivelist(): | |
|
395 | for i in self.archives: | |
|
396 | if self.repo.ui.configbool("web", "allow" + i, False): | |
|
397 | yield {"type" : i, "node" : nodeid} | |
|
402 | 398 | |
|
403 | 399 | yield self.t('changeset', |
|
404 | 400 | diff=diff, |
|
405 | 401 | rev=cl.rev(n), |
|
406 | 402 | node=nodeid, |
|
407 | 403 | parent=self.parents("changesetparent", |
|
408 | 404 | cl.parents(n), cl.rev), |
|
409 | 405 | changesettag=self.showtag("changesettag",n), |
|
410 | 406 | manifest=hex(changes[0]), |
|
411 | 407 | author=changes[1], |
|
412 | 408 | desc=changes[4], |
|
413 | 409 | date=t, |
|
414 | 410 | files=files, |
|
415 |
|
|
|
411 | archives=archivelist()) | |
|
416 | 412 | |
|
417 | 413 | def filelog(self, f, filenode): |
|
418 | 414 | cl = self.repo.changelog |
|
419 | 415 | fl = self.repo.file(f) |
|
420 | 416 | count = fl.count() |
|
421 | 417 | |
|
422 | 418 | def entries(**map): |
|
423 | 419 | l = [] |
|
424 | 420 | parity = (count - 1) & 1 |
|
425 | 421 | |
|
426 | 422 | for i in range(count): |
|
427 | 423 | n = fl.node(i) |
|
428 | 424 | lr = fl.linkrev(n) |
|
429 | 425 | cn = cl.node(lr) |
|
430 | 426 | cs = cl.read(cl.node(lr)) |
|
431 | 427 | t = float(cs[2].split(' ')[0]) |
|
432 | 428 | |
|
433 | 429 | l.insert(0, {"parity": parity, |
|
434 | 430 | "filenode": hex(n), |
|
435 | 431 | "filerev": i, |
|
436 | 432 | "file": f, |
|
437 | 433 | "node": hex(cn), |
|
438 | 434 | "author": cs[1], |
|
439 | 435 | "date": t, |
|
440 | 436 | "parent": self.parents("filelogparent", |
|
441 | 437 | fl.parents(n), |
|
442 | 438 | fl.rev, file=f), |
|
443 | 439 | "desc": cs[4]}) |
|
444 | 440 | parity = 1 - parity |
|
445 | 441 | |
|
446 | 442 | for e in l: |
|
447 | 443 | yield e |
|
448 | 444 | |
|
449 | 445 | yield self.t("filelog", file=f, filenode=filenode, entries=entries) |
|
450 | 446 | |
|
451 | 447 | def filerevision(self, f, node): |
|
452 | 448 | fl = self.repo.file(f) |
|
453 | 449 | n = bin(node) |
|
454 | 450 | text = fl.read(n) |
|
455 | 451 | changerev = fl.linkrev(n) |
|
456 | 452 | cl = self.repo.changelog |
|
457 | 453 | cn = cl.node(changerev) |
|
458 | 454 | cs = cl.read(cn) |
|
459 | 455 | t = float(cs[2].split(' ')[0]) |
|
460 | 456 | mfn = cs[0] |
|
461 | 457 | |
|
462 | 458 | def lines(): |
|
463 | 459 | for l, t in enumerate(text.splitlines(1)): |
|
464 | 460 | yield {"line": t, |
|
465 | 461 | "linenumber": "% 6d" % (l + 1), |
|
466 | 462 | "parity": l & 1} |
|
467 | 463 | |
|
468 | 464 | yield self.t("filerevision", |
|
469 | 465 | file=f, |
|
470 | 466 | filenode=node, |
|
471 | 467 | path=up(f), |
|
472 | 468 | text=lines(), |
|
473 | 469 | rev=changerev, |
|
474 | 470 | node=hex(cn), |
|
475 | 471 | manifest=hex(mfn), |
|
476 | 472 | author=cs[1], |
|
477 | 473 | date=t, |
|
478 | 474 | parent=self.parents("filerevparent", |
|
479 | 475 | fl.parents(n), fl.rev, file=f), |
|
480 | 476 | permissions=self.repo.manifest.readflags(mfn)[f]) |
|
481 | 477 | |
|
482 | 478 | def fileannotate(self, f, node): |
|
483 | 479 | bcache = {} |
|
484 | 480 | ncache = {} |
|
485 | 481 | fl = self.repo.file(f) |
|
486 | 482 | n = bin(node) |
|
487 | 483 | changerev = fl.linkrev(n) |
|
488 | 484 | |
|
489 | 485 | cl = self.repo.changelog |
|
490 | 486 | cn = cl.node(changerev) |
|
491 | 487 | cs = cl.read(cn) |
|
492 | 488 | t = float(cs[2].split(' ')[0]) |
|
493 | 489 | mfn = cs[0] |
|
494 | 490 | |
|
495 | 491 | def annotate(**map): |
|
496 | 492 | parity = 1 |
|
497 | 493 | last = None |
|
498 | 494 | for r, l in fl.annotate(n): |
|
499 | 495 | try: |
|
500 | 496 | cnode = ncache[r] |
|
501 | 497 | except KeyError: |
|
502 | 498 | cnode = ncache[r] = self.repo.changelog.node(r) |
|
503 | 499 | |
|
504 | 500 | try: |
|
505 | 501 | name = bcache[r] |
|
506 | 502 | except KeyError: |
|
507 | 503 | cl = self.repo.changelog.read(cnode) |
|
508 | 504 | name = cl[1] |
|
509 | 505 | f = name.find('@') |
|
510 | 506 | if f >= 0: |
|
511 | 507 | name = name[:f] |
|
512 | 508 | f = name.find('<') |
|
513 | 509 | if f >= 0: |
|
514 | 510 | name = name[f+1:] |
|
515 | 511 | bcache[r] = name |
|
516 | 512 | |
|
517 | 513 | if last != cnode: |
|
518 | 514 | parity = 1 - parity |
|
519 | 515 | last = cnode |
|
520 | 516 | |
|
521 | 517 | yield {"parity": parity, |
|
522 | 518 | "node": hex(cnode), |
|
523 | 519 | "rev": r, |
|
524 | 520 | "author": name, |
|
525 | 521 | "file": f, |
|
526 | 522 | "line": l} |
|
527 | 523 | |
|
528 | 524 | yield self.t("fileannotate", |
|
529 | 525 | file=f, |
|
530 | 526 | filenode=node, |
|
531 | 527 | annotate=annotate, |
|
532 | 528 | path=up(f), |
|
533 | 529 | rev=changerev, |
|
534 | 530 | node=hex(cn), |
|
535 | 531 | manifest=hex(mfn), |
|
536 | 532 | author=cs[1], |
|
537 | 533 | date=t, |
|
538 | 534 | parent=self.parents("fileannotateparent", |
|
539 | 535 | fl.parents(n), fl.rev, file=f), |
|
540 | 536 | permissions=self.repo.manifest.readflags(mfn)[f]) |
|
541 | 537 | |
|
542 | 538 | def manifest(self, mnode, path): |
|
543 | 539 | mf = self.repo.manifest.read(bin(mnode)) |
|
544 | 540 | rev = self.repo.manifest.rev(bin(mnode)) |
|
545 | 541 | node = self.repo.changelog.node(rev) |
|
546 | 542 | mff=self.repo.manifest.readflags(bin(mnode)) |
|
547 | 543 | |
|
548 | 544 | files = {} |
|
549 | 545 | |
|
550 | 546 | p = path[1:] |
|
551 | 547 | l = len(p) |
|
552 | 548 | |
|
553 | 549 | for f,n in mf.items(): |
|
554 | 550 | if f[:l] != p: |
|
555 | 551 | continue |
|
556 | 552 | remain = f[l:] |
|
557 | 553 | if "/" in remain: |
|
558 | 554 | short = remain[:remain.find("/") + 1] # bleah |
|
559 | 555 | files[short] = (f, None) |
|
560 | 556 | else: |
|
561 | 557 | short = os.path.basename(remain) |
|
562 | 558 | files[short] = (f, n) |
|
563 | 559 | |
|
564 | 560 | def filelist(**map): |
|
565 | 561 | parity = 0 |
|
566 | 562 | fl = files.keys() |
|
567 | 563 | fl.sort() |
|
568 | 564 | for f in fl: |
|
569 | 565 | full, fnode = files[f] |
|
570 | 566 | if not fnode: |
|
571 | 567 | continue |
|
572 | 568 | |
|
573 | 569 | yield {"file": full, |
|
574 | 570 | "manifest": mnode, |
|
575 | 571 | "filenode": hex(fnode), |
|
576 | 572 | "parity": parity, |
|
577 | 573 | "basename": f, |
|
578 | 574 | "permissions": mff[full]} |
|
579 | 575 | parity = 1 - parity |
|
580 | 576 | |
|
581 | 577 | def dirlist(**map): |
|
582 | 578 | parity = 0 |
|
583 | 579 | fl = files.keys() |
|
584 | 580 | fl.sort() |
|
585 | 581 | for f in fl: |
|
586 | 582 | full, fnode = files[f] |
|
587 | 583 | if fnode: |
|
588 | 584 | continue |
|
589 | 585 | |
|
590 | 586 | yield {"parity": parity, |
|
591 | 587 | "path": os.path.join(path, f), |
|
592 | 588 | "manifest": mnode, |
|
593 | 589 | "basename": f[:-1]} |
|
594 | 590 | parity = 1 - parity |
|
595 | 591 | |
|
596 | 592 | yield self.t("manifest", |
|
597 | 593 | manifest=mnode, |
|
598 | 594 | rev=rev, |
|
599 | 595 | node=hex(node), |
|
600 | 596 | path=path, |
|
601 | 597 | up=up(path), |
|
602 | 598 | fentries=filelist, |
|
603 | 599 | dentries=dirlist) |
|
604 | 600 | |
|
605 | 601 | def tags(self): |
|
606 | 602 | cl = self.repo.changelog |
|
607 | 603 | mf = cl.read(cl.tip())[0] |
|
608 | 604 | |
|
609 | 605 | i = self.repo.tagslist() |
|
610 | 606 | i.reverse() |
|
611 | 607 | |
|
612 | 608 | def entries(**map): |
|
613 | 609 | parity = 0 |
|
614 | 610 | for k,n in i: |
|
615 | 611 | yield {"parity": parity, |
|
616 | 612 | "tag": k, |
|
617 | 613 | "node": hex(n)} |
|
618 | 614 | parity = 1 - parity |
|
619 | 615 | |
|
620 | 616 | yield self.t("tags", |
|
621 | 617 | manifest=hex(mf), |
|
622 | 618 | entries=entries) |
|
623 | 619 | |
|
624 | 620 | def filediff(self, file, changeset): |
|
625 | 621 | n = bin(changeset) |
|
626 | 622 | cl = self.repo.changelog |
|
627 | 623 | p1 = cl.parents(n)[0] |
|
628 | 624 | cs = cl.read(n) |
|
629 | 625 | mf = self.repo.manifest.read(cs[0]) |
|
630 | 626 | |
|
631 | 627 | def diff(**map): |
|
632 | 628 | yield self.diff(p1, n, file) |
|
633 | 629 | |
|
634 | 630 | yield self.t("filediff", |
|
635 | 631 | file=file, |
|
636 | 632 | filenode=hex(mf.get(file, nullid)), |
|
637 | 633 | node=changeset, |
|
638 | 634 | rev=self.repo.changelog.rev(n), |
|
639 | 635 | parent=self.parents("filediffparent", |
|
640 | 636 | cl.parents(n), cl.rev), |
|
641 | 637 | diff=diff) |
|
642 | 638 | |
|
643 |
def |
|
|
639 | def archive(self, cnode, type): | |
|
640 | cs = self.repo.changelog.read(cnode) | |
|
641 | mnode = cs[0] | |
|
642 | mf = self.repo.manifest.read(mnode) | |
|
643 | rev = self.repo.manifest.rev(mnode) | |
|
644 | reponame = re.sub(r"\W+", "-", self.reponame) | |
|
645 | name = "%s-%s/" % (reponame, short(cnode)) | |
|
646 | ||
|
644 | 647 | if type == 'zip': |
|
645 | 648 | import zipfile |
|
646 | 649 | |
|
647 | tmp = tempfile.mkstemp()[1] | |
|
648 | zf = zipfile.ZipFile(tmp, "w", zipfile.ZIP_DEFLATED) | |
|
649 | mf = self.repo.manifest.read(bin(mnode)) | |
|
650 | rev = self.repo.manifest.rev(bin(mnode)) | |
|
651 | cnode = short(self.repo.changelog.node(rev)) | |
|
652 | name = os.path.basename(self.repo.path[:-4]) # without '/.hg' suffix | |
|
653 | name += '-' + str(rev) + '-' + cnode + '/' | |
|
650 | try: | |
|
651 | tmp = tempfile.mkstemp()[1] | |
|
652 | zf = zipfile.ZipFile(tmp, "w", zipfile.ZIP_DEFLATED) | |
|
653 | ||
|
654 | for f in mf.keys(): | |
|
655 | zf.writestr(name + f, self.repo.file(f).read(mf[f])) | |
|
656 | zf.close() | |
|
654 | 657 | |
|
655 | for fname in mf.keys(): | |
|
656 | r = self.repo.file(fname) | |
|
657 | zf.writestr(name + fname, r.read(mf[fname])) | |
|
658 | zf.close() | |
|
659 | ||
|
660 | f = open(tmp, 'r') | |
|
661 | httphdr('application/zip', name[:-1] + '.zip', os.path.getsize(tmp)) | |
|
662 | sys.stdout.write(f.read()) | |
|
663 | f.close() | |
|
664 | os.unlink(tmp) | |
|
658 | f = open(tmp, 'r') | |
|
659 | httphdr('application/zip', name[:-1] + '.zip', | |
|
660 | os.path.getsize(tmp)) | |
|
661 | sys.stdout.write(f.read()) | |
|
662 | f.close() | |
|
663 | finally: | |
|
664 | os.unlink(tmp) | |
|
665 | 665 | |
|
666 | 666 | else: |
|
667 | 667 | import StringIO |
|
668 | 668 | import time |
|
669 | 669 | import tarfile |
|
670 | 670 | |
|
671 | #if type == "gz": | |
|
672 | # tf = tarfile.TarFile.gzopen('', 'w', sys.stdout, compressionlevel) | |
|
673 | #else: | |
|
674 | # tf = tarfile.TarFile.bz2open('', 'w', sys.stdout, compressionlevel) | |
|
675 | 671 | tf = tarfile.TarFile.open(mode='w|' + type, fileobj=sys.stdout) |
|
676 | ||
|
677 | mf = self.repo.manifest.read(bin(mnode)) | |
|
678 | rev = self.repo.manifest.rev(bin(mnode)) | |
|
679 | cnode = short(self.repo.changelog.node(rev)) | |
|
680 | mff = self.repo.manifest.readflags(bin(mnode)) | |
|
672 | mff = self.repo.manifest.readflags(mnode) | |
|
681 | 673 | mtime = int(time.time()) |
|
682 | name = os.path.basename(self.repo.path[:-4]) # without '/.hg' suffix | |
|
683 | name += '-' + str(rev) + '-' + cnode + '/' | |
|
684 | 674 | |
|
685 | 675 | httphdr('application/octet-stream', name[:-1] + '.tar.' + type) |
|
686 | 676 | for fname in mf.keys(): |
|
687 | r = self.repo.file(fname) | |
|
688 | rcont = r.read(mf[fname]) | |
|
677 | rcont = self.repo.file(fname).read(mf[fname]) | |
|
689 | 678 | finfo = tarfile.TarInfo(name + fname) |
|
690 | 679 | finfo.mtime = mtime |
|
691 | 680 | finfo.size = len(rcont) |
|
692 | 681 | finfo.mode = mff[fname] and 0755 or 0644 |
|
693 | 682 | tf.addfile(finfo, StringIO.StringIO(rcont)) |
|
694 | 683 | tf.close() |
|
695 | 684 | |
|
696 | 685 | # add tags to things |
|
697 | 686 | # tags -> list of changesets corresponding to tags |
|
698 | 687 | # find tag, changeset, file |
|
699 | 688 | |
|
700 | 689 | def run(self): |
|
701 | 690 | def header(**map): |
|
702 | 691 | yield self.t("header", **map) |
|
703 | 692 | |
|
704 | 693 | def footer(**map): |
|
705 | 694 | yield self.t("footer", **map) |
|
706 | 695 | |
|
707 | 696 | self.refresh() |
|
708 | 697 | args = cgi.parse() |
|
709 | 698 | |
|
710 | 699 | t = self.repo.ui.config("web", "templates", templatepath()) |
|
711 | 700 | m = os.path.join(t, "map") |
|
712 | 701 | style = self.repo.ui.config("web", "style", "") |
|
713 | 702 | if args.has_key('style'): |
|
714 | 703 | style = args['style'][0] |
|
715 | 704 | if style: |
|
716 | 705 | b = os.path.basename("map-" + style) |
|
717 | 706 | p = os.path.join(t, b) |
|
718 | 707 | if os.path.isfile(p): |
|
719 | 708 | m = p |
|
720 | 709 | |
|
721 | 710 | port = os.environ["SERVER_PORT"] |
|
722 | 711 | port = port != "80" and (":" + port) or "" |
|
723 | 712 | uri = os.environ["REQUEST_URI"] |
|
724 | 713 | if "?" in uri: |
|
725 | 714 | uri = uri.split("?")[0] |
|
726 | 715 | url = "http://%s%s%s" % (os.environ["SERVER_NAME"], port, uri) |
|
727 | 716 | |
|
728 | 717 | self.t = templater(m, common_filters, |
|
729 | 718 | {"url": url, |
|
730 | 719 | "repo": self.reponame, |
|
731 | 720 | "header": header, |
|
732 | 721 | "footer": footer, |
|
733 | 722 | }) |
|
734 | 723 | |
|
735 | 724 | if not args.has_key('cmd'): |
|
736 | 725 | args['cmd'] = [self.t.cache['default'],] |
|
737 | 726 | |
|
738 | 727 | if args['cmd'][0] == 'changelog': |
|
739 | 728 | c = self.repo.changelog.count() - 1 |
|
740 | 729 | hi = c |
|
741 | 730 | if args.has_key('rev'): |
|
742 | 731 | hi = args['rev'][0] |
|
743 | 732 | try: |
|
744 | 733 | hi = self.repo.changelog.rev(self.repo.lookup(hi)) |
|
745 | 734 | except RepoError: |
|
746 | 735 | write(self.search(hi)) |
|
747 | 736 | return |
|
748 | 737 | |
|
749 | 738 | write(self.changelog(hi)) |
|
750 | 739 | |
|
751 | 740 | elif args['cmd'][0] == 'changeset': |
|
752 | 741 | write(self.changeset(args['node'][0])) |
|
753 | 742 | |
|
754 | 743 | elif args['cmd'][0] == 'manifest': |
|
755 | 744 | write(self.manifest(args['manifest'][0], args['path'][0])) |
|
756 | 745 | |
|
757 | 746 | elif args['cmd'][0] == 'tags': |
|
758 | 747 | write(self.tags()) |
|
759 | 748 | |
|
760 | 749 | elif args['cmd'][0] == 'filediff': |
|
761 | 750 | write(self.filediff(args['file'][0], args['node'][0])) |
|
762 | 751 | |
|
763 | 752 | elif args['cmd'][0] == 'file': |
|
764 | 753 | write(self.filerevision(args['file'][0], args['filenode'][0])) |
|
765 | 754 | |
|
766 | 755 | elif args['cmd'][0] == 'annotate': |
|
767 | 756 | write(self.fileannotate(args['file'][0], args['filenode'][0])) |
|
768 | 757 | |
|
769 | 758 | elif args['cmd'][0] == 'filelog': |
|
770 | 759 | write(self.filelog(args['file'][0], args['filenode'][0])) |
|
771 | 760 | |
|
772 | 761 | elif args['cmd'][0] == 'heads': |
|
773 | 762 | httphdr("application/mercurial-0.1") |
|
774 | 763 | h = self.repo.heads() |
|
775 | 764 | sys.stdout.write(" ".join(map(hex, h)) + "\n") |
|
776 | 765 | |
|
777 | 766 | elif args['cmd'][0] == 'branches': |
|
778 | 767 | httphdr("application/mercurial-0.1") |
|
779 | 768 | nodes = [] |
|
780 | 769 | if args.has_key('nodes'): |
|
781 | 770 | nodes = map(bin, args['nodes'][0].split(" ")) |
|
782 | 771 | for b in self.repo.branches(nodes): |
|
783 | 772 | sys.stdout.write(" ".join(map(hex, b)) + "\n") |
|
784 | 773 | |
|
785 | 774 | elif args['cmd'][0] == 'between': |
|
786 | 775 | httphdr("application/mercurial-0.1") |
|
787 | 776 | nodes = [] |
|
788 | 777 | if args.has_key('pairs'): |
|
789 | 778 | pairs = [map(bin, p.split("-")) |
|
790 | 779 | for p in args['pairs'][0].split(" ")] |
|
791 | 780 | for b in self.repo.between(pairs): |
|
792 | 781 | sys.stdout.write(" ".join(map(hex, b)) + "\n") |
|
793 | 782 | |
|
794 | 783 | elif args['cmd'][0] == 'changegroup': |
|
795 | 784 | httphdr("application/mercurial-0.1") |
|
796 | 785 | nodes = [] |
|
797 | 786 | if not self.allowpull: |
|
798 | 787 | return |
|
799 | 788 | |
|
800 | 789 | if args.has_key('roots'): |
|
801 | 790 | nodes = map(bin, args['roots'][0].split(" ")) |
|
802 | 791 | |
|
803 | 792 | z = zlib.compressobj() |
|
804 | 793 | f = self.repo.changegroup(nodes) |
|
805 | 794 | while 1: |
|
806 | 795 | chunk = f.read(4096) |
|
807 | 796 | if not chunk: |
|
808 | 797 | break |
|
809 | 798 | sys.stdout.write(z.compress(chunk)) |
|
810 | 799 | |
|
811 | 800 | sys.stdout.write(z.flush()) |
|
812 | 801 | |
|
813 |
elif args['cmd'][0] == ' |
|
|
814 |
|
|
|
802 | elif args['cmd'][0] == 'archive': | |
|
803 | changeset = bin(args['node'][0]) | |
|
815 | 804 | type = args['type'][0] |
|
816 |
f |
|
|
817 | if type == i and i in self.allowedtarballs: | |
|
818 |
|
|
|
819 |
|
|
|
805 | if (type in self.archives and | |
|
806 | self.repo.ui.configbool("web", "allow" + type, False)): | |
|
807 | self.archive(changeset, type) | |
|
808 | return | |
|
820 | 809 | |
|
821 | 810 | write(self.t("error")) |
|
822 | 811 | |
|
823 | 812 | else: |
|
824 | 813 | write(self.t("error")) |
|
825 | 814 | |
|
826 | 815 | def create_server(repo): |
|
827 | 816 | |
|
828 | 817 | def openlog(opt, default): |
|
829 | 818 | if opt and opt != '-': |
|
830 | 819 | return open(opt, 'w') |
|
831 | 820 | return default |
|
832 | 821 | |
|
833 | 822 | address = repo.ui.config("web", "address", "") |
|
834 | 823 | port = int(repo.ui.config("web", "port", 8000)) |
|
835 | 824 | use_ipv6 = repo.ui.configbool("web", "ipv6") |
|
836 | 825 | accesslog = openlog(repo.ui.config("web", "accesslog", "-"), sys.stdout) |
|
837 | 826 | errorlog = openlog(repo.ui.config("web", "errorlog", "-"), sys.stderr) |
|
838 | 827 | |
|
839 | 828 | import BaseHTTPServer |
|
840 | 829 | |
|
841 | 830 | class IPv6HTTPServer(BaseHTTPServer.HTTPServer): |
|
842 | 831 | address_family = getattr(socket, 'AF_INET6', None) |
|
843 | 832 | |
|
844 | 833 | def __init__(self, *args, **kwargs): |
|
845 | 834 | if self.address_family is None: |
|
846 | 835 | raise RepoError('IPv6 not available on this system') |
|
847 | 836 | BaseHTTPServer.HTTPServer.__init__(self, *args, **kwargs) |
|
848 | 837 | |
|
849 | 838 | class hgwebhandler(BaseHTTPServer.BaseHTTPRequestHandler): |
|
850 | 839 | def log_error(self, format, *args): |
|
851 | 840 | errorlog.write("%s - - [%s] %s\n" % (self.address_string(), |
|
852 | 841 | self.log_date_time_string(), |
|
853 | 842 | format % args)) |
|
854 | 843 | |
|
855 | 844 | def log_message(self, format, *args): |
|
856 | 845 | accesslog.write("%s - - [%s] %s\n" % (self.address_string(), |
|
857 | 846 | self.log_date_time_string(), |
|
858 | 847 | format % args)) |
|
859 | 848 | |
|
860 | 849 | def do_POST(self): |
|
861 | 850 | try: |
|
862 | 851 | self.do_hgweb() |
|
863 | 852 | except socket.error, inst: |
|
864 | 853 | if inst.args[0] != 32: |
|
865 | 854 | raise |
|
866 | 855 | |
|
867 | 856 | def do_GET(self): |
|
868 | 857 | self.do_POST() |
|
869 | 858 | |
|
870 | 859 | def do_hgweb(self): |
|
871 | 860 | query = "" |
|
872 | 861 | p = self.path.find("?") |
|
873 | 862 | if p: |
|
874 | 863 | query = self.path[p + 1:] |
|
875 | 864 | query = query.replace('+', ' ') |
|
876 | 865 | |
|
877 | 866 | env = {} |
|
878 | 867 | env['GATEWAY_INTERFACE'] = 'CGI/1.1' |
|
879 | 868 | env['REQUEST_METHOD'] = self.command |
|
880 | 869 | env['SERVER_NAME'] = self.server.server_name |
|
881 | 870 | env['SERVER_PORT'] = str(self.server.server_port) |
|
882 | 871 | env['REQUEST_URI'] = "/" |
|
883 | 872 | if query: |
|
884 | 873 | env['QUERY_STRING'] = query |
|
885 | 874 | host = self.address_string() |
|
886 | 875 | if host != self.client_address[0]: |
|
887 | 876 | env['REMOTE_HOST'] = host |
|
888 | 877 | env['REMOTE_ADDR'] = self.client_address[0] |
|
889 | 878 | |
|
890 | 879 | if self.headers.typeheader is None: |
|
891 | 880 | env['CONTENT_TYPE'] = self.headers.type |
|
892 | 881 | else: |
|
893 | 882 | env['CONTENT_TYPE'] = self.headers.typeheader |
|
894 | 883 | length = self.headers.getheader('content-length') |
|
895 | 884 | if length: |
|
896 | 885 | env['CONTENT_LENGTH'] = length |
|
897 | 886 | accept = [] |
|
898 | 887 | for line in self.headers.getallmatchingheaders('accept'): |
|
899 | 888 | if line[:1] in "\t\n\r ": |
|
900 | 889 | accept.append(line.strip()) |
|
901 | 890 | else: |
|
902 | 891 | accept = accept + line[7:].split(',') |
|
903 | 892 | env['HTTP_ACCEPT'] = ','.join(accept) |
|
904 | 893 | |
|
905 | 894 | os.environ.update(env) |
|
906 | 895 | |
|
907 | 896 | save = sys.argv, sys.stdin, sys.stdout, sys.stderr |
|
908 | 897 | try: |
|
909 | 898 | sys.stdin = self.rfile |
|
910 | 899 | sys.stdout = self.wfile |
|
911 | 900 | sys.argv = ["hgweb.py"] |
|
912 | 901 | if '=' not in query: |
|
913 | 902 | sys.argv.append(query) |
|
914 | 903 | self.send_response(200, "Script output follows") |
|
915 | 904 | hg.run() |
|
916 | 905 | finally: |
|
917 | 906 | sys.argv, sys.stdin, sys.stdout, sys.stderr = save |
|
918 | 907 | |
|
919 | 908 | hg = hgweb(repo) |
|
920 | 909 | if use_ipv6: |
|
921 | 910 | return IPv6HTTPServer((address, port), hgwebhandler) |
|
922 | 911 | else: |
|
923 | 912 | return BaseHTTPServer.HTTPServer((address, port), hgwebhandler) |
|
924 | 913 | |
|
925 | 914 | def server(path, name, templates, address, port, use_ipv6=False, |
|
926 | 915 | accesslog=sys.stdout, errorlog=sys.stderr): |
|
927 | 916 | httpd = create_server(path, name, templates, address, port, use_ipv6, |
|
928 | 917 | accesslog, errorlog) |
|
929 | 918 | httpd.serve_forever() |
|
930 | 919 | |
|
931 | 920 | # This is a stopgap |
|
932 | 921 | class hgwebdir: |
|
933 | 922 | def __init__(self, config): |
|
934 | 923 | self.cp = ConfigParser.SafeConfigParser() |
|
935 | 924 | self.cp.read(config) |
|
936 | 925 | |
|
937 | 926 | def run(self): |
|
938 | 927 | try: |
|
939 | 928 | virtual = os.environ["PATH_INFO"] |
|
940 | 929 | except: |
|
941 | 930 | virtual = "" |
|
942 | 931 | |
|
943 | 932 | if virtual[1:]: |
|
944 | 933 | real = self.cp.get("paths", virtual[1:]) |
|
945 | 934 | h = hgweb(real) |
|
946 | 935 | h.run() |
|
947 | 936 | return |
|
948 | 937 | |
|
949 | 938 | def header(**map): |
|
950 | 939 | yield tmpl("header", **map) |
|
951 | 940 | |
|
952 | 941 | def footer(**map): |
|
953 | 942 | yield tmpl("footer", **map) |
|
954 | 943 | |
|
955 | 944 | templates = templatepath() |
|
956 | 945 | m = os.path.join(templates, "map") |
|
957 | 946 | tmpl = templater(m, common_filters, |
|
958 | 947 | {"header": header, "footer": footer}) |
|
959 | 948 | |
|
960 | 949 | def entries(**map): |
|
961 | 950 | parity = 0 |
|
962 | 951 | l = self.cp.items("paths") |
|
963 | 952 | l.sort() |
|
964 | 953 | for v,r in l: |
|
965 | 954 | cp2 = ConfigParser.SafeConfigParser() |
|
966 | 955 | cp2.read(os.path.join(r, ".hg", "hgrc")) |
|
967 | 956 | |
|
968 | 957 | def get(sec, val, default): |
|
969 | 958 | try: |
|
970 | 959 | return cp2.get(sec, val) |
|
971 | 960 | except: |
|
972 | 961 | return default |
|
973 | 962 | |
|
974 | 963 | url = os.environ["REQUEST_URI"] + "/" + v |
|
975 | 964 | url = url.replace("//", "/") |
|
976 | 965 | |
|
977 | 966 | yield dict(author=get("web", "author", "unknown"), |
|
978 | 967 | name=get("web", "name", v), |
|
979 | 968 | url=url, |
|
980 | 969 | parity=parity, |
|
981 | 970 | shortdesc=get("web", "description", "unknown"), |
|
982 | 971 | lastupdate=os.stat(os.path.join(r, ".hg", |
|
983 | 972 | "00changelog.d")).st_mtime) |
|
984 | 973 | |
|
985 | 974 | parity = 1 - parity |
|
986 | 975 | |
|
987 | 976 | write(tmpl("index", entries=entries)) |
@@ -1,50 +1,50 | |||
|
1 | 1 | #header# |
|
2 | 2 | <title>#repo|escape#: changeset #node|short#</title> |
|
3 | 3 | </head> |
|
4 | 4 | <body> |
|
5 | 5 | |
|
6 | 6 | <div class="buttons"> |
|
7 | 7 | <a href="?cmd=changelog;rev=#rev#">changelog</a> |
|
8 | 8 | <a href="?cmd=tags">tags</a> |
|
9 | 9 | <a href="?cmd=manifest;manifest=#manifest#;path=/">manifest</a> |
|
10 | 10 | <a href="?cmd=changeset;node=#node#;style=raw">raw</a> |
|
11 | #tarballs%tarballentry# | |
|
11 | #archives%archiveentry# | |
|
12 | 12 | </div> |
|
13 | 13 | |
|
14 | 14 | <h2>changeset: #desc|escape|firstline#</h2> |
|
15 | 15 | |
|
16 | 16 | <table id="changesetEntry"> |
|
17 | 17 | <tr> |
|
18 | 18 | <th class="changeset">changeset #rev#:</th> |
|
19 | 19 | <td class="changeset"><a href="?cmd=changeset;node=#node#">#node|short#</a></td> |
|
20 | 20 | </tr> |
|
21 | 21 | #parent# |
|
22 | 22 | #changesettag# |
|
23 | 23 | <tr> |
|
24 | 24 | <th class="manifest">manifest:</th> |
|
25 | 25 | <td class="manifest"><a href="?cmd=manifest;manifest=#manifest#;path=/">#manifest|short#</a></td> |
|
26 | 26 | </tr> |
|
27 | 27 | <tr> |
|
28 | 28 | <th class="author">author:</th> |
|
29 | 29 | <td class="author">#author|obfuscate#</td> |
|
30 | 30 | </tr> |
|
31 | 31 | <tr> |
|
32 | 32 | <th class="date">date:</th> |
|
33 | 33 | <td class="date">#date|date# (#date|age# ago)</td></tr> |
|
34 | 34 | <tr> |
|
35 | 35 | <th class="files">files:</th> |
|
36 | 36 | <td class="files">#files#</td></tr> |
|
37 | 37 | <tr> |
|
38 | 38 | <th class="description">description:</th> |
|
39 | 39 | <td class="description">#desc|escape|addbreaks#</td> |
|
40 | 40 | </tr> |
|
41 | 41 | </table> |
|
42 | 42 | |
|
43 | 43 | <div id="changesetDiff"> |
|
44 | 44 | #diff# |
|
45 | 45 | </div> |
|
46 | 46 | |
|
47 | 47 | </body> |
|
48 | 48 | </html> |
|
49 | 49 | |
|
50 | 50 |
General Comments 0
You need to be logged in to leave comments.
Login now