diff options
author | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2012-09-05 17:49:21 +0100 |
---|---|---|
committer | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2012-09-07 13:35:30 +0100 |
commit | 2c04007fc74d5971b12f351a4c2076e403386997 (patch) | |
tree | 208ff1cccbf752657329fd2975a797093f9dae18 | |
parent | cd00de30a0f4d2d422053692948ea9986960c43f (diff) | |
download | morph-cache-server-2c04007fc74d5971b12f351a4c2076e403386997.tar.gz |
Return tree SHA1 when looking for ref resolution.
Morph now expects the tree SHA1 in addition when resolving references
using the cache server. This is to better facilitate correct cache
key computation since commits can be made which have no tree changes
and thus nothing to usefully affect the build. (For example the morph
branch and build features)
-rwxr-xr-x | morph-cache-server | 5 | ||||
-rw-r--r-- | morphcacheserver/repocache.py | 13 |
2 files changed, 14 insertions, 4 deletions
diff --git a/morph-cache-server b/morph-cache-server index bb84915..3a121d4 100755 --- a/morph-cache-server +++ b/morph-cache-server @@ -65,11 +65,12 @@ class MorphCacheServer(cliapp.Application): ref = self._unescape_parameter(request.query.ref) try: response.set_header('Cache-Control', 'no-cache') - sha1 = repo_cache.resolve_ref(repo, ref) + sha1, tree = repo_cache.resolve_ref(repo, ref) return { 'repo': '%s' % repo, 'ref': '%s' % ref, - 'sha1': '%s' % sha1 + 'sha1': '%s' % sha1, + 'tree': '%s' % tree } except Exception, e: response.status = 404 diff --git a/morphcacheserver/repocache.py b/morphcacheserver/repocache.py index c226ef4..b55692f 100644 --- a/morphcacheserver/repocache.py +++ b/morphcacheserver/repocache.py @@ -64,16 +64,25 @@ class RepoCache(object): refs = [x.split() for x in refs] else: refs = [x.split() for x in refs if 'origin' in x] - return refs[0][0] + return refs[0][0], self._tree_from_commit(repo_dir, refs[0][0]) + except cliapp.AppException: pass + if not self._is_valid_sha1(ref): raise InvalidReferenceError(repo_url, ref) try: - return self._rev_list(ref).strip() + sha = self._rev_list(ref).strip() + return sha, self._tree_from_commit(repo_dir, sha) except: raise InvalidReferenceError(repo_url, ref) + def _tree_from_commit(self, repo_dir, commitsha): + commit_info = self.app.runcmd(['git', 'log', '-1', + '--format=format:%T', commitsha], + cwd=repo_dir) + return commit_info.strip() + def cat_file(self, repo_url, ref, filename): quoted_url = self._quote_url(repo_url) repo_dir = os.path.join(self.repo_cache_dir, quoted_url) |