diff options
-rw-r--r-- | morphlib/localrepocache.py | 56 | ||||
-rw-r--r-- | morphlib/localrepocache_tests.py | 6 |
2 files changed, 29 insertions, 33 deletions
diff --git a/morphlib/localrepocache.py b/morphlib/localrepocache.py index 4fb82a3b..942c057a 100644 --- a/morphlib/localrepocache.py +++ b/morphlib/localrepocache.py @@ -178,14 +178,6 @@ class LocalRepoCache(object): path = os.path.join(self._cachedir, basename) return path - def _base_iterate(self, reponame): - for baseurl in self._baseurls: - if not baseurl.endswith('/'): - baseurl += '/' # pragma: no cover - repourl = urlparse.urljoin(baseurl, reponame) - path = self._cache_name(repourl) - yield repourl, path - def _split_reponame(self, reponame): '''Split reponame into prefix and suffix. @@ -232,10 +224,9 @@ class LocalRepoCache(object): def has_repo(self, reponame): '''Have we already got a cache of a given repo?''' - for repourl, path in self._base_iterate(reponame): - if self._exists(path): - return True - return False + url = self.pull_url(reponame) + path = self._cache_name(url) + return self._exists(path) def _clone_with_bundle(self, repourl, path): escaped = self._escape(repourl) @@ -276,22 +267,21 @@ class LocalRepoCache(object): pass if self._bundle_base_url: - for repourl, path in self._base_iterate(reponame): - ok, error = self._clone_with_bundle(repourl, path) - if ok: - return self.get_repo(reponame) - else: - errors.append(error) - - for repourl, path in self._base_iterate(reponame): - try: - self._git(['clone', '-n', repourl, path]) - except morphlib.execute.CommandFailure, e: - errors.append('Unable to clone from %s to %s: %s' % - (repourl, path, e)) + repourl = self.pull_url(reponame) + path = self._cache_name(repourl) + ok, error = self._clone_with_bundle(repourl, path) + if ok: + return self.get_repo(reponame) else: - break - else: + errors.append(error) + + repourl = self.pull_url(reponame) + path = self._cache_name(repourl) + try: + self._git(['clone', '-n', repourl, path]) + except morphlib.execute.CommandFailure, e: + errors.append('Unable to clone from %s to %s: %s' % + (repourl, path, e)) raise NoRemote(reponame, errors) return self.get_repo(reponame) @@ -302,11 +292,11 @@ class LocalRepoCache(object): if reponame in self._cached_repo_objects: return self._cached_repo_objects[reponame] else: - for repourl, path in self._base_iterate(reponame): - if self._exists(path): - repo = morphlib.cachedrepo.CachedRepo( - reponame, repourl, path) - self._cached_repo_objects[reponame] = repo - return repo + repourl = self.pull_url(reponame) + path = self._cache_name(repourl) + if self._exists(path): + repo = morphlib.cachedrepo.CachedRepo(reponame, repourl, path) + self._cached_repo_objects[reponame] = repo + return repo raise NotCached(reponame) diff --git a/morphlib/localrepocache_tests.py b/morphlib/localrepocache_tests.py index 917de598..aa888885 100644 --- a/morphlib/localrepocache_tests.py +++ b/morphlib/localrepocache_tests.py @@ -84,6 +84,12 @@ class LocalRepoCacheTests(unittest.TestCase): def test_expands_shortened_url_correctly_for_pushing(self): self.assertEqual(self.lrc.push_url(self.reponame), self.pushurl) + def test_expands_full_url_correctly_for_pulling(self): + self.assertEqual(self.lrc.pull_url(self.repourl), self.repourl) + + def test_expands_full_url_correctly_for_pushing(self): + self.assertEqual(self.lrc.push_url(self.pushurl), self.pushurl) + def test_has_not_got_shortened_repo_initially(self): self.assertFalse(self.lrc.has_repo(self.reponame)) |