diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-08-24 17:58:42 +0100 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-08-24 17:58:42 +0100 |
commit | 98b802e36b2a291b39dbdb83b55546b1acae1573 (patch) | |
tree | a6579f891f29f15a7b8b7c94ea3847cc66ad5428 /morphlib/morphologyfactory.py | |
parent | 975b3f30605c36a714bf5b9619817a897cb6a4a3 (diff) | |
download | morph-98b802e36b2a291b39dbdb83b55546b1acae1573.tar.gz |
Use git ls-tree to autodetect build system
The cost of one git ls-tree call is roughly the same as one
git cat-file call. Therefore, when autodetecting the build system,
it is much faster to list the tree once and then search for the
required files than to call git cat-file for every possible one.
Diffstat (limited to 'morphlib/morphologyfactory.py')
-rw-r--r-- | morphlib/morphologyfactory.py | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/morphlib/morphologyfactory.py b/morphlib/morphologyfactory.py index 89288b33..c03d541e 100644 --- a/morphlib/morphologyfactory.py +++ b/morphlib/morphologyfactory.py @@ -72,26 +72,15 @@ class MorphologyFactory(object): raise NotcachedError(reponame) def _autodetect_text(self, reponame, sha1, filename): - # TODO get lists of files from the cache to reduce round trips if self._lrc.has_repo(reponame): repo = self._lrc.get_repo(reponame) - - def has_file(filename): - try: - repo.cat(sha1, filename) - return True - except IOError: - return False + file_list = repo.ls_tree(sha1) elif self._rrc is not None: - def has_file(filename): - try: - text = self._rrc.cat_file(reponame, sha1, filename) - return True - except morphlib.remoterepocache.CatFileError: - return False + file_list = self._rrc.ls_tree(reponame, sha1) else: raise NotcachedError(reponame) - bs = morphlib.buildsystem.detect_build_system(has_file) + + bs = morphlib.buildsystem.detect_build_system(file_list) if bs is None: raise AutodetectError(reponame, sha1) # TODO consider changing how morphs are located to be by morph |