We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ea6af04 commit 062aafaCopy full SHA for 062aafa
AUTHORS
@@ -0,0 +1,2 @@
1
+Michael Trier <mtrier _at_ gmail.com>
2
+Alan Briolat
CHANGES
@@ -2,6 +2,12 @@
CHANGES
3
=======
4
5
+0.1.2
6
+=====
7
+Corrected problem with Tree.__div__ not working with zero length files.
8
+Removed __len__ override and replaced with size instead. Also made size cache
9
+properly.
10
+
11
0.1.1
12
=====
13
Fixed up some urls because I'm a moron
README
@@ -195,7 +195,7 @@ A blob has certain attributes.
195
>>> blob.mime_type
196
'text/x-python'
197
198
- >>> len(blob)
+ >>> blob.size
199
415
200
201
You can get the data of a blob as a string.
lib/git_python/blob.py
@@ -23,22 +23,24 @@ def __init__(self, repo, **kwargs):
23
self.id = None
24
self.mode = None
25
self.name = None
26
- self.size = None
+ self._size = None
27
self.data_stored = None
28
29
self.repo = repo
30
for k, v in kwargs.items():
31
setattr(self, k, v)
32
33
- def __len__(self):
+ @property
34
+ def size(self):
35
"""
36
The size of this blob in bytes
37
38
Returns
39
int
40
- self.size = self.size or int(self.repo.git.cat_file(self.id, **{'s': True}).rstrip())
41
- return self.size
+ if self._size is None:
42
+ self._size = int(self.repo.git.cat_file(self.id, **{'s': True}).rstrip())
43
+ return self._size
44
45
@property
46
def data(self):
test/git/test_blob.py
@@ -28,9 +28,19 @@ def test_should_cache_data(self, git):
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_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'})
0 commit comments