summaryrefslogtreecommitdiff
path: root/morphlib/plugins/artifact_inspection_plugin.py
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2016-03-02 17:11:34 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2016-03-16 19:11:21 +0000
commitd58d8e8f7a4ec03ff14021a4515c8283dad52573 (patch)
tree5ece2d0524e4423bb953e6140831c9fde93b7219 /morphlib/plugins/artifact_inspection_plugin.py
parent014a029ade9a045a839ca86c35690b218098ea33 (diff)
downloadmorph-d58d8e8f7a4ec03ff14021a4515c8283dad52573.tar.gz
Unify local and remote repo cache modules
There's not really any reason you'd want to use the RemoteRepoCache class except as a workaround for the slow speed of some LocalRepoCache operations, so I can't see this ruining anyone's day. The main reason for doing this is so we can simply the sourceresolver code. One reason that the sourceresolver class is so hopelessly complicated is that it right now has to use two incompatible interfaces for Git repo caches. I've taken the opportunity to detangle the RepoCache class from the App class. Now all of the configuration for the RepoCache class is passed into the constructor explicitly. This makes the class usable from outside Morph: resolver = morphlib.repoaliasresolver.RepoAliasResolver(aliases=[]) repo_cache = morphlib.repocache.RepoCache('/src/cache/gits', resolver) Change-Id: I596c81d7645b67504c88e555172a8c238f4f8a66
Diffstat (limited to 'morphlib/plugins/artifact_inspection_plugin.py')
-rw-r--r--morphlib/plugins/artifact_inspection_plugin.py37
1 files changed, 14 insertions, 23 deletions
diff --git a/morphlib/plugins/artifact_inspection_plugin.py b/morphlib/plugins/artifact_inspection_plugin.py
index 413a0072..d396f93b 100644
--- a/morphlib/plugins/artifact_inspection_plugin.py
+++ b/morphlib/plugins/artifact_inspection_plugin.py
@@ -36,28 +36,23 @@ class NotASystemArtifactError(cliapp.AppException):
class ProjectVersionGuesser(object):
- def __init__(self, app, lrc, rrc, interesting_files):
+ def __init__(self, app, repo_cache, interesting_files):
self.app = app
- self.lrc = lrc
- self.rrc = rrc
+ self.repo_cache = repo_cache
self.interesting_files = interesting_files
def file_contents(self, repo, ref, tree):
filenames = [x for x in self.interesting_files if x in tree]
- if filenames:
- if self.lrc.has_repo(repo):
- repository = self.lrc.get_updated_repo(repo, ref)
- for filename in filenames:
- yield filename, repository.read_file(filename, ref)
- elif self.rrc:
- for filename in filenames:
- yield filename, self.rrc.cat_file(repo, ref, filename)
+ for filename in filenames:
+ # This can use a remote repo cache if available, to avoid having
+ # to clone every repo locally.
+ yield filename, self.repo_cache.cat_file(repo, ref, filename)
class AutotoolsVersionGuesser(ProjectVersionGuesser):
- def __init__(self, app, lrc, rrc):
- ProjectVersionGuesser.__init__(self, app, lrc, rrc, [
+ def __init__(self, app, repo_cache):
+ ProjectVersionGuesser.__init__(self, app, repo_cache, [
'configure.ac',
'configure.in',
'configure.ac.in',
@@ -136,9 +131,9 @@ class VersionGuesser(object):
def __init__(self, app):
self.app = app
- self.lrc, self.rrc = morphlib.util.new_repo_caches(app)
+ self.repo_cache = morphlib.util.new_repo_cache(app)
self.guessers = [
- AutotoolsVersionGuesser(app, self.lrc, self.rrc)
+ AutotoolsVersionGuesser(app, self.repo_cache)
]
def guess_version(self, repo, ref):
@@ -146,14 +141,10 @@ class VersionGuesser(object):
repo=repo, ref=ref, chatty=True)
version = None
try:
- if self.lrc.has_repo(repo):
- repository = self.lrc.get_updated_repo(repo, ref)
- tree = repository.list_files(ref=ref, recurse=False)
- elif self.rrc:
- repository = None
- tree = self.rrc.ls_tree(repo, ref)
- else:
- return None
+ # This can use a remote repo cache if available, to avoid having
+ # to clone every repo locally.
+ tree = self.repo_cache.ls_tree(repo, ref)
+
for guesser in self.guessers:
version = guesser.guess_version(repo, ref, tree)
if version: