##// END OF EJS Templates
hgweb: move getblock() closure out of compare()...
Yuya Nishihara -
r38009:53b0a51a default
parent child Browse files
Show More
@@ -591,45 +591,45 b' def _compline(tmpl, type, leftlineno, le'
591 'rightline': rightline or '',
591 'rightline': rightline or '',
592 })
592 })
593
593
594 def compare(tmpl, context, leftlines, rightlines):
594 def _getcompblock(tmpl, leftlines, rightlines, opcodes):
595 '''Generator function that provides side-by-side comparison data.'''
595 for type, llo, lhi, rlo, rhi in opcodes:
596
596 len1 = lhi - llo
597 def getblock(opcodes):
597 len2 = rhi - rlo
598 for type, llo, lhi, rlo, rhi in opcodes:
598 count = min(len1, len2)
599 len1 = lhi - llo
599 for i in xrange(count):
600 len2 = rhi - rlo
600 yield _compline(tmpl,
601 count = min(len1, len2)
601 type=type,
602 for i in xrange(count):
602 leftlineno=llo + i + 1,
603 leftline=leftlines[llo + i],
604 rightlineno=rlo + i + 1,
605 rightline=rightlines[rlo + i])
606 if len1 > len2:
607 for i in xrange(llo + count, lhi):
603 yield _compline(tmpl,
608 yield _compline(tmpl,
604 type=type,
609 type=type,
605 leftlineno=llo + i + 1,
610 leftlineno=i + 1,
606 leftline=leftlines[llo + i],
611 leftline=leftlines[i],
607 rightlineno=rlo + i + 1,
612 rightlineno=None,
608 rightline=rightlines[rlo + i])
613 rightline=None)
609 if len1 > len2:
614 elif len2 > len1:
610 for i in xrange(llo + count, lhi):
615 for i in xrange(rlo + count, rhi):
611 yield _compline(tmpl,
616 yield _compline(tmpl,
612 type=type,
617 type=type,
613 leftlineno=i + 1,
618 leftlineno=None,
614 leftline=leftlines[i],
619 leftline=None,
615 rightlineno=None,
620 rightlineno=i + 1,
616 rightline=None)
621 rightline=rightlines[i])
617 elif len2 > len1:
618 for i in xrange(rlo + count, rhi):
619 yield _compline(tmpl,
620 type=type,
621 leftlineno=None,
622 leftline=None,
623 rightlineno=i + 1,
624 rightline=rightlines[i])
625
622
623 def compare(tmpl, context, leftlines, rightlines):
624 '''Generator function that provides side-by-side comparison data.'''
626 s = difflib.SequenceMatcher(None, leftlines, rightlines)
625 s = difflib.SequenceMatcher(None, leftlines, rightlines)
627 if context < 0:
626 if context < 0:
628 yield tmpl.generate('comparisonblock',
627 l = _getcompblock(tmpl, leftlines, rightlines, s.get_opcodes())
629 {'lines': getblock(s.get_opcodes())})
628 yield tmpl.generate('comparisonblock', {'lines': l})
630 else:
629 else:
631 for oc in s.get_grouped_opcodes(n=context):
630 for oc in s.get_grouped_opcodes(n=context):
632 yield tmpl.generate('comparisonblock', {'lines': getblock(oc)})
631 l = _getcompblock(tmpl, leftlines, rightlines, oc)
632 yield tmpl.generate('comparisonblock', {'lines': l})
633
633
634 def diffstatgen(ctx, basectx):
634 def diffstatgen(ctx, basectx):
635 '''Generator function that provides the diffstat data.'''
635 '''Generator function that provides the diffstat data.'''
General Comments 0
You need to be logged in to leave comments. Login now