##// END OF EJS Templates
hgweb: move compline() closure out of compare()
Yuya Nishihara -
r38008:406f945c default
parent child Browse files
Show More
@@ -575,50 +575,53 b' def diffs(web, ctx, basectx, files, styl'
575 575 linerange, lineidprefix)
576 576 return templateutil.mappinggenerator(_diffsgen, args=args, name='diffblock')
577 577
578 def _compline(tmpl, type, leftlineno, leftline, rightlineno, rightline):
579 lineid = leftlineno and ("l%d" % leftlineno) or ''
580 lineid += rightlineno and ("r%d" % rightlineno) or ''
581 llno = '%d' % leftlineno if leftlineno else ''
582 rlno = '%d' % rightlineno if rightlineno else ''
583 return tmpl.generate('comparisonline', {
584 'type': type,
585 'lineid': lineid,
586 'leftlineno': leftlineno,
587 'leftlinenumber': "% 6s" % llno,
588 'leftline': leftline or '',
589 'rightlineno': rightlineno,
590 'rightlinenumber': "% 6s" % rlno,
591 'rightline': rightline or '',
592 })
593
578 594 def compare(tmpl, context, leftlines, rightlines):
579 595 '''Generator function that provides side-by-side comparison data.'''
580 596
581 def compline(type, leftlineno, leftline, rightlineno, rightline):
582 lineid = leftlineno and ("l%d" % leftlineno) or ''
583 lineid += rightlineno and ("r%d" % rightlineno) or ''
584 llno = '%d' % leftlineno if leftlineno else ''
585 rlno = '%d' % rightlineno if rightlineno else ''
586 return tmpl.generate('comparisonline', {
587 'type': type,
588 'lineid': lineid,
589 'leftlineno': leftlineno,
590 'leftlinenumber': "% 6s" % llno,
591 'leftline': leftline or '',
592 'rightlineno': rightlineno,
593 'rightlinenumber': "% 6s" % rlno,
594 'rightline': rightline or '',
595 })
596
597 597 def getblock(opcodes):
598 598 for type, llo, lhi, rlo, rhi in opcodes:
599 599 len1 = lhi - llo
600 600 len2 = rhi - rlo
601 601 count = min(len1, len2)
602 602 for i in xrange(count):
603 yield compline(type=type,
604 leftlineno=llo + i + 1,
605 leftline=leftlines[llo + i],
606 rightlineno=rlo + i + 1,
607 rightline=rightlines[rlo + i])
603 yield _compline(tmpl,
604 type=type,
605 leftlineno=llo + i + 1,
606 leftline=leftlines[llo + i],
607 rightlineno=rlo + i + 1,
608 rightline=rightlines[rlo + i])
608 609 if len1 > len2:
609 610 for i in xrange(llo + count, lhi):
610 yield compline(type=type,
611 leftlineno=i + 1,
612 leftline=leftlines[i],
613 rightlineno=None,
614 rightline=None)
611 yield _compline(tmpl,
612 type=type,
613 leftlineno=i + 1,
614 leftline=leftlines[i],
615 rightlineno=None,
616 rightline=None)
615 617 elif len2 > len1:
616 618 for i in xrange(rlo + count, rhi):
617 yield compline(type=type,
618 leftlineno=None,
619 leftline=None,
620 rightlineno=i + 1,
621 rightline=rightlines[i])
619 yield _compline(tmpl,
620 type=type,
621 leftlineno=None,
622 leftline=None,
623 rightlineno=i + 1,
624 rightline=rightlines[i])
622 625
623 626 s = difflib.SequenceMatcher(None, leftlines, rightlines)
624 627 if context < 0:
General Comments 0
You need to be logged in to leave comments. Login now