summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS2
-rw-r--r--CHANGES6
-rw-r--r--README2
-rw-r--r--lib/git_python/blob.py10
-rw-r--r--test/git/test_blob.py12
5 files changed, 26 insertions, 6 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 00000000..5212b9fa
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,2 @@
+Michael Trier <mtrier _at_ gmail.com>
+Alan Briolat
diff --git a/CHANGES b/CHANGES
index 29841f1e..3115e9ee 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,12 @@
CHANGES
=======
+0.1.2
+=====
+Corrected problem with Tree.__div__ not working with zero length files.
+Removed __len__ override and replaced with size instead. Also made size cache
+properly.
+
0.1.1
=====
Fixed up some urls because I'm a moron
diff --git a/README b/README
index b68b746f..abb9ad1f 100644
--- a/README
+++ b/README
@@ -195,7 +195,7 @@ A blob has certain attributes.
>>> blob.mime_type
'text/x-python'
- >>> len(blob)
+ >>> blob.size
415
You can get the data of a blob as a string.
diff --git a/lib/git_python/blob.py b/lib/git_python/blob.py
index c89c3c3f..054cdb9b 100644
--- a/lib/git_python/blob.py
+++ b/lib/git_python/blob.py
@@ -23,22 +23,24 @@ class Blob(object):
self.id = None
self.mode = None
self.name = None
- self.size = None
+ self._size = None
self.data_stored = None
self.repo = repo
for k, v in kwargs.items():
setattr(self, k, v)
- def __len__(self):
+ @property
+ def size(self):
"""
The size of this blob in bytes
Returns
int
"""
- self.size = self.size or int(self.repo.git.cat_file(self.id, **{'s': True}).rstrip())
- return self.size
+ if self._size is None:
+ self._size = int(self.repo.git.cat_file(self.id, **{'s': True}).rstrip())
+ return self._size
@property
def data(self):
diff --git a/test/git/test_blob.py b/test/git/test_blob.py
index 1d84e1d8..ee546ab4 100644
--- a/test/git/test_blob.py
+++ b/test/git/test_blob.py
@@ -28,9 +28,19 @@ class TestBlob(object):
def test_should_return_file_size(self, git):
git.return_value = fixture('cat_file_blob_size')
blob = Blob(self.repo, **{'id': 'abc'})
- assert_equal(11, len(blob))
+ assert_equal(11, blob.size)
assert_true(git.called)
assert_equal(git.call_args, (('cat_file', 'abc'), {'s': True}))
+
+ @patch(Git, 'method_missing')
+ def test_should_cache_file_size(self, git):
+ git.return_value = fixture('cat_file_blob_size')
+ blob = Blob(self.repo, **{'id': 'abc'})
+ assert_equal(11, blob.size)
+ assert_equal(11, blob.size)
+ assert_true(git.called)
+ assert_equal(git.call_count, 1)
+ assert_equal(git.call_args, (('cat_file', 'abc'), {'s': True}))
def test_mime_type_should_return_mime_type_for_known_types(self):
blob = Blob(self.repo, **{'id': 'abc', 'name': 'foo.png'})