scripts: add a script to find hg repos efficiently
authorGregory Szorc <gps@mozilla.com>
Fri, 19 Dec 2014 11:56:20 -0800
changeset 360005 56cf093e516b7285c9c44be42ee392d54d58b62f
parent 360004 66e4e215fcea90984ba30c917644565bd7ee53c2
child 360006 263a686f854a12f7bb2ff721dfc0fbef9c8608ad
push id16998
push userrwood@mozilla.com
push dateMon, 02 May 2016 19:42:03 +0000
scripts: add a script to find hg repos efficiently
scripts/find-hg-repos.py
new file mode 100755
--- /dev/null
+++ b/scripts/find-hg-repos.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+"""Find Mercurial repositories under a specified path."""
+
+import os
+import sys
+
+def find_hg_repos(path):
+    for root, dirs, files in os.walk(path):
+        for d in dirs:
+            if d == '.hg':
+                yield root
+
+        dirs[:] = [d for d in dirs if d != '.hg']
+
+if __name__ == '__main__':
+    if len(sys.argv) == 1:
+        print('usage: %s dir0 [dir1] ...')
+        sys.exit(1)
+
+    for d in sys.argv[1:]:
+        for path in find_hg_repos(d):
+            print(path)