# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1548361705 18000
#      Thu Jan 24 15:28:25 2019 -0500
# Node ID 20a9a4d5c6b96607b1d2b1936b8eb1fcaad09ff5
# Parent  2e0076fa9c33b4d4a8283dd1dd90554492c78b76
Extract repo stats gathering in its own function

diff --git a/repo-scripts/make-reference b/repo-scripts/make-reference
--- a/repo-scripts/make-reference
+++ b/repo-scripts/make-reference
@@ -13,6 +13,47 @@
 import yaml
 
 
+def gather_repo_stats(repo, repo_id, repo_source):
+    """ Gather repo related stats
+    """
+    hgversion = shell_exec(["hg", "version", "-T", "{ver}"])
+
+    numrevs = count_line_exec(["hg", "-R", repo, "log", "-T", "{rev}\n"])
+    numrevshidden = count_line_exec(
+        ["hg", "-R", repo, "--hidden", "log", "-T", "{rev}\n"]
+    )
+
+    numheads = count_line_exec(
+        ["hg", "-R", repo, "heads", "-t", "-T", "{rev}\n"]
+    )
+    numheadshidden = count_line_exec(
+        ["hg", "-R", repo, "--hidden", "heads", "-t", "-T", "{rev}\n"]
+    )
+
+    numbranches = count_line_exec(
+        ["hg", "-R", repo, "branches", "-c", "-T", "{rev}\n"]
+    )
+    numbrancheshidden = count_line_exec(
+        ["hg", "-R", repo, "--hidden", "branches", "-c", "-T", "{rev}\n"]
+    )
+
+    # Generate YAML file
+    return {
+        "reference-repo": {
+            "id": repo_id,
+            "enabled": True,
+            "source": repo_source,
+            "hg-version": hgversion,
+            "number-revisions": {"visible": numrevs, "all": numrevshidden},
+            "number-heads": {"visible": numheads, "all": numheadshidden},
+            "number-named-branch": {
+                "visible": numbranches,
+                "all": numbrancheshidden,
+            },
+        }
+    }
+
+
 def shell_exec(command, env=None):
     # Simulate bash script printing the commands it runs
     process = subprocess.Popen(
@@ -64,42 +105,7 @@
     shell_exec(["hg", "-R", repo_main, "debugupdatecache"])
 
     ### Compute stats
-    hgversion = shell_exec(["hg", "version", "-T", "{ver}"])
-
-    numrevs = count_line_exec(["hg", "-R", repo_main, "log", "-T", "{rev}\n"])
-    numrevshidden = count_line_exec(
-        ["hg", "-R", repo_main, "--hidden", "log", "-T", "{rev}\n"]
-    )
-
-    numheads = count_line_exec(
-        ["hg", "-R", repo_main, "heads", "-t", "-T", "{rev}\n"]
-    )
-    numheadshidden = count_line_exec(
-        ["hg", "-R", repo_main, "--hidden", "heads", "-t", "-T", "{rev}\n"]
-    )
-
-    numbranches = count_line_exec(
-        ["hg", "-R", repo_main, "branches", "-c", "-T", "{rev}\n"]
-    )
-    numbrancheshidden = count_line_exec(
-        ["hg", "-R", repo_main, "--hidden", "branches", "-c", "-T", "{rev}\n"]
-    )
-
-    # Generate YAML file
-    data = {
-        "reference-repo": {
-            "id": repo_id,
-            "enabled": True,
-            "source": repo_source,
-            "hg-version": hgversion,
-            "number-revisions": {"visible": numrevs, "all": numrevshidden},
-            "number-heads": {"visible": numheads, "all": numheadshidden},
-            "number-named-branch": {
-                "visible": numbranches,
-                "all": numbrancheshidden,
-            },
-        }
-    }
+    data = gather_repo_stats(repo_main, repo_id, repo_source)
 
     # Write data to the benchrepo file
     with open(repo_details, "w") as repo_details_file: