|
14 | 14 |
|
15 | 15 | import datetime
|
16 | 16 | import os
|
| 17 | +import io |
17 | 18 | import re
|
18 | 19 | from operator import itemgetter
|
19 | 20 |
|
@@ -115,26 +116,32 @@ def _build_commit_map(self, session):
|
115 | 116 | if db_detail.test_count:
|
116 | 117 | self._shas_to_commits[db_detail.commit_id].test_counts[db_detail.author] = db_detail.test_count
|
117 | 118 |
|
| 119 | + def _process_lines_into_line_counts(self, repository, commit, path, lines, line_counts, test_counts): |
| 120 | + is_test_file = _is_test_file(repository.configuration, path) |
| 121 | + author = self._names_to_authors[_author_line(commit)] |
| 122 | + line_counts[author] = line_counts.get(author, 0) + len(lines) |
| 123 | + if is_test_file: |
| 124 | + for line in lines: |
| 125 | + if re.search(repository.test_line_regex, line): |
| 126 | + test_counts[author] = test_counts.get(author, 0) + 1 |
| 127 | + |
118 | 128 | def _blame_blob_into_line_counts(self, repository, commit_to_blame, path, line_counts, test_counts):
|
119 | 129 | if not _is_source_file(repository.configuration, path):
|
120 | 130 | return
|
121 |
| - is_test_file = _is_test_file(repository.configuration, path) |
122 | 131 | blame = repository.git_repository.blame(commit_to_blame, path, w=True)
|
123 | 132 | for commit, lines in blame:
|
124 |
| - author = self._names_to_authors[_author_line(commit)] |
125 |
| - line_counts[author] = line_counts.get(author, 0) + len(lines) |
126 |
| - if is_test_file: |
127 |
| - for line in lines: |
128 |
| - if re.search(repository.test_line_regex, line): |
129 |
| - test_counts[author] = test_counts.get(author, 0) + 1 |
| 133 | + self._process_lines_into_line_counts(repository, commit, path, lines, line_counts, test_counts) |
130 | 134 |
|
131 | 135 | def _make_full_commit_stats(self, repository, commit):
|
132 | 136 | line_counts = {}
|
133 | 137 | test_counts = {}
|
134 | 138 | for git_object in commit.tree.traverse(visit_once=True):
|
135 | 139 | if git_object.type != 'blob':
|
136 | 140 | continue
|
137 |
| - self._blame_blob_into_line_counts(repository, commit, git_object.path, line_counts, test_counts) |
| 141 | + if not _is_source_file(repository.configuration, git_object.path): |
| 142 | + continue |
| 143 | + lines = [line.decode('utf-8') for line in io.BytesIO(git_object.data_stream.read()).readlines()] |
| 144 | + self._process_lines_into_line_counts(repository, commit, git_object.path, lines, line_counts, test_counts) |
138 | 145 | return line_counts, test_counts
|
139 | 146 |
|
140 | 147 | def _make_diffed_commit_stats(self, repository, commit, previous_commit, previous_commit_line_counts,
|
|
0 commit comments