summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES6
-rw-r--r--lib/git/refs.py27
-rw-r--r--test/git/test_base.py7
3 files changed, 23 insertions, 17 deletions
diff --git a/CHANGES b/CHANGES
index 001213d0..61172343 100644
--- a/CHANGES
+++ b/CHANGES
@@ -63,6 +63,12 @@ Tree
* now mimics behaviour of a read-only list instead of a dict to maintain order.
* content_from_string method is now private and not part of the public API anymore
+Refs
+----
+* Will dynmically retrieve their object at the time of query to assure the information
+ is actual. Recently objects would be cached, hence ref object not be safely kept
+ persistent.
+
0.1.6
=====
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):
"""
diff --git a/test/git/test_base.py b/test/git/test_base.py
index 6e3aad7f..402cdba3 100644
--- a/test/git/test_base.py
+++ b/test/git/test_base.py
@@ -78,9 +78,10 @@ class TestBase(object):
for head in self.repo.heads:
head.name
head.path
- cur_obj = head.object
- del( head.object )
- assert cur_obj == head.object
+ prev_object = head.object
+ cur_object = head.object
+ assert prev_object == cur_object # represent the same git object
+ assert prev_object is not cur_object # but are different instances
# END for each head
def test_get_object_type_by_name(self):