##// END OF EJS Templates
diffs: fixed problem with potential diff display.
milka -
r4592:8ef51af3 stable
parent child Browse files
Show More
@@ -398,7 +398,10 b' class DiffSet(object):'
398 ):
398 ):
399
399
400 self.highlight_mode = highlight_mode
400 self.highlight_mode = highlight_mode
401 self.highlighted_filenodes = {}
401 self.highlighted_filenodes = {
402 'before': {},
403 'after': {}
404 }
402 self.source_node_getter = source_node_getter
405 self.source_node_getter = source_node_getter
403 self.target_node_getter = target_node_getter
406 self.target_node_getter = target_node_getter
404 self.source_nodes = source_nodes or {}
407 self.source_nodes = source_nodes or {}
@@ -657,7 +660,7 b' class DiffSet(object):'
657 else:
660 else:
658 before_tokens = self.get_line_tokens(
661 before_tokens = self.get_line_tokens(
659 line_text=before['line'], line_number=before['old_lineno'],
662 line_text=before['line'], line_number=before['old_lineno'],
660 input_file=source_file, no_hl=no_hl)
663 input_file=source_file, no_hl=no_hl, source='before')
661 original.lineno = before['old_lineno']
664 original.lineno = before['old_lineno']
662 original.content = before['line']
665 original.content = before['line']
663 original.action = self.action_to_op(before['action'])
666 original.action = self.action_to_op(before['action'])
@@ -671,7 +674,7 b' class DiffSet(object):'
671 else:
674 else:
672 after_tokens = self.get_line_tokens(
675 after_tokens = self.get_line_tokens(
673 line_text=after['line'], line_number=after['new_lineno'],
676 line_text=after['line'], line_number=after['new_lineno'],
674 input_file=target_file, no_hl=no_hl)
677 input_file=target_file, no_hl=no_hl, source='after')
675 modified.lineno = after['new_lineno']
678 modified.lineno = after['new_lineno']
676 modified.content = after['line']
679 modified.content = after['line']
677 modified.action = self.action_to_op(after['action'])
680 modified.action = self.action_to_op(after['action'])
@@ -705,7 +708,7 b' class DiffSet(object):'
705
708
706 return lines
709 return lines
707
710
708 def get_line_tokens(self, line_text, line_number, input_file=None, no_hl=False):
711 def get_line_tokens(self, line_text, line_number, input_file=None, no_hl=False, source=''):
709 filenode = None
712 filenode = None
710 filename = None
713 filename = None
711
714
@@ -720,8 +723,7 b' class DiffSet(object):'
720 lexer = self._get_lexer_for_filename(filename)
723 lexer = self._get_lexer_for_filename(filename)
721 file_size_allowed = input_file.size < self.max_file_size_limit
724 file_size_allowed = input_file.size < self.max_file_size_limit
722 if line_number and file_size_allowed:
725 if line_number and file_size_allowed:
723 return self.get_tokenized_filenode_line(
726 return self.get_tokenized_filenode_line(input_file, line_number, lexer, source)
724 input_file, line_number, lexer)
725
727
726 if hl_mode in (self.HL_REAL, self.HL_FAST) and filename:
728 if hl_mode in (self.HL_REAL, self.HL_FAST) and filename:
727 lexer = self._get_lexer_for_filename(filename)
729 lexer = self._get_lexer_for_filename(filename)
@@ -729,17 +731,19 b' class DiffSet(object):'
729
731
730 return list(tokenize_string(line_text, plain_text_lexer))
732 return list(tokenize_string(line_text, plain_text_lexer))
731
733
732 def get_tokenized_filenode_line(self, filenode, line_number, lexer=None):
734 def get_tokenized_filenode_line(self, filenode, line_number, lexer=None, source=''):
733
735
734 if filenode not in self.highlighted_filenodes:
736 def tokenize(_filenode):
735 tokenized_lines = filenode_as_lines_tokens(filenode, lexer)
737 self.highlighted_filenodes[source][filenode] = filenode_as_lines_tokens(filenode, lexer)
736 self.highlighted_filenodes[filenode] = tokenized_lines
738
739 if filenode not in self.highlighted_filenodes[source]:
740 tokenize(filenode)
737
741
738 try:
742 try:
739 return self.highlighted_filenodes[filenode][line_number - 1]
743 return self.highlighted_filenodes[source][filenode][line_number - 1]
740 except Exception:
744 except Exception:
741 log.exception('diff rendering error')
745 log.exception('diff rendering error')
742 return [('', u'rhodecode diff rendering error')]
746 return [('', u'L{}: rhodecode diff rendering error'.format(line_number))]
743
747
744 def action_to_op(self, action):
748 def action_to_op(self, action):
745 return {
749 return {
General Comments 0
You need to be logged in to leave comments. Login now