Fix use of bare repositories.
[jelmer/gitpython.git] / lib / git / stats.py
1 # stats.py
2 # Copyright (C) 2008 Michael Trier (mtrier@gmail.com) and contributors
3 #
4 # This module is part of GitPython and is released under
5 # the BSD License: http://www.opensource.org/licenses/bsd-license.php
6
7 class Stats(object):
8     def __init__(self, repo, total, files):
9         self.repo = repo
10         self.total = total
11         self.files = files
12
13     @classmethod
14     def list_from_string(cls, repo, text):
15         hsh = {'total': {'insertions': 0, 'deletions': 0, 'lines': 0, 'files': 0}, 'files': {}}
16         for line in text.splitlines():
17             (raw_insertions, raw_deletions, filename) = line.split("\t")
18             insertions = raw_insertions != '-' and int(raw_insertions) or 0
19             deletions = raw_deletions != '-' and int(raw_deletions) or 0
20             hsh['total']['insertions'] += insertions
21             hsh['total']['deletions'] += deletions
22             hsh['total']['lines'] += insertions + deletions
23             hsh['total']['files'] += 1
24             hsh['files'][filename.strip()] = {'insertions': insertions,
25                                               'deletions': deletions,
26                                               'lines': insertions + deletions}
27         return Stats(repo, hsh['total'], hsh['files'])