diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2012-04-20 12:22:30 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2012-04-20 12:26:15 +0000 |
commit | 29495567ce1787e426687d7d59653874e2efdcf4 (patch) | |
tree | 8615b9b52d10bdad6badd48b32aa555da07ca1a3 /morphlib/morphologyfactory.py | |
parent | c84b5c726509c07c3a1803121cb21046a7987ac7 (diff) | |
download | morph-29495567ce1787e426687d7d59653874e2efdcf4.tar.gz |
morphologyfactory: infer build system without list
Detecting the build system is managed by it asking if any files exist
detecting if the file exists is done with a callback function.
This callback can use cat-file.
If list_files existed this could be more efficient as it would not
require the files to be read from the remote server and it only needs
to be one round-trip
Diffstat (limited to 'morphlib/morphologyfactory.py')
-rw-r--r-- | morphlib/morphologyfactory.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/morphlib/morphologyfactory.py b/morphlib/morphologyfactory.py index e7ee9323..6f9915fb 100644 --- a/morphlib/morphologyfactory.py +++ b/morphlib/morphologyfactory.py @@ -57,14 +57,25 @@ 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) - files = repo.list_files(sha1) + def has_file(filename): + try: + repo.cat(sha1, filename) + return True + except IOError: + return False elif self._rrc is not None: - files = self._rrc.list_files(reponame, sha1) + def has_file(filename): + try: + text = self._rrc.cat_file(reponame, sha1, filename) + return True + except morphlib.remoterepocache.CatFileError: + return False else: raise NotcachedError(reponame) - bs = morphlib.buildsystem.detect_build_system(lambda x: x in files) + bs = morphlib.buildsystem.detect_build_system(has_file) if bs is None: raise AutodetectError(reponame, sha1) # TODO consider changing how morphs are located to be by morph |