From 29495567ce1787e426687d7d59653874e2efdcf4 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Fri, 20 Apr 2012 12:22:30 +0000 Subject: 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 --- morphlib/morphologyfactory.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'morphlib/morphologyfactory.py') 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 -- cgit v1.2.1