diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-08-24 17:57:49 +0100 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-08-24 17:57:49 +0100 |
commit | 975b3f30605c36a714bf5b9619817a897cb6a4a3 (patch) | |
tree | 5564243efa6a55dc49ed05c2455e70b32598c6bf /morphlib/remoterepocache.py | |
parent | 6c13c2ebdea1da19bf359fef9a9e0b08e5491a4a (diff) | |
download | morph-975b3f30605c36a714bf5b9619817a897cb6a4a3.tar.gz |
Support 'git ls-tree' in local and remote repos
Diffstat (limited to 'morphlib/remoterepocache.py')
-rw-r--r-- | morphlib/remoterepocache.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/morphlib/remoterepocache.py b/morphlib/remoterepocache.py index d8526562..c40057b1 100644 --- a/morphlib/remoterepocache.py +++ b/morphlib/remoterepocache.py @@ -35,6 +35,13 @@ class CatFileError(cliapp.AppException): self, 'Failed to cat file %s in ref %s of repo %s' % (filename, ref, repo_name)) +class LsTreeError(cliapp.AppException): + + def __init__(self, repo_name, ref): + cliapp.AppException.__init__( + self, 'Failed to list tree in ref %s of repo %s' % + (ref, repo_name)) + class RemoteRepoCache(object): @@ -56,6 +63,14 @@ class RemoteRepoCache(object): except: raise CatFileError(repo_name, ref, filename) + def ls_tree(self, repo_name, ref): + repo_url = self._resolver.pull_url(repo_name) + try: + info = json.loads(self._ls_tree_for_repo_url(repo_url, ref)) + return info['tree'].keys() + except: + raise LsTreeError(repo_name, ref) + def _resolve_ref_for_repo_url(self, repo_url, ref): # pragma: no cover data = self._make_request('sha1s?repo=%s&ref=%s' % (repo_url, ref)) info = json.loads(data) @@ -66,6 +81,9 @@ class RemoteRepoCache(object): return self._make_request( 'files?repo=%s&ref=%s&filename=%s' % (repo_url, ref, filename)) + def _ls_tree_for_repo_url(self, repo_url, ref): # pragma: no cover + return self._make_request('trees?repo=%s&ref=%s' % (repo_url, ref)) + def _make_request(self, path): # pragma: no cover server_url = self.server_url if not server_url.endswith('/'): |