Show More
@@ -13,11 +13,13 b' from mercurial.ui import *' | |||||
13 | def templatepath(): |
|
13 | def templatepath(): | |
14 | for f in "templates", "../templates": |
|
14 | for f in "templates", "../templates": | |
15 | p = os.path.join(os.path.dirname(__file__), f) |
|
15 | p = os.path.join(os.path.dirname(__file__), f) | |
16 |
if os.path.isdir(p): |
|
16 | if os.path.isdir(p): | |
|
17 | return p | |||
17 |
|
18 | |||
18 | def age(t): |
|
19 | def age(t): | |
19 | def plural(t, c): |
|
20 | def plural(t, c): | |
20 |
if c == 1: |
|
21 | if c == 1: | |
|
22 | return t | |||
21 | return t + "s" |
|
23 | return t + "s" | |
22 | def fmt(t, c): |
|
24 | def fmt(t, c): | |
23 | return "%d %s" % (c, plural(t, c)) |
|
25 | return "%d %s" % (c, plural(t, c)) | |
@@ -37,17 +39,20 b' def age(t):' | |||||
37 |
|
39 | |||
38 | for t, s in scales: |
|
40 | for t, s in scales: | |
39 | n = delta / s |
|
41 | n = delta / s | |
40 |
if n >= 2 or s == 1: |
|
42 | if n >= 2 or s == 1: | |
|
43 | return fmt(t, n) | |||
41 |
|
44 | |||
42 | def nl2br(text): |
|
45 | def nl2br(text): | |
43 | return text.replace('\n', '<br/>\n') |
|
46 | return text.replace('\n', '<br/>\n') | |
44 |
|
47 | |||
45 | def obfuscate(text): |
|
48 | def obfuscate(text): | |
46 |
return ''.join([ |
|
49 | return ''.join(['&#%d;' % ord(c) for c in text]) | |
47 |
|
50 | |||
48 | def up(p): |
|
51 | def up(p): | |
49 |
if p[0] != "/": |
|
52 | if p[0] != "/": | |
50 | if p[-1] == "/": p = p[:-1] |
|
53 | p = "/" + p | |
|
54 | if p[-1] == "/": | |||
|
55 | p = p[:-1] | |||
51 | up = os.path.dirname(p) |
|
56 | up = os.path.dirname(p) | |
52 | if up == "/": |
|
57 | if up == "/": | |
53 | return "/" |
|
58 | return "/" | |
@@ -173,7 +178,8 b' class hgweb:' | |||||
173 | yield self.t("fileellipses") |
|
178 | yield self.t("fileellipses") | |
174 |
|
179 | |||
175 | def parents(self, t1, nodes=[], rev=None,**args): |
|
180 | def parents(self, t1, nodes=[], rev=None,**args): | |
176 |
if not rev: |
|
181 | if not rev: | |
|
182 | rev = lambda x: "" | |||
177 | for node in nodes: |
|
183 | for node in nodes: | |
178 | if node != nullid: |
|
184 | if node != nullid: | |
179 | yield self.t(t1, node=hex(node), rev=rev(node), **args) |
|
185 | yield self.t(t1, node=hex(node), rev=rev(node), **args) | |
@@ -184,20 +190,21 b' class hgweb:' | |||||
184 |
|
190 | |||
185 | def diff(self, node1, node2, files): |
|
191 | def diff(self, node1, node2, files): | |
186 | def filterfiles(list, files): |
|
192 | def filterfiles(list, files): | |
187 |
l = [ |
|
193 | l = [x for x in list if x in files] | |
188 |
|
194 | |||
189 | for f in files: |
|
195 | for f in files: | |
190 |
if f[-1] != os.sep: |
|
196 | if f[-1] != os.sep: | |
191 | l += [ x for x in list if x.startswith(f) ] |
|
197 | f += os.sep | |
|
198 | l += [x for x in list if x.startswith(f)] | |||
192 | return l |
|
199 | return l | |
193 |
|
200 | |||
194 | parity = [0] |
|
201 | parity = [0] | |
195 | def diffblock(diff, f, fn): |
|
202 | def diffblock(diff, f, fn): | |
196 | yield self.t("diffblock", |
|
203 | yield self.t("diffblock", | |
197 |
lines |
|
204 | lines=prettyprintlines(diff), | |
198 |
parity |
|
205 | parity=parity[0], | |
199 |
file |
|
206 | file=f, | |
200 |
filenode |
|
207 | filenode=hex(fn or nullid)) | |
201 | parity[0] = 1 - parity[0] |
|
208 | parity[0] = 1 - parity[0] | |
202 |
|
209 | |||
203 | def prettyprintlines(diff): |
|
210 | def prettyprintlines(diff): | |
@@ -249,11 +256,15 b' class hgweb:' | |||||
249 |
|
256 | |||
250 | l = [] |
|
257 | l = [] | |
251 | for f in seq(): |
|
258 | for f in seq(): | |
252 |
if f < self.maxchanges / 2: |
|
259 | if f < self.maxchanges / 2: | |
253 |
|
|
260 | continue | |
|
261 | if f > count: | |||
|
262 | break | |||
254 | r = "%d" % f |
|
263 | r = "%d" % f | |
255 |
if pos + f < count: |
|
264 | if pos + f < count: | |
256 |
|
|
265 | l.append(("+" + r, pos + f)) | |
|
266 | if pos - f >= 0: | |||
|
267 | l.insert(0, ("-" + r, pos - f)) | |||
257 |
|
268 | |||
258 | yield {"rev": 0, "label": "(0)"} |
|
269 | yield {"rev": 0, "label": "(0)"} | |
259 |
|
270 | |||
@@ -272,21 +283,21 b' class hgweb:' | |||||
272 | hn = hex(n) |
|
283 | hn = hex(n) | |
273 | t = float(changes[2].split(' ')[0]) |
|
284 | t = float(changes[2].split(' ')[0]) | |
274 |
|
285 | |||
275 | l.insert(0, { |
|
286 | l.insert(0, {"parity": parity, | |
276 |
" |
|
287 | "author": changes[1], | |
277 | "author": changes[1], |
|
288 | "parent": self.parents("changelogparent", | |
278 | "parent": self.parents("changelogparent", |
|
289 | cl.parents(n), cl.rev), | |
279 | cl.parents(n), cl.rev), |
|
290 | "changelogtag": self.showtag("changelogtag",n), | |
280 | "changelogtag": self.showtag("changelogtag",n), |
|
291 | "manifest": hex(changes[0]), | |
281 |
" |
|
292 | "desc": changes[4], | |
282 |
"de |
|
293 | "date": t, | |
283 | "date": t, |
|
294 | "files": self.listfilediffs(changes[3], n), | |
284 | "files": self.listfilediffs(changes[3], n), |
|
295 | "rev": i, | |
285 |
" |
|
296 | "node": hn}) | |
286 | "node": hn}) |
|
|||
287 | parity = 1 - parity |
|
297 | parity = 1 - parity | |
288 |
|
298 | |||
289 |
for e in l: |
|
299 | for e in l: | |
|
300 | yield e | |||
290 |
|
301 | |||
291 | cl = self.repo.changelog |
|
302 | cl = self.repo.changelog | |
292 | mf = cl.read(cl.tip())[0] |
|
303 | mf = cl.read(cl.tip())[0] | |
@@ -326,27 +337,28 b' class hgweb:' | |||||
326 | q in " ".join(changes[3][:20]).lower()): |
|
337 | q in " ".join(changes[3][:20]).lower()): | |
327 | miss = 1 |
|
338 | miss = 1 | |
328 | break |
|
339 | break | |
329 |
if miss: |
|
340 | if miss: | |
|
341 | continue | |||
330 |
|
342 | |||
331 | count += 1 |
|
343 | count += 1 | |
332 | hn = hex(n) |
|
344 | hn = hex(n) | |
333 | t = float(changes[2].split(' ')[0]) |
|
345 | t = float(changes[2].split(' ')[0]) | |
334 |
|
346 | |||
335 | yield self.t( |
|
347 | yield self.t('searchentry', | |
336 |
|
|
348 | parity=count & 1, | |
337 |
|
|
349 | author=changes[1], | |
338 | author=changes[1], |
|
350 | parent=self.parents("changelogparent", | |
339 | parent=self.parents("changelogparent", |
|
351 | cl.parents(n), cl.rev), | |
340 | cl.parents(n), cl.rev), |
|
352 | changelogtag=self.showtag("changelogtag",n), | |
341 | changelogtag=self.showtag("changelogtag",n), |
|
353 | manifest=hex(changes[0]), | |
342 |
|
|
354 | desc=changes[4], | |
343 |
de |
|
355 | date=t, | |
344 | date=t, |
|
356 | files=self.listfilediffs(changes[3], n), | |
345 | files=self.listfilediffs(changes[3], n), |
|
357 | rev=i, | |
346 |
|
|
358 | node=hn) | |
347 | node=hn) |
|
|||
348 |
|
359 | |||
349 |
if count >= self.maxchanges: |
|
360 | if count >= self.maxchanges: | |
|
361 | break | |||
350 |
|
362 | |||
351 | cl = self.repo.changelog |
|
363 | cl = self.repo.changelog | |
352 | mf = cl.read(cl.tip())[0] |
|
364 | mf = cl.read(cl.tip())[0] | |
@@ -367,7 +379,7 b' class hgweb:' | |||||
367 | mf = self.repo.manifest.read(changes[0]) |
|
379 | mf = self.repo.manifest.read(changes[0]) | |
368 | for f in changes[3]: |
|
380 | for f in changes[3]: | |
369 | files.append(self.t("filenodelink", |
|
381 | files.append(self.t("filenodelink", | |
370 |
filenode |
|
382 | filenode=hex(mf.get(f, nullid)), file=f)) | |
371 |
|
383 | |||
372 | def diff(**map): |
|
384 | def diff(**map): | |
373 | yield self.diff(p1, n, None) |
|
385 | yield self.diff(p1, n, None) | |
@@ -377,7 +389,7 b' class hgweb:' | |||||
377 | rev=cl.rev(n), |
|
389 | rev=cl.rev(n), | |
378 | node=nodeid, |
|
390 | node=nodeid, | |
379 | parent=self.parents("changesetparent", |
|
391 | parent=self.parents("changesetparent", | |
380 |
|
|
392 | cl.parents(n), cl.rev), | |
381 | changesettag=self.showtag("changesettag",n), |
|
393 | changesettag=self.showtag("changesettag",n), | |
382 | manifest=hex(changes[0]), |
|
394 | manifest=hex(changes[0]), | |
383 | author=changes[1], |
|
395 | author=changes[1], | |
@@ -395,7 +407,6 b' class hgweb:' | |||||
395 | parity = (count - 1) & 1 |
|
407 | parity = (count - 1) & 1 | |
396 |
|
408 | |||
397 | for i in range(count): |
|
409 | for i in range(count): | |
398 |
|
||||
399 | n = fl.node(i) |
|
410 | n = fl.node(i) | |
400 | lr = fl.linkrev(n) |
|
411 | lr = fl.linkrev(n) | |
401 | cn = cl.node(lr) |
|
412 | cn = cl.node(lr) | |
@@ -410,16 +421,15 b' class hgweb:' | |||||
410 | "author": cs[1], |
|
421 | "author": cs[1], | |
411 | "date": t, |
|
422 | "date": t, | |
412 | "parent": self.parents("filelogparent", |
|
423 | "parent": self.parents("filelogparent", | |
413 |
fl.parents(n), |
|
424 | fl.parents(n), | |
|
425 | fl.rev, file=f), | |||
414 | "desc": cs[4]}) |
|
426 | "desc": cs[4]}) | |
415 | parity = 1 - parity |
|
427 | parity = 1 - parity | |
416 |
|
428 | |||
417 |
for e in l: |
|
429 | for e in l: | |
|
430 | yield e | |||
418 |
|
431 | |||
419 | yield self.t("filelog", |
|
432 | yield self.t("filelog", file=f, filenode=filenode, entries=entries) | |
420 | file=f, |
|
|||
421 | filenode=filenode, |
|
|||
422 | entries=entries) |
|
|||
423 |
|
433 | |||
424 | def filerevision(self, f, node): |
|
434 | def filerevision(self, f, node): | |
425 | fl = self.repo.file(f) |
|
435 | fl = self.repo.file(f) | |
@@ -438,7 +448,8 b' class hgweb:' | |||||
438 | "linenumber": "% 6d" % (l + 1), |
|
448 | "linenumber": "% 6d" % (l + 1), | |
439 | "parity": l & 1} |
|
449 | "parity": l & 1} | |
440 |
|
450 | |||
441 |
yield self.t("filerevision", |
|
451 | yield self.t("filerevision", | |
|
452 | file=f, | |||
442 | filenode=node, |
|
453 | filenode=node, | |
443 | path=up(f), |
|
454 | path=up(f), | |
444 | text=lines(), |
|
455 | text=lines(), | |
@@ -448,7 +459,7 b' class hgweb:' | |||||
448 | author=cs[1], |
|
459 | author=cs[1], | |
449 | date=t, |
|
460 | date=t, | |
450 | parent=self.parents("filerevparent", |
|
461 | parent=self.parents("filerevparent", | |
451 |
|
|
462 | fl.parents(n), fl.rev, file=f), | |
452 | permissions=self.repo.manifest.readflags(mfn)[f]) |
|
463 | permissions=self.repo.manifest.readflags(mfn)[f]) | |
453 |
|
464 | |||
454 | def fileannotate(self, f, node): |
|
465 | def fileannotate(self, f, node): | |
@@ -498,18 +509,18 b' class hgweb:' | |||||
498 | "line": l} |
|
509 | "line": l} | |
499 |
|
510 | |||
500 | yield self.t("fileannotate", |
|
511 | yield self.t("fileannotate", | |
501 |
file |
|
512 | file=f, | |
502 |
filenode |
|
513 | filenode=node, | |
503 |
annotate |
|
514 | annotate=annotate, | |
504 |
path |
|
515 | path=up(f), | |
505 |
rev |
|
516 | rev=changerev, | |
506 |
node |
|
517 | node=hex(cn), | |
507 |
manifest |
|
518 | manifest=hex(mfn), | |
508 |
author |
|
519 | author=cs[1], | |
509 |
date |
|
520 | date=t, | |
510 |
parent |
|
521 | parent=self.parents("fileannotateparent", | |
511 |
|
|
522 | fl.parents(n), fl.rev, file=f), | |
512 |
permissions |
|
523 | permissions=self.repo.manifest.readflags(mfn)[f]) | |
513 |
|
524 | |||
514 | def manifest(self, mnode, path): |
|
525 | def manifest(self, mnode, path): | |
515 | mf = self.repo.manifest.read(bin(mnode)) |
|
526 | mf = self.repo.manifest.read(bin(mnode)) | |
@@ -609,7 +620,7 b' class hgweb:' | |||||
609 | node=changeset, |
|
620 | node=changeset, | |
610 | rev=self.repo.changelog.rev(n), |
|
621 | rev=self.repo.changelog.rev(n), | |
611 | parent=self.parents("filediffparent", |
|
622 | parent=self.parents("filediffparent", | |
612 | cl.parents(n), cl.rev), |
|
623 | cl.parents(n), cl.rev), | |
613 | diff=diff) |
|
624 | diff=diff) | |
614 |
|
625 | |||
615 | # add tags to things |
|
626 | # add tags to things | |
@@ -634,12 +645,14 b' class hgweb:' | |||||
634 | if style: |
|
645 | if style: | |
635 | b = os.path.basename("map-" + style) |
|
646 | b = os.path.basename("map-" + style) | |
636 | p = os.path.join(t, b) |
|
647 | p = os.path.join(t, b) | |
637 |
if os.path.isfile(p): |
|
648 | if os.path.isfile(p): | |
|
649 | m = p | |||
638 |
|
650 | |||
639 | port = os.environ["SERVER_PORT"] |
|
651 | port = os.environ["SERVER_PORT"] | |
640 | port = port != "80" and (":" + port) or "" |
|
652 | port = port != "80" and (":" + port) or "" | |
641 | uri = os.environ["REQUEST_URI"] |
|
653 | uri = os.environ["REQUEST_URI"] | |
642 |
if "?" in uri: |
|
654 | if "?" in uri: | |
|
655 | uri = uri.split("?")[0] | |||
643 | url = "http://%s%s%s" % (os.environ["SERVER_NAME"], port, uri) |
|
656 | url = "http://%s%s%s" % (os.environ["SERVER_NAME"], port, uri) | |
644 |
|
657 | |||
645 | self.t = templater(m, common_filters, |
|
658 | self.t = templater(m, common_filters, | |
@@ -647,7 +660,7 b' class hgweb:' | |||||
647 | "repo": self.reponame, |
|
660 | "repo": self.reponame, | |
648 | "header": header, |
|
661 | "header": header, | |
649 | "footer": footer, |
|
662 | "footer": footer, | |
650 |
|
|
663 | }) | |
651 |
|
664 | |||
652 | if not args.has_key('cmd'): |
|
665 | if not args.has_key('cmd'): | |
653 | args['cmd'] = [self.t.cache['default'],] |
|
666 | args['cmd'] = [self.t.cache['default'],] | |
@@ -703,8 +716,8 b' class hgweb:' | |||||
703 | httphdr("application/mercurial-0.1") |
|
716 | httphdr("application/mercurial-0.1") | |
704 | nodes = [] |
|
717 | nodes = [] | |
705 | if args.has_key('pairs'): |
|
718 | if args.has_key('pairs'): | |
706 |
pairs = [ |
|
719 | pairs = [map(bin, p.split("-")) | |
707 |
|
|
720 | for p in args['pairs'][0].split(" ")] | |
708 | for b in self.repo.between(pairs): |
|
721 | for b in self.repo.between(pairs): | |
709 | sys.stdout.write(" ".join(map(hex, b)) + "\n") |
|
722 | sys.stdout.write(" ".join(map(hex, b)) + "\n") | |
710 |
|
723 | |||
@@ -721,7 +734,8 b' class hgweb:' | |||||
721 | f = self.repo.changegroup(nodes) |
|
734 | f = self.repo.changegroup(nodes) | |
722 | while 1: |
|
735 | while 1: | |
723 | chunk = f.read(4096) |
|
736 | chunk = f.read(4096) | |
724 |
if not chunk: |
|
737 | if not chunk: | |
|
738 | break | |||
725 | sys.stdout.write(z.compress(chunk)) |
|
739 | sys.stdout.write(z.compress(chunk)) | |
726 |
|
740 | |||
727 | sys.stdout.write(z.flush()) |
|
741 | sys.stdout.write(z.flush()) | |
@@ -767,7 +781,8 b' def create_server(repo):' | |||||
767 | try: |
|
781 | try: | |
768 | self.do_hgweb() |
|
782 | self.do_hgweb() | |
769 | except socket.error, inst: |
|
783 | except socket.error, inst: | |
770 |
if inst.args[0] != 32: |
|
784 | if inst.args[0] != 32: | |
|
785 | raise | |||
771 |
|
786 | |||
772 | def do_GET(self): |
|
787 | def do_GET(self): | |
773 | self.do_POST() |
|
788 | self.do_POST() |
General Comments 0
You need to be logged in to leave comments.
Login now