From 014a029ade9a045a839ca86c35690b218098ea33 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Thu, 3 Mar 2016 15:56:40 +0000 Subject: Get rid of the CachedRepo class (almost) For a long time the CachedRepo class has basically been a wrapper around the GitDir class, but with a few extra methods that don't really even belong there. It is now a tiny class in the localrepocache module which just keeps track of a few extra attributes. All other functionality is provided by the gitdir module. This commit also removes the `git clone` approach for copying repos out of the cache. The alternative approach implemented by git.copy_repository() was slightly faster when I tested, so for now we should use that everywhere. Longer term we should find out why this is quicker than `git clone`, and fix Git itself to be fast. Change-Id: I1686ab43253d44c3903d9a0bad8bb75528e9cf75 --- morphlib/plugins/anchor_plugin.py | 4 ++-- morphlib/plugins/cross-bootstrap_plugin.py | 4 ++-- morphlib/plugins/diff_plugin.py | 6 +++--- morphlib/plugins/get_repo_plugin.py | 6 +++--- morphlib/plugins/system_manifests_plugin.py | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) (limited to 'morphlib/plugins') diff --git a/morphlib/plugins/anchor_plugin.py b/morphlib/plugins/anchor_plugin.py index 62c66c15..7465c479 100644 --- a/morphlib/plugins/anchor_plugin.py +++ b/morphlib/plugins/anchor_plugin.py @@ -140,7 +140,7 @@ class AnchorPlugin(cliapp.Plugin): repo = bc.lrc.get_updated_repo(reponame, refs=(s.original_ref for s in sources)) - remote = Remote(repo.gitdir) + remote = Remote(repo) push_url = resolver.push_url(reponame) remote.set_push_url(push_url) @@ -178,7 +178,7 @@ class AnchorPlugin(cliapp.Plugin): lsinfo = dict((ref, sha1) for (sha1, ref) in remote.ls()) for flag, sha1, target, summary, reason in results: - commit = repo.gitdir.resolve_ref_to_commit(sha1) + commit = repo.resolve_ref_to_commit(sha1) # Fail if we failed to push something other than a tag # pushed to a branch diff --git a/morphlib/plugins/cross-bootstrap_plugin.py b/morphlib/plugins/cross-bootstrap_plugin.py index 265b273b..273e677d 100644 --- a/morphlib/plugins/cross-bootstrap_plugin.py +++ b/morphlib/plugins/cross-bootstrap_plugin.py @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2015 Codethink Limited +# Copyright (C) 2013-2016 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -38,7 +38,7 @@ echo "Complete!" ''' def escape_source_name(source): - repo_name = source.repo.original_name + repo_name = source.repo_name ref = source.original_ref source_name = '%s__%s' % (repo_name, ref) return re.sub('[:/]', '_', source_name) diff --git a/morphlib/plugins/diff_plugin.py b/morphlib/plugins/diff_plugin.py index 9855c39f..26964df8 100644 --- a/morphlib/plugins/diff_plugin.py +++ b/morphlib/plugins/diff_plugin.py @@ -64,8 +64,8 @@ class DiffPlugin(cliapp.Plugin): ref=s.sha1) for s in (from_source, to_source)) - from_desc = from_repo.gitdir.version_guess(from_source.sha1) - to_desc = to_repo.gitdir.version_guess(to_source.sha1) + from_desc = from_repo.version_guess(from_source.sha1) + to_desc = to_repo.version_guess(to_source.sha1) self.app.output.write( '{} ref changed from {} to {}\n'.format(name, from_desc, @@ -101,7 +101,7 @@ class DiffPlugin(cliapp.Plugin): 'Convert a definition path list into a list of systems' ml = MorphologyLoader() repo = self.bc.lrc.get_updated_repo(reponame, ref=ref) - mf = MorphologyFinder(gitdir=repo.gitdir, ref=ref) + mf = MorphologyFinder(gitdir=repo, ref=ref) # We may have been given an empty set of definitions as input, in # which case we instead use every we find. if not definitions: diff --git a/morphlib/plugins/get_repo_plugin.py b/morphlib/plugins/get_repo_plugin.py index e8ebf229..fc81d6e5 100644 --- a/morphlib/plugins/get_repo_plugin.py +++ b/morphlib/plugins/get_repo_plugin.py @@ -46,13 +46,13 @@ class GetRepoPlugin(cliapp.Plugin): def _clone_repo(self, cached_repo, dirname, checkout_ref): '''Clone a cached git repository into the directory given by path.''' # Do the clone. - gd = morphlib.gitdir.clone_from_cached_repo( - cached_repo, dirname, checkout_ref) + gd = morphlib.gitdir.checkout_from_cached_repo( + cached_repo, checkout_ref, dirname) # Configure the "origin" remote to use the upstream git repository, # and not the locally cached copy. resolver = morphlib.repoaliasresolver.RepoAliasResolver( - cached_repo.app.settings['repo-alias']) + self.app.settings['repo-alias']) remote = gd.get_remote('origin') remote.set_fetch_url(resolver.pull_url(cached_repo.url)) remote.set_push_url(resolver.push_url(cached_repo.original_name)) diff --git a/morphlib/plugins/system_manifests_plugin.py b/morphlib/plugins/system_manifests_plugin.py index 4444ecb3..86388737 100644 --- a/morphlib/plugins/system_manifests_plugin.py +++ b/morphlib/plugins/system_manifests_plugin.py @@ -172,7 +172,7 @@ def run_licensecheck(filename): def checkout_repo(lrc, repo, dest, ref='master'): cached = lrc.get_updated_repo(repo, ref) if not os.path.exists(dest): - cached.checkout(ref, dest) + morphlib.gitdir.checkout_from_cached_repo(repo, ref, dest) def load_lorries(dir): lorries = [] @@ -292,8 +292,8 @@ class Manifest(object): try: self.status(msg='Checking out chunk repo into %(dir)s at %(ref)s', dir=dir, ref=ref, chatty=True) - cached_repo.checkout(ref, dir) - gd = morphlib.gitdir.GitDirectory(dir) + gd = morphlib.gitdir.checkout_from_cached_repo( + cached_repo, ref, dir) gd.update_submodules(app) self.status(msg='Getting license info', chatty=True) -- cgit v1.2.1