summaryrefslogtreecommitdiff
path: root/morphcacheserver/repocache.py
diff options
context:
space:
mode:
Diffstat (limited to 'morphcacheserver/repocache.py')
-rw-r--r--morphcacheserver/repocache.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/morphcacheserver/repocache.py b/morphcacheserver/repocache.py
index 3bb348f..7061508 100644
--- a/morphcacheserver/repocache.py
+++ b/morphcacheserver/repocache.py
@@ -81,6 +81,32 @@ class RepoCache(object):
return self._cat_file(repo_dir, sha1, filename)
+ def ls_tree(self, repo_url, ref, path):
+ quoted_url = self._quote_url(repo_url)
+ repo_dir = os.path.join(self.repo_cache_dir, quoted_url)
+ if not self._is_valid_sha1(ref):
+ raise UnresolvedNamedReferenceError(repo_url, ref)
+ if not os.path.exists(repo_dir):
+ raise RepositoryNotFoundError(repo_url)
+
+ try:
+ sha1 = self._rev_list(repo_dir, ref).strip()
+ except:
+ raise InvalidReferenceError(repo_url, ref)
+
+ lines = self._ls_tree(repo_dir, sha1, path).strip()
+ lines = lines.splitlines()
+ data = {}
+ for line in lines:
+ elements = line.split()
+ basename = elements[3]
+ data[basename] = {
+ 'mode': elements[0],
+ 'kind': elements[1],
+ 'sha1': elements[2],
+ }
+ return data
+
def get_bundle_filename(self, repo_url):
quoted_url = self._quote_url(repo_url)
return os.path.join(self.bundle_cache_dir, '%s.bndl' % quoted_url)
@@ -102,6 +128,9 @@ class RepoCache(object):
['git', 'cat-file', 'blob', '%s:%s' % (sha1, filename)],
cwd=repo_dir)
+ def _ls_tree(self, repo_dir, sha1, path):
+ return self.app.runcmd(['git', 'ls-tree', sha1, path], cwd=repo_dir)
+
def _is_valid_sha1(self, ref):
valid_chars = 'abcdefABCDEF0123456789'
return len(ref) == 40 and all([x in valid_chars for x in ref])