##// END OF EJS Templates
nodes: expose line counts in node information. This would be used in full text search
marcink -
r3962:605faead default
parent child Browse files
Show More
@@ -607,11 +607,8 b' class FileNode(Node):'
607 if self.commit:
607 if self.commit:
608 return self.commit.get_largefile_node(self.path)
608 return self.commit.get_largefile_node(self.path)
609
609
610 def lines(self, count_empty=False):
610 def count_lines(self, content, count_empty=False):
611 all_lines, empty_lines = 0, 0
612
611
613 if not self.is_binary:
614 content = self.content
615 if count_empty:
612 if count_empty:
616 all_lines = 0
613 all_lines = 0
617 empty_lines = 0
614 empty_lines = 0
@@ -630,6 +627,14 b' class FileNode(Node):'
630
627
631 return all_lines, empty_lines
628 return all_lines, empty_lines
632
629
630 def lines(self, count_empty=False):
631 all_lines, empty_lines = 0, 0
632
633 if not self.is_binary:
634 content = self.content
635 all_lines, empty_lines = self.count_lines(content, count_empty=count_empty)
636 return all_lines, empty_lines
637
633 def __repr__(self):
638 def __repr__(self):
634 return '<%s %r @ %s>' % (self.__class__.__name__, self.path,
639 return '<%s %r @ %s>' % (self.__class__.__name__, self.path,
635 getattr(self.commit, 'short_id', ''))
640 getattr(self.commit, 'short_id', ''))
@@ -665,11 +665,14 b' class ScmModel(BaseModel):'
665 size = file_node.size
665 size = file_node.size
666 over_size_limit = (max_file_bytes is not None and size > max_file_bytes)
666 over_size_limit = (max_file_bytes is not None and size > max_file_bytes)
667 full_content = None
667 full_content = None
668 all_lines = 0
668 if not file_node.is_binary and not over_size_limit:
669 if not file_node.is_binary and not over_size_limit:
669 full_content = safe_unicode(file_node.content)
670 full_content = safe_unicode(file_node.content)
671 all_lines, empty_lines = file_node.count_lines(full_content)
670
672
671 file_data.update({
673 file_data.update({
672 "content": full_content,
674 "content": full_content,
675 "lines": all_lines
673 })
676 })
674 elif content:
677 elif content:
675 # get content *without* cache
678 # get content *without* cache
@@ -678,11 +681,14 b' class ScmModel(BaseModel):'
678
681
679 over_size_limit = (max_file_bytes is not None and size > max_file_bytes)
682 over_size_limit = (max_file_bytes is not None and size > max_file_bytes)
680 full_content = None
683 full_content = None
684 all_lines = 0
681 if not is_binary and not over_size_limit:
685 if not is_binary and not over_size_limit:
682 full_content = safe_unicode(_content)
686 full_content = safe_unicode(_content)
687 all_lines, empty_lines = file_node.count_lines(full_content)
683
688
684 file_data.update({
689 file_data.update({
685 "content": full_content,
690 "content": full_content,
691 "lines": all_lines
686 })
692 })
687
693
688 except RepositoryError:
694 except RepositoryError:
General Comments 0
You need to be logged in to leave comments. Login now