From 9ee31065abea645cbc2cf3e54b691d5983a228b2 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 11:01:12 +0200 Subject: Intermediate commit: commit,tree and blob objects now derive from object - test is in place which still fails on purpose. Need to integrate tags which can be objects or just a special form of a ref --- lib/git/blob.py | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'lib/git/blob.py') diff --git a/lib/git/blob.py b/lib/git/blob.py index 1e8aa12b..3ecd3a38 100644 --- a/lib/git/blob.py +++ b/lib/git/blob.py @@ -10,10 +10,13 @@ import re import time from actor import Actor from commit import Commit +import base -class Blob(object): +class Blob(base.Object): """A Blob encapsulates a git blob object""" DEFAULT_MIME_TYPE = "text/plain" + type = "blob" + __slots__ = ("mode", "path", "_data_stored") # precompiled regex re_whitespace = re.compile(r'\s+') @@ -40,28 +43,10 @@ class Blob(object): Returns git.Blob """ - self.repo = repo - self.id = id + super(Blob,self).__init__(repo, id, "blob") self.mode = mode self.path = path - - self._size = None - self.data_stored = None - - @property - def size(self): - """ - The size of this blob in bytes - - Returns - int - - NOTE - The size will be cached after the first access - """ - if self._size is None: - self._size = int(self.repo.git.cat_file(self.id, s=True).rstrip()) - return self._size + self._data_stored = None @property def data(self): @@ -74,8 +59,8 @@ class Blob(object): NOTE The data will be cached after the first access. """ - self.data_stored = self.data_stored or self.repo.git.cat_file(self.id, p=True, with_raw_output=True) - return self.data_stored + self._data_stored = self._data_stored or self.repo.git.cat_file(self.id, p=True, with_raw_output=True) + return self._data_stored @property def mime_type(self): -- cgit v1.2.1