@@ -14,7 +14,7 @@ class Ref(LazyMixin, Iterable):
1414 """
1515 Represents a named reference to any object
1616 """
17- __slots__ = ("repo" , "path" , "object" )
17+ __slots__ = ("repo" , "path" )
1818
1919 def __init__ (self , repo , path , object = None ):
2020 """
@@ -34,18 +34,6 @@ def __init__(self, repo, path, object = None):
3434 if object is not None :
3535 self .object = object
3636
37- def _set_cache_ (self , attr ):
38- if attr == "object" :
39- # have to be dynamic here as we may be a tag which can point to anything
40- # it uses our path to stay dynamic
41- hexsha , typename , size = self .repo .git .get_object_header (self .path )
42- # pin-point our object to a specific sha, even though it might not
43- # reflect the our cached object anymore in case our rev now points
44- # to a different commit
45- self .object = get_object_type_by_name (typename )(self .repo , hexsha )
46- else :
47- super (Ref , self )._set_cache_ (attr )
48-
4937 def __str__ (self ):
5038 return self .name
5139
@@ -74,7 +62,18 @@ def name(self):
7462 return self .path # could be refs/HEAD
7563
7664 return '/' .join (tokens [2 :])
77-
65+
66+ @property
67+ def object (self ):
68+ """
69+ Returns
70+ The object our ref currently refers to. Refs can be cached, they will
71+ always point to the actual object as it gets re-created on each query
72+ """
73+ # have to be dynamic here as we may be a tag which can point to anything
74+ hexsha , typename , size = self .repo .git .get_object_header (self .path )
75+ return get_object_type_by_name (typename )(self .repo , hexsha )
76+
7877 @classmethod
7978 def iter_items (cls , repo , common_path = "refs" , ** kwargs ):
8079 """
0 commit comments