summaryrefslogtreecommitdiff
path: root/lib/git/refs.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-10-14 19:46:24 +0200
committerSebastian Thiel <byronimo@gmail.com>2009-10-14 19:46:24 +0200
commit832b56394b079c9f6e4c777934447a9e224facfe (patch)
tree5f795bededdc1efe13902f2f77b9b7771d98d597 /lib/git/refs.py
parentc5df44408218003eb49e3b8fc94329c5e8b46c7d (diff)
downloadgitpython-832b56394b079c9f6e4c777934447a9e224facfe.tar.gz
Refs are now truly dynamic - this costs a little bit of (persistent command) work, but assures refs behave as expected
Diffstat (limited to 'lib/git/refs.py')
-rw-r--r--lib/git/refs.py27
1 files changed, 13 insertions, 14 deletions
diff --git a/lib/git/refs.py b/lib/git/refs.py
index be02fb40..3c9eb817 100644
--- a/lib/git/refs.py
+++ b/lib/git/refs.py
@@ -14,7 +14,7 @@ class Ref(LazyMixin, Iterable):
"""
Represents a named reference to any object
"""
- __slots__ = ("repo", "path", "object")
+ __slots__ = ("repo", "path")
def __init__(self, repo, path, object = None):
"""
@@ -34,18 +34,6 @@ class Ref(LazyMixin, Iterable):
if object is not None:
self.object = object
- def _set_cache_(self, attr):
- if attr == "object":
- # have to be dynamic here as we may be a tag which can point to anything
- # it uses our path to stay dynamic
- hexsha, typename, size = self.repo.git.get_object_header(self.path)
- # pin-point our object to a specific sha, even though it might not
- # reflect the our cached object anymore in case our rev now points
- # to a different commit
- self.object = get_object_type_by_name(typename)(self.repo, hexsha)
- else:
- super(Ref, self)._set_cache_(attr)
-
def __str__(self):
return self.name
@@ -74,7 +62,18 @@ class Ref(LazyMixin, Iterable):
return self.path # could be refs/HEAD
return '/'.join(tokens[2:])
-
+
+ @property
+ def object(self):
+ """
+ Returns
+ The object our ref currently refers to. Refs can be cached, they will
+ always point to the actual object as it gets re-created on each query
+ """
+ # have to be dynamic here as we may be a tag which can point to anything
+ hexsha, typename, size = self.repo.git.get_object_header(self.path)
+ return get_object_type_by_name(typename)(self.repo, hexsha)
+
@classmethod
def iter_items(cls, repo, common_path = "refs", **kwargs):
"""