##// 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,27 +607,32 b' class FileNode(Node):'
607 607 if self.commit:
608 608 return self.commit.get_largefile_node(self.path)
609 609
610 def count_lines(self, content, count_empty=False):
611
612 if count_empty:
613 all_lines = 0
614 empty_lines = 0
615 for line in content.splitlines(True):
616 if line == '\n':
617 empty_lines += 1
618 all_lines += 1
619
620 return all_lines, all_lines - empty_lines
621 else:
622 # fast method
623 empty_lines = all_lines = content.count('\n')
624 if all_lines == 0 and content:
625 # one-line without a newline
626 empty_lines = all_lines = 1
627
628 return all_lines, empty_lines
629
610 630 def lines(self, count_empty=False):
611 631 all_lines, empty_lines = 0, 0
612 632
613 633 if not self.is_binary:
614 634 content = self.content
615 if count_empty:
616 all_lines = 0
617 empty_lines = 0
618 for line in content.splitlines(True):
619 if line == '\n':
620 empty_lines += 1
621 all_lines += 1
622
623 return all_lines, all_lines - empty_lines
624 else:
625 # fast method
626 empty_lines = all_lines = content.count('\n')
627 if all_lines == 0 and content:
628 # one-line without a newline
629 empty_lines = all_lines = 1
630
635 all_lines, empty_lines = self.count_lines(content, count_empty=count_empty)
631 636 return all_lines, empty_lines
632 637
633 638 def __repr__(self):
@@ -665,11 +665,14 b' class ScmModel(BaseModel):'
665 665 size = file_node.size
666 666 over_size_limit = (max_file_bytes is not None and size > max_file_bytes)
667 667 full_content = None
668 all_lines = 0
668 669 if not file_node.is_binary and not over_size_limit:
669 670 full_content = safe_unicode(file_node.content)
671 all_lines, empty_lines = file_node.count_lines(full_content)
670 672
671 673 file_data.update({
672 674 "content": full_content,
675 "lines": all_lines
673 676 })
674 677 elif content:
675 678 # get content *without* cache
@@ -678,11 +681,14 b' class ScmModel(BaseModel):'
678 681
679 682 over_size_limit = (max_file_bytes is not None and size > max_file_bytes)
680 683 full_content = None
684 all_lines = 0
681 685 if not is_binary and not over_size_limit:
682 686 full_content = safe_unicode(_content)
687 all_lines, empty_lines = file_node.count_lines(full_content)
683 688
684 689 file_data.update({
685 690 "content": full_content,
691 "lines": all_lines
686 692 })
687 693
688 694 except RepositoryError:
General Comments 0
You need to be logged in to leave comments. Login now