diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-14 19:46:24 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-14 19:46:24 +0200 |
commit | 832b56394b079c9f6e4c777934447a9e224facfe (patch) | |
tree | 5f795bededdc1efe13902f2f77b9b7771d98d597 /lib/git/refs.py | |
parent | c5df44408218003eb49e3b8fc94329c5e8b46c7d (diff) | |
download | gitpython-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.py | 27 |
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): """ |