diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-02-20 11:33:21 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-02-20 13:48:43 +0000 |
commit | 532af11d11003d52fc79cd4719f2b3353640a38b (patch) | |
tree | 08a860175c86de915c8ca7d36dc09575f99a3534 | |
parent | 1d7e39b955f4da58230f9c5a06ff1b05f8bc020b (diff) | |
download | morph-532af11d11003d52fc79cd4719f2b3353640a38b.tar.gz |
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.
-rw-r--r-- | morphlib/sourceresolver.py | 14 |
1 files 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 |