summaryrefslogtreecommitdiff
path: root/morphlib/sysbranchdir.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2013-09-16 17:06:47 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2013-09-17 14:32:37 +0000
commit0fc54dcc96b52f97c1e270f079fc7bf1bc0abd2b (patch)
treed235e3705ecb049c387d6ae928bdb9d538817edc /morphlib/sysbranchdir.py
parent86209e1f346fd24119f31872b589a70533523585 (diff)
downloadmorph-0fc54dcc96b52f97c1e270f079fc7bf1bc0abd2b.tar.gz
util: add find_leaves() supplimenting find_leaf()
The workspace needs to be able to list all its system branches, and the system branches need to be able to list all their git repositories. This is broadly the same thing, just with a different directory to look out for, so provide that utility in morphlib.util. find_leaf() is rewritten to use find_leaves(), this is less efficient since it waits until every leaf is found. I felt it was better to reduce the code than maintain a slightly more optimal algorithm. The find_leaf() algorithm could become more optimal if it could lazily check for at least one result in a generator.
Diffstat (limited to 'morphlib/sysbranchdir.py')
-rw-r--r--morphlib/sysbranchdir.py10
1 files changed, 3 insertions, 7 deletions
diff --git a/morphlib/sysbranchdir.py b/morphlib/sysbranchdir.py
index 0b3c859a..a05ca52e 100644
--- a/morphlib/sysbranchdir.py
+++ b/morphlib/sysbranchdir.py
@@ -156,13 +156,9 @@ class SystemBranchDirectory(object):
'''
- gitdirs = []
- for dirname, subdirs, filenames in os.walk(self.root_directory):
- if os.path.isdir(os.path.join(dirname, '.git')):
- del subdirs[:]
- gitdirs.append(morphlib.gitdir.GitDirectory(dirname))
-
- return gitdirs
+ return (morphlib.gitdir.GitDirectory(dirname)
+ for dirname in
+ morphlib.util.find_leaves(self.root_directory, '.git'))
def create(root_directory, root_repository_url, system_branch_name):