summaryrefslogtreecommitdiff
path: root/morphlib/cachedrepo.py
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-09-05 17:12:26 +0000
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-09-05 17:12:26 +0000
commitb9488584415d94fc28c2e064b917183b851af07b (patch)
treeebdb4f647c43afd633fcc5243e26ef24c6096628 /morphlib/cachedrepo.py
parent083fd4de011e0fcf4a445b38a7fa6ef8964a5ccb (diff)
downloadmorph-b9488584415d94fc28c2e064b917183b851af07b.tar.gz
Resolve tree SHA1 along with commit SHA1 when resolving refs
Adjust all other parts and the tests to work with this.
Diffstat (limited to 'morphlib/cachedrepo.py')
-rw-r--r--morphlib/cachedrepo.py34
1 files changed, 20 insertions, 14 deletions
diff --git a/morphlib/cachedrepo.py b/morphlib/cachedrepo.py
index f647102f..eef49ffb 100644
--- a/morphlib/cachedrepo.py
+++ b/morphlib/cachedrepo.py
@@ -91,27 +91,29 @@ class CachedRepo(object):
return len(ref) == 40 and all([x in valid_chars for x in ref])
def resolve_ref(self, ref):
- '''Attempts to resolve a Git ref into its corresponding SHA1.
+ '''Attempts to resolve a ref into its SHA1 and tree SHA1.
Raises an InvalidReferenceError if the ref is not found in the
repository.
'''
- try:
- refs = self._show_ref(ref).split('\n')
- # split each ref line into an array, drop non-origin branches
- refs = [x.split() for x in refs if 'origin' in x]
- return refs[0][0]
- except cliapp.AppException:
- pass
-
if not self.is_valid_sha1(ref):
- raise InvalidReferenceError(self, ref)
- try:
- return self._rev_list(ref).strip()
- except cliapp.AppException:
- raise InvalidReferenceError(self, ref)
+ try:
+ refs = self._show_ref(ref).split('\n')
+ # split each ref line into an array, drop non-origin branches
+ refs = [x.split() for x in refs if 'origin' in x]
+ absref = refs[0][0]
+ except cliapp.AppException:
+ raise InvalidReferenceError(self, ref)
+ else:
+ try:
+ absref = self._rev_list(ref).strip()
+ except cliapp.AppException:
+ raise InvalidReferenceError(self, ref)
+
+ tree = self._show_tree_hash(absref)
+ return absref, tree
def cat(self, ref, filename):
'''Attempts to read a file given a SHA1 ref.
@@ -197,6 +199,10 @@ class CachedRepo(object):
def _show_ref(self, ref): # pragma: no cover
return self._runcmd(['git', 'show-ref', ref])
+ def _show_tree_hash(self, absref): # pragma: no cover
+ return self._runcmd(
+ ['git', 'log', '-1', '--format=format:%T', absref]).strip()
+
def _rev_list(self, ref): # pragma: no cover
return self._runcmd(['git', 'rev-list', '--no-walk', ref])