Show More
@@ -607,27 +607,32 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 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 | def lines(self, count_empty=False): |
|
630 | def lines(self, count_empty=False): | |
611 | all_lines, empty_lines = 0, 0 |
|
631 | all_lines, empty_lines = 0, 0 | |
612 |
|
632 | |||
613 | if not self.is_binary: |
|
633 | if not self.is_binary: | |
614 | content = self.content |
|
634 | content = self.content | |
615 | if count_empty: |
|
635 | all_lines, empty_lines = self.count_lines(content, count_empty=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 |
|
||||
631 | return all_lines, empty_lines |
|
636 | return all_lines, empty_lines | |
632 |
|
637 | |||
633 | def __repr__(self): |
|
638 | def __repr__(self): |
@@ -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