0fb6828cf5d24535b1b69a542367fac2e540bb36
[jelmer/gitpython.git] / lib / git / stats.py
1 class Stats(object):
2     def __init__(self, repo, total, files):
3         self.repo = repo
4         self.total = total
5         self.files = files
6
7     @classmethod
8     def list_from_string(cls, repo, text):
9         hsh = {'total': {'insertions': 0, 'deletions': 0, 'lines': 0, 'files': 0}, 'files': {}}
10         for line in text.splitlines():
11             (insertions, deletions, filename) = line.split("\t")
12             hsh['total']['insertions'] += insertions != '-' and int(insertions) or 0
13             hsh['total']['deletions'] += deleteions != '-' and int(deletions) or 0
14             hsh['total']['lines'] = (hsh['total']['deletions'] + hsh['total']['insertions'])
15             hsh['total']['files'] += 1
16             hsh['files'][filename.strip()] = {'insertions': int(insertions), 'deletions': int(deletions)}
17         return Stats(repo, hsh['total'], hsh['files'])