Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/webutil.py @ 37984:3f70466ec7aa
hgweb: move prettyprintlines() closure out of diffs()
This will be wrapped with mappedgenerator.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Tue, 03 Apr 2018 23:38:19 +0900 |
parents | 9482498b96b0 |
children | 6a4de2dc78dd |
comparison
equal
deleted
inserted
replaced
37983:b9e6b71dc272 | 37984:3f70466ec7aa |
---|---|
517 | 517 |
518 def listfilediffs(files, node, max): | 518 def listfilediffs(files, node, max): |
519 return templateutil.mappedgenerator(_listfilediffsgen, | 519 return templateutil.mappedgenerator(_listfilediffsgen, |
520 args=(files, node, max)) | 520 args=(files, node, max)) |
521 | 521 |
522 def _prettyprintdifflines(tmpl, lines, blockno, lineidprefix): | |
523 for lineno, l in enumerate(lines, 1): | |
524 difflineno = "%d.%d" % (blockno, lineno) | |
525 if l.startswith('+'): | |
526 ltype = "difflineplus" | |
527 elif l.startswith('-'): | |
528 ltype = "difflineminus" | |
529 elif l.startswith('@'): | |
530 ltype = "difflineat" | |
531 else: | |
532 ltype = "diffline" | |
533 yield tmpl.generate(ltype, { | |
534 'line': l, | |
535 'lineno': lineno, | |
536 'lineid': lineidprefix + "l%s" % difflineno, | |
537 'linenumber': "% 8s" % difflineno, | |
538 }) | |
539 | |
522 def diffs(web, ctx, basectx, files, style, linerange=None, | 540 def diffs(web, ctx, basectx, files, style, linerange=None, |
523 lineidprefix=''): | 541 lineidprefix=''): |
524 | |
525 def prettyprintlines(lines, blockno): | |
526 for lineno, l in enumerate(lines, 1): | |
527 difflineno = "%d.%d" % (blockno, lineno) | |
528 if l.startswith('+'): | |
529 ltype = "difflineplus" | |
530 elif l.startswith('-'): | |
531 ltype = "difflineminus" | |
532 elif l.startswith('@'): | |
533 ltype = "difflineat" | |
534 else: | |
535 ltype = "diffline" | |
536 yield web.tmpl.generate(ltype, { | |
537 'line': l, | |
538 'lineno': lineno, | |
539 'lineid': lineidprefix + "l%s" % difflineno, | |
540 'linenumber': "% 8s" % difflineno, | |
541 }) | |
542 | |
543 repo = web.repo | 542 repo = web.repo |
544 if files: | 543 if files: |
545 m = match.exact(repo.root, repo.getcwd(), files) | 544 m = match.exact(repo.root, repo.getcwd(), files) |
546 else: | 545 else: |
547 m = match.always(repo.root, repo.getcwd()) | 546 m = match.always(repo.root, repo.getcwd()) |
564 lines.extend(hunklines) | 563 lines.extend(hunklines) |
565 if lines: | 564 if lines: |
566 yield web.tmpl.generate('diffblock', { | 565 yield web.tmpl.generate('diffblock', { |
567 'parity': next(parity), | 566 'parity': next(parity), |
568 'blockno': blockno, | 567 'blockno': blockno, |
569 'lines': prettyprintlines(lines, blockno), | 568 'lines': _prettyprintdifflines(web.tmpl, lines, blockno, |
569 lineidprefix), | |
570 }) | 570 }) |
571 | 571 |
572 def compare(tmpl, context, leftlines, rightlines): | 572 def compare(tmpl, context, leftlines, rightlines): |
573 '''Generator function that provides side-by-side comparison data.''' | 573 '''Generator function that provides side-by-side comparison data.''' |
574 | 574 |