[PATCH 2/3] Make CachedRepo.resolve_ref handle non-existent SHA1

Lars Wirzenius lars.wirzenius at codethink.co.uk
Thu Oct 24 16:29:42 BST 2013


This changes how CachedRepo runs git to get the SHA1 information
it needs, based on a suggestion by Richard Maw.
---
 morphlib/cachedrepo.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/morphlib/cachedrepo.py b/morphlib/cachedrepo.py
index 0a085bb..e85b005 100644
--- a/morphlib/cachedrepo.py
+++ b/morphlib/cachedrepo.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012  Codethink Limited
+# Copyright (C) 2012-2013  Codethink Limited
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -126,7 +126,11 @@ class CachedRepo(object):
         except cliapp.AppException:
             raise InvalidReferenceError(self, ref)
 
-        tree = self._show_tree_hash(absref)
+        try:
+            tree = self._show_tree_hash(absref)
+        except cliapp.AppException:
+            raise InvalidReferenceError(self, ref)
+
         return absref, tree
 
     def cat(self, ref, filename):
@@ -239,11 +243,12 @@ class CachedRepo(object):
         return self.app.runcmd(*args, **kwargs)
 
     def _rev_parse(self, ref):  # pragma: no cover
-        return self._runcmd(['git', 'rev-parse', '--verify', ref])[0:40]
+        return self._runcmd(
+            ['git', 'rev-parse', '--verify', '%s^{commit}' % ref])[0:40]
 
     def _show_tree_hash(self, absref):  # pragma: no cover
         return self._runcmd(
-                ['git', 'log', '-1', '--format=format:%T', absref]).strip()
+            ['git', 'rev-parse', '--verify', '%s^{tree}' % absref]).strip()
 
     def _ls_tree(self, ref):  # pragma: no cover
         result = self._runcmd(['git', 'ls-tree', '--name-only', ref])
-- 
1.8.4




More information about the baserock-dev mailing list