##// END OF EJS Templates
hgweb: convert comparison {lines} to a mappinggenerator with named template...
Yuya Nishihara -
r38010:c0ccbf4f default
parent child Browse files
Show More
@@ -575,12 +575,12 b' def diffs(web, ctx, basectx, files, styl'
575 linerange, lineidprefix)
575 linerange, lineidprefix)
576 return templateutil.mappinggenerator(_diffsgen, args=args, name='diffblock')
576 return templateutil.mappinggenerator(_diffsgen, args=args, name='diffblock')
577
577
578 def _compline(tmpl, type, leftlineno, leftline, rightlineno, rightline):
578 def _compline(type, leftlineno, leftline, rightlineno, rightline):
579 lineid = leftlineno and ("l%d" % leftlineno) or ''
579 lineid = leftlineno and ("l%d" % leftlineno) or ''
580 lineid += rightlineno and ("r%d" % rightlineno) or ''
580 lineid += rightlineno and ("r%d" % rightlineno) or ''
581 llno = '%d' % leftlineno if leftlineno else ''
581 llno = '%d' % leftlineno if leftlineno else ''
582 rlno = '%d' % rightlineno if rightlineno else ''
582 rlno = '%d' % rightlineno if rightlineno else ''
583 return tmpl.generate('comparisonline', {
583 return {
584 'type': type,
584 'type': type,
585 'lineid': lineid,
585 'lineid': lineid,
586 'leftlineno': leftlineno,
586 'leftlineno': leftlineno,
@@ -589,46 +589,48 b' def _compline(tmpl, type, leftlineno, le'
589 'rightlineno': rightlineno,
589 'rightlineno': rightlineno,
590 'rightlinenumber': "% 6s" % rlno,
590 'rightlinenumber': "% 6s" % rlno,
591 'rightline': rightline or '',
591 'rightline': rightline or '',
592 })
592 }
593
593
594 def _getcompblock(tmpl, leftlines, rightlines, opcodes):
594 def _getcompblockgen(context, leftlines, rightlines, opcodes):
595 for type, llo, lhi, rlo, rhi in opcodes:
595 for type, llo, lhi, rlo, rhi in opcodes:
596 len1 = lhi - llo
596 len1 = lhi - llo
597 len2 = rhi - rlo
597 len2 = rhi - rlo
598 count = min(len1, len2)
598 count = min(len1, len2)
599 for i in xrange(count):
599 for i in xrange(count):
600 yield _compline(tmpl,
600 yield _compline(type=type,
601 type=type,
602 leftlineno=llo + i + 1,
601 leftlineno=llo + i + 1,
603 leftline=leftlines[llo + i],
602 leftline=leftlines[llo + i],
604 rightlineno=rlo + i + 1,
603 rightlineno=rlo + i + 1,
605 rightline=rightlines[rlo + i])
604 rightline=rightlines[rlo + i])
606 if len1 > len2:
605 if len1 > len2:
607 for i in xrange(llo + count, lhi):
606 for i in xrange(llo + count, lhi):
608 yield _compline(tmpl,
607 yield _compline(type=type,
609 type=type,
610 leftlineno=i + 1,
608 leftlineno=i + 1,
611 leftline=leftlines[i],
609 leftline=leftlines[i],
612 rightlineno=None,
610 rightlineno=None,
613 rightline=None)
611 rightline=None)
614 elif len2 > len1:
612 elif len2 > len1:
615 for i in xrange(rlo + count, rhi):
613 for i in xrange(rlo + count, rhi):
616 yield _compline(tmpl,
614 yield _compline(type=type,
617 type=type,
618 leftlineno=None,
615 leftlineno=None,
619 leftline=None,
616 leftline=None,
620 rightlineno=i + 1,
617 rightlineno=i + 1,
621 rightline=rightlines[i])
618 rightline=rightlines[i])
622
619
620 def _getcompblock(leftlines, rightlines, opcodes):
621 args = (leftlines, rightlines, opcodes)
622 return templateutil.mappinggenerator(_getcompblockgen, args=args,
623 name='comparisonline')
624
623 def compare(tmpl, context, leftlines, rightlines):
625 def compare(tmpl, context, leftlines, rightlines):
624 '''Generator function that provides side-by-side comparison data.'''
626 '''Generator function that provides side-by-side comparison data.'''
625 s = difflib.SequenceMatcher(None, leftlines, rightlines)
627 s = difflib.SequenceMatcher(None, leftlines, rightlines)
626 if context < 0:
628 if context < 0:
627 l = _getcompblock(tmpl, leftlines, rightlines, s.get_opcodes())
629 l = _getcompblock(leftlines, rightlines, s.get_opcodes())
628 yield tmpl.generate('comparisonblock', {'lines': l})
630 yield tmpl.generate('comparisonblock', {'lines': l})
629 else:
631 else:
630 for oc in s.get_grouped_opcodes(n=context):
632 for oc in s.get_grouped_opcodes(n=context):
631 l = _getcompblock(tmpl, leftlines, rightlines, oc)
633 l = _getcompblock(leftlines, rightlines, oc)
632 yield tmpl.generate('comparisonblock', {'lines': l})
634 yield tmpl.generate('comparisonblock', {'lines': l})
633
635
634 def diffstatgen(ctx, basectx):
636 def diffstatgen(ctx, basectx):
General Comments 0
You need to be logged in to leave comments. Login now