From d58d8e8f7a4ec03ff14021a4515c8283dad52573 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Wed, 2 Mar 2016 17:11:34 +0000 Subject: 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 --- morphlib/git.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'morphlib/git.py') diff --git a/morphlib/git.py b/morphlib/git.py index 190544ac..cab551ef 100644 --- a/morphlib/git.py +++ b/morphlib/git.py @@ -58,12 +58,13 @@ class MissingSubmoduleCommitError(cliapp.AppException): class Submodules(object): - def __init__(self, app, repo, ref): - self.app = app + def __init__(self, repo, ref, runcmd_cb=cliapp.runcmd): self.repo = repo self.ref = ref self.submodules = [] + self.runcmd_cb = runcmd_cb + def load(self): content = self._read_gitmodules_file() @@ -76,7 +77,7 @@ class Submodules(object): def _read_gitmodules_file(self): try: # try to read the .gitmodules file from the repo/ref - content = gitcmd(self.app.runcmd, 'cat-file', 'blob', + content = gitcmd(self.runcmd_cb, 'cat-file', 'blob', '%s:.gitmodules' % self.ref, cwd=self.repo, ignore_fail=True) @@ -100,7 +101,7 @@ class Submodules(object): try: # list objects in the parent repo tree to find the commit # object that corresponds to the submodule - commit = gitcmd(self.app.runcmd, 'ls-tree', self.ref, + commit = gitcmd(self.runcmd_cb, 'ls-tree', self.ref, submodule.path, cwd=self.repo) # read the commit hash from the output -- cgit v1.2.1