From 532af11d11003d52fc79cd4719f2b3353640a38b Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Fri, 20 Feb 2015 11:33:21 +0000 Subject: sourceresolver: Never assume that a given ref is present locally Checking that a given ref exists using `git rev-parse --verify 1234^{commit}` is a reasonably quick operation. As a rough guide, 1000 invocations took 1.6 seconds on my PC. The code is too fragile and hard to reason about if we assume that one function has been called before another so the repo will already be up to date. This should fix any spurious InvalidRefError exceptions that the build graph speedups branch has introduced. --- morphlib/sourceresolver.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/morphlib/sourceresolver.py b/morphlib/sourceresolver.py index e84a6cd2..22e643d2 100644 --- a/morphlib/sourceresolver.py +++ b/morphlib/sourceresolver.py @@ -239,11 +239,10 @@ class SourceResolver(object): morph = loader.load_from_string(text) except morphlib.remoterepocache.CatFileError: morph = None - else: - # We assume that _resolve_ref() must have already been called and - # so the repo in question would have been made available already - # if it had been possible. - raise NotcachedError(reponame) + else: # pragma: no cover + repo = self.cache_repo_locally(reponame) + text = repo.read_file(filename, sha1) + morph = loader.load_from_string(text) return morph @@ -295,7 +294,10 @@ class SourceResolver(object): if self.lrc.has_repo(reponame): repo = self.lrc.get_repo(reponame) - file_list = repo.list_files(ref=sha1, recurse=False) + try: + file_list = repo.list_files(ref=sha1, recurse=False) + except morphlib.gitdir.InvalidRefError: # pragma: no cover + pass elif self.rrc is not None: try: # This may or may not succeed; if the is repo not -- cgit v1.2.1