fixed http://groups.google.com/group/git-python/browse_thread/thread/62b972d2345c74c2...
[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             (raw_insertions, raw_deletions, filename) = line.split("\t")
12             insertions = raw_insertions != '-' and int(raw_insertions) or 0
13             deletions = raw_deletions != '-' and int(raw_deletions) or 0
14             hsh['total']['insertions'] += insertions
15             hsh['total']['deletions'] += deletions
16             hsh['total']['lines'] = insertions + deletions
17             hsh['total']['files'] += 1
18             hsh['files'][filename.strip()] = {'insertions': insertions,
19                                               'deletions': deletions,
20                                               'lines': insertions + deletions}
21         return Stats(repo, hsh['total'], hsh['files'])