diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-12-13 12:36:07 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2012-12-13 15:37:53 +0000 |
commit | de50cec19b4f7e4c5a6da5ecc5cddd7a52ac3725 (patch) | |
tree | 552fdae98cd0cc15d0b8a23ee225751b1d8ae374 /morphlib/cachedrepo.py | |
parent | d63c97a0bef1cd2f03ca266acda67cad065632df (diff) | |
download | morph-de50cec19b4f7e4c5a6da5ecc5cddd7a52ac3725.tar.gz |
Always use `git rev-parse --verify` to resolve refs
Previously some code used `git show-ref`, which is wrong -- given two
refs named 'alpha/master' and 'master', `git show-ref master` will
return both, sorted alphabetically. This can lead to build failures,
etc. due to refs resolving to the wrong SHAs.
We should also use `git rev-parse --verify` to verify SHA1s, which
we previously did with `git rev-list`.
Finally, `git rev-parse --verify` is more than twice as fast as
`git show-ref`.
Diffstat (limited to 'morphlib/cachedrepo.py')
-rw-r--r-- | morphlib/cachedrepo.py | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/morphlib/cachedrepo.py b/morphlib/cachedrepo.py index 0b5ce60f..312f580f 100644 --- a/morphlib/cachedrepo.py +++ b/morphlib/cachedrepo.py @@ -112,18 +112,10 @@ class CachedRepo(object): ''' - if not morphlib.git.is_valid_sha1(ref): - try: - refs = self._show_ref(ref).split('\n') - refs = [x.split() for x in refs] - 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) + try: + absref = self._rev_parse(ref) + except cliapp.AppException: + raise InvalidReferenceError(self, ref) tree = self._show_tree_hash(absref) return absref, tree @@ -141,7 +133,7 @@ class CachedRepo(object): if not morphlib.git.is_valid_sha1(ref): raise UnresolvedNamedReferenceError(self, ref) try: - sha1 = self._rev_list(ref).strip() + sha1 = self._rev_parse(ref) except cliapp.AppException: raise InvalidReferenceError(self, ref) @@ -193,7 +185,7 @@ class CachedRepo(object): '''Loads a morphology from a given ref''' if not morphlib.git.is_valid_sha1(ref): - ref = self._rev_list(ref).strip() + ref = self._rev_parse(ref) text = self.cat(ref, '%s.morph' % name) morphology = morphlib.morph2.Morphology(text) return morphology @@ -210,7 +202,7 @@ class CachedRepo(object): if not morphlib.git.is_valid_sha1(ref): raise UnresolvedNamedReferenceError(self, ref) try: - sha1 = self._rev_list(ref).strip() + sha1 = self._rev_parse(ref) except cliapp.AppException: raise InvalidReferenceError(self, ref) @@ -237,16 +229,13 @@ class CachedRepo(object): kwargs['cwd'] = self.path return self.app.runcmd(*args, **kwargs) - def _show_ref(self, ref): # pragma: no cover - return self._runcmd(['git', 'show-ref', ref]) + def _rev_parse(self, ref): # pragma: no cover + return self._runcmd(['git', 'rev-parse', '--verify', ref])[0:40] 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]) - def _ls_tree(self, ref): # pragma: no cover result = self._runcmd(['git', 'ls-tree', '--name-only', ref]) return result.split('\n') |