Marcin Kuzminski avatar Marcin Kuzminski committed 7ccf403

made repo-size hook more generic

Comments (0)

Files changed (1)

rhodecode/lib/hooks.py

 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
     :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]
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.