Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/hgweb_mod.py @ 6123:f7f25f58693a
merged Edward Lee's line anchors patch
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 15 Feb 2008 19:44:54 +0100 |
parents | 404be894cf71 800e2756c9ab |
children | 74406f50bd46 |
comparison
equal
deleted
inserted
replaced
6117:c74f1d9092f8 | 6123:f7f25f58693a |
---|---|
8 | 8 |
9 import os, mimetypes, re | 9 import os, mimetypes, re |
10 from mercurial.node import * | 10 from mercurial.node import * |
11 from mercurial import mdiff, ui, hg, util, archival, patch, hook | 11 from mercurial import mdiff, ui, hg, util, archival, patch, hook |
12 from mercurial import revlog, templater, templatefilters | 12 from mercurial import revlog, templater, templatefilters |
13 from common import ErrorResponse, get_mtime, style_map, paritygen, get_contact | 13 from common import get_mtime, style_map, paritygen, countgen, get_contact |
14 from common import ErrorResponse | |
14 from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR | 15 from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR |
15 from request import wsgirequest | 16 from request import wsgirequest |
16 import webcommands, protocol | 17 import webcommands, protocol |
17 | 18 |
18 shortcuts = { | 19 shortcuts = { |
370 lines=prettyprintlines(diff), | 371 lines=prettyprintlines(diff), |
371 parity=parity.next(), | 372 parity=parity.next(), |
372 file=f, | 373 file=f, |
373 filenode=hex(fn or nullid)) | 374 filenode=hex(fn or nullid)) |
374 | 375 |
376 blockcount = countgen() | |
375 def prettyprintlines(diff): | 377 def prettyprintlines(diff): |
376 for l in diff.splitlines(1): | 378 blockno = blockcount.next() |
379 for lineno, l in enumerate(diff.splitlines(1)): | |
380 if blockno == 0: | |
381 lineno = lineno + 1 | |
382 else: | |
383 lineno = "%d.%d" % (blockno, lineno + 1) | |
377 if l.startswith('+'): | 384 if l.startswith('+'): |
378 yield tmpl("difflineplus", line=l) | 385 ltype = "difflineplus" |
379 elif l.startswith('-'): | 386 elif l.startswith('-'): |
380 yield tmpl("difflineminus", line=l) | 387 ltype = "difflineminus" |
381 elif l.startswith('@'): | 388 elif l.startswith('@'): |
382 yield tmpl("difflineat", line=l) | 389 ltype = "difflineat" |
383 else: | 390 else: |
384 yield tmpl("diffline", line=l) | 391 ltype = "diffline" |
392 yield tmpl(ltype, | |
393 line=l, | |
394 lineid="l%s" % lineno, | |
395 linenumber="% 8s" % lineno) | |
385 | 396 |
386 r = self.repo | 397 r = self.repo |
387 c1 = r.changectx(node1) | 398 c1 = r.changectx(node1) |
388 c2 = r.changectx(node2) | 399 c2 = r.changectx(node2) |
389 date1 = util.datestr(c1.date()) | 400 date1 = util.datestr(c1.date()) |
595 if util.binary(text): | 606 if util.binary(text): |
596 mt = mimetypes.guess_type(f)[0] or 'application/octet-stream' | 607 mt = mimetypes.guess_type(f)[0] or 'application/octet-stream' |
597 text = '(binary:%s)' % mt | 608 text = '(binary:%s)' % mt |
598 | 609 |
599 def lines(): | 610 def lines(): |
600 for l, t in enumerate(text.splitlines(1)): | 611 for lineno, t in enumerate(text.splitlines(1)): |
601 yield {"line": t, | 612 yield {"line": t, |
602 "linenumber": "% 6d" % (l + 1), | 613 "lineid": "l%d" % (lineno + 1), |
614 "linenumber": "% 6d" % (lineno + 1), | |
603 "parity": parity.next()} | 615 "parity": parity.next()} |
604 | 616 |
605 return tmpl("filerevision", | 617 return tmpl("filerevision", |
606 file=f, | 618 file=f, |
607 path=_up(f), | 619 path=_up(f), |
622 fl = fctx.filelog() | 634 fl = fctx.filelog() |
623 parity = paritygen(self.stripecount) | 635 parity = paritygen(self.stripecount) |
624 | 636 |
625 def annotate(**map): | 637 def annotate(**map): |
626 last = None | 638 last = None |
627 for f, l in fctx.annotate(follow=True): | 639 for lineno, (f, l) in enumerate(fctx.annotate(follow=True)): |
628 fnode = f.filenode() | 640 fnode = f.filenode() |
629 name = self.repo.ui.shortuser(f.user()) | 641 name = self.repo.ui.shortuser(f.user()) |
630 | 642 |
631 if last != fnode: | 643 if last != fnode: |
632 last = fnode | 644 last = fnode |
634 yield {"parity": parity.next(), | 646 yield {"parity": parity.next(), |
635 "node": hex(f.node()), | 647 "node": hex(f.node()), |
636 "rev": f.rev(), | 648 "rev": f.rev(), |
637 "author": name, | 649 "author": name, |
638 "file": f.path(), | 650 "file": f.path(), |
639 "line": l} | 651 "line": l, |
652 "lineid": "l%d" % (lineno + 1), | |
653 "linenumber": "% 6d" % (lineno + 1)} | |
640 | 654 |
641 return tmpl("fileannotate", | 655 return tmpl("fileannotate", |
642 file=f, | 656 file=f, |
643 annotate=annotate, | 657 annotate=annotate, |
644 path=_up(f), | 658 path=_up(f), |