diff --git a/rhodecode/lib/hooks.py b/rhodecode/lib/hooks.py --- a/rhodecode/lib/hooks.py +++ b/rhodecode/lib/hooks.py @@ -33,6 +33,33 @@ from rhodecode.lib.utils import action_l from inspect import isfunction +def _get_scm_size(alias, root_path): + + if not alias.startswith('.'): + alias += '.' + + size_scm, size_root = 0, 0 + for path, dirs, files in os.walk(root_path): + if path.find(alias) != -1: + for f in files: + try: + size_scm += os.path.getsize(os.path.join(path, f)) + except OSError: + pass + else: + for f in files: + try: + size_root += os.path.getsize(os.path.join(path, f)) + except OSError: + pass + + size_scm_f = h.format_byte_size(size_scm) + size_root_f = h.format_byte_size(size_root) + size_total_f = h.format_byte_size(size_root + size_scm) + + return size_scm_f, size_root_f, size_total_f + + def repo_size(ui, repo, hooktype=None, **kwargs): """ Presents size of repository after push @@ -42,24 +69,7 @@ def repo_size(ui, repo, hooktype=None, * :param hooktype: """ - size_hg, size_root = 0, 0 - for path, dirs, files in os.walk(repo.root): - if path.find('.hg') != -1: - for f in files: - try: - size_hg += os.path.getsize(os.path.join(path, f)) - except OSError: - pass - else: - for f in files: - try: - size_root += os.path.getsize(os.path.join(path, f)) - except OSError: - pass - - size_hg_f = h.format_byte_size(size_hg) - size_root_f = h.format_byte_size(size_root) - size_total_f = h.format_byte_size(size_root + size_hg) + size_hg_f, size_root_f, size_total_f = _get_scm_size('.hg', repo.root) last_cs = repo[len(repo) - 1]