Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dd2d126

Browse files
authored
Merge pull request #305 from IP1102/master
Cache the _stats function
2 parents 679f652 + 861eee1 commit dd2d126

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

pydriller/domain/commit.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ def __init__(self, commit: GitCommit, conf) -> None:
542542
"""
543543
self._c_object = commit
544544
self._conf = conf
545+
self._stats_cache = None
545546

546547
def __hash__(self) -> int:
547548
"""
@@ -688,6 +689,9 @@ def merge(self) -> bool:
688689
return len(self._c_object.parents) > 1
689690

690691
def _stats(self):
692+
if self._stats_cache is not None:
693+
return self._stats_cache
694+
691695
if len(self.parents) == 0:
692696
text = self._conf.get('git').repo.git.diff_tree(self.hash, "--", numstat=True, root=True)
693697
text2 = ""
@@ -698,7 +702,8 @@ def _stats(self):
698702
else:
699703
text = self._conf.get('git').repo.git.diff(self._c_object.parents[0].hexsha, self._c_object.hexsha, "--", numstat=True, root=True)
700704

701-
return self._list_from_string(text)
705+
self._stats_cache = self._list_from_string(text)
706+
return self._stats_cache
702707

703708
def _list_from_string(self, text: str):
704709
total = {"insertions": 0, "deletions": 0, "lines": 0, "files": 0}

0 commit comments

Comments
 (0)