comparison mercurial/hgweb/hgweb_mod.py @ 6142:50a277e6ceae

merge backout
author Thomas Arendsen Hein <thomas@intevation.de>
date Mon, 18 Feb 2008 19:21:33 +0100
parents 90e5c82a3859 74406f50bd46
children b023915aa1bc
comparison
equal deleted inserted replaced
6141:90e5c82a3859 6142:50a277e6ceae
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 = {
369 lines=prettyprintlines(diff), 370 lines=prettyprintlines(diff),
370 parity=parity.next(), 371 parity=parity.next(),
371 file=f, 372 file=f,
372 filenode=hex(fn or nullid)) 373 filenode=hex(fn or nullid))
373 374
375 blockcount = countgen()
374 def prettyprintlines(diff): 376 def prettyprintlines(diff):
375 for l in diff.splitlines(1): 377 blockno = blockcount.next()
378 for lineno, l in enumerate(diff.splitlines(1)):
379 if blockno == 0:
380 lineno = lineno + 1
381 else:
382 lineno = "%d.%d" % (blockno, lineno + 1)
376 if l.startswith('+'): 383 if l.startswith('+'):
377 yield tmpl("difflineplus", line=l) 384 ltype = "difflineplus"
378 elif l.startswith('-'): 385 elif l.startswith('-'):
379 yield tmpl("difflineminus", line=l) 386 ltype = "difflineminus"
380 elif l.startswith('@'): 387 elif l.startswith('@'):
381 yield tmpl("difflineat", line=l) 388 ltype = "difflineat"
382 else: 389 else:
383 yield tmpl("diffline", line=l) 390 ltype = "diffline"
391 yield tmpl(ltype,
392 line=l,
393 lineid="l%s" % lineno,
394 linenumber="% 8s" % lineno)
384 395
385 r = self.repo 396 r = self.repo
386 c1 = r.changectx(node1) 397 c1 = r.changectx(node1)
387 c2 = r.changectx(node2) 398 c2 = r.changectx(node2)
388 date1 = util.datestr(c1.date()) 399 date1 = util.datestr(c1.date())
464 qw = query.lower().split() 475 qw = query.lower().split()
465 476
466 def revgen(): 477 def revgen():
467 for i in xrange(cl.count() - 1, 0, -100): 478 for i in xrange(cl.count() - 1, 0, -100):
468 l = [] 479 l = []
469 for j in xrange(max(0, i - 100), i): 480 for j in xrange(max(0, i - 100), i + 1):
470 ctx = self.repo.changectx(j) 481 ctx = self.repo.changectx(j)
471 l.append(ctx) 482 l.append(ctx)
472 l.reverse() 483 l.reverse()
473 for e in l: 484 for e in l:
474 yield e 485 yield e
594 if util.binary(text): 605 if util.binary(text):
595 mt = mimetypes.guess_type(f)[0] or 'application/octet-stream' 606 mt = mimetypes.guess_type(f)[0] or 'application/octet-stream'
596 text = '(binary:%s)' % mt 607 text = '(binary:%s)' % mt
597 608
598 def lines(): 609 def lines():
599 for l, t in enumerate(text.splitlines(1)): 610 for lineno, t in enumerate(text.splitlines(1)):
600 yield {"line": t, 611 yield {"line": t,
601 "linenumber": "% 6d" % (l + 1), 612 "lineid": "l%d" % (lineno + 1),
613 "linenumber": "% 6d" % (lineno + 1),
602 "parity": parity.next()} 614 "parity": parity.next()}
603 615
604 return tmpl("filerevision", 616 return tmpl("filerevision",
605 file=f, 617 file=f,
606 path=_up(f), 618 path=_up(f),
621 fl = fctx.filelog() 633 fl = fctx.filelog()
622 parity = paritygen(self.stripecount) 634 parity = paritygen(self.stripecount)
623 635
624 def annotate(**map): 636 def annotate(**map):
625 last = None 637 last = None
626 for f, l in fctx.annotate(follow=True): 638 lines = enumerate(fctx.annotate(follow=True, linenumber=True))
639 for lineno, ((f, targetline), l) in lines:
627 fnode = f.filenode() 640 fnode = f.filenode()
628 name = self.repo.ui.shortuser(f.user()) 641 name = self.repo.ui.shortuser(f.user())
629 642
630 if last != fnode: 643 if last != fnode:
631 last = fnode 644 last = fnode
633 yield {"parity": parity.next(), 646 yield {"parity": parity.next(),
634 "node": hex(f.node()), 647 "node": hex(f.node()),
635 "rev": f.rev(), 648 "rev": f.rev(),
636 "author": name, 649 "author": name,
637 "file": f.path(), 650 "file": f.path(),
638 "line": l} 651 "targetline": targetline,
652 "line": l,
653 "lineid": "l%d" % (lineno + 1),
654 "linenumber": "% 6d" % (lineno + 1)}
639 655
640 return tmpl("fileannotate", 656 return tmpl("fileannotate",
641 file=f, 657 file=f,
642 annotate=annotate, 658 annotate=annotate,
643 path=_up(f), 659 path=_up(f),