| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Michael Trier <mtrier _at_ gmail.com> | ||
| 2 | + Alan Briolat | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,12 @@ | |||
| 2 | 2 | CHANGES | |
| 3 | 3 | ======= | |
| 4 | 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 | + | ||
| 5 | 11 | 0.1.1 | |
| 6 | 12 | ===== | |
| 7 | 13 | Fixed up some urls because I'm a moron | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -195,7 +195,7 @@ A blob has certain attributes. | |||
| 195 | 195 | >>> blob.mime_type | |
| 196 | 196 | 'text/x-python' | |
| 197 | 197 | ||
| 198 | - >>> len(blob) | ||
| 198 | + >>> blob.size | ||
| 199 | 199 | 415 | |
| 200 | 200 | ||
| 201 | 201 | You can get the data of a blob as a string. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,22 +23,24 @@ def __init__(self, repo, **kwargs): | |||
| 23 | 23 | self.id = None | |
| 24 | 24 | self.mode = None | |
| 25 | 25 | self.name = None | |
| 26 | - self.size = None | ||
| 26 | + self._size = None | ||
| 27 | 27 | self.data_stored = None | |
| 28 | 28 | ||
| 29 | 29 | self.repo = repo | |
| 30 | 30 | for k, v in kwargs.items(): | |
| 31 | 31 | setattr(self, k, v) | |
| 32 | 32 | ||
| 33 | - def __len__(self): | ||
| 33 | + @property | ||
| 34 | + def size(self): | ||
| 34 | 35 | """ | |
| 35 | 36 | The size of this blob in bytes | |
| 36 | 37 | ||
| 37 | 38 | Returns | |
| 38 | 39 | int | |
| 39 | 40 | """ | |
| 40 | - self.size = self.size or int(self.repo.git.cat_file(self.id, **{'s': True}).rstrip()) | ||
| 41 | - return self.size | ||
| 41 | + if self._size is None: | ||
| 42 | + self._size = int(self.repo.git.cat_file(self.id, **{'s': True}).rstrip()) | ||
| 43 | + return self._size | ||
| 42 | 44 | ||
| 43 | 45 | @property | |
| 44 | 46 | def data(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,9 +28,19 @@ def test_should_cache_data(self, git): | |||
| 28 | 28 | def test_should_return_file_size(self, git): | |
| 29 | 29 | git.return_value = fixture('cat_file_blob_size') | |
| 30 | 30 | blob = Blob(self.repo, **{'id': 'abc'}) | |
| 31 | - assert_equal(11, len(blob)) | ||
| 31 | + assert_equal(11, blob.size) | ||
| 32 | 32 | assert_true(git.called) | |
| 33 | 33 | assert_equal(git.call_args, (('cat_file', 'abc'), {'s': True})) | |
| 34 | + | ||
| 35 | + @patch(Git, 'method_missing') | ||
| 36 | + def test_should_cache_file_size(self, git): | ||
| 37 | + git.return_value = fixture('cat_file_blob_size') | ||
| 38 | + blob = Blob(self.repo, **{'id': 'abc'}) | ||
| 39 | + assert_equal(11, blob.size) | ||
| 40 | + assert_equal(11, blob.size) | ||
| 41 | + assert_true(git.called) | ||
| 42 | + assert_equal(git.call_count, 1) | ||
| 43 | + assert_equal(git.call_args, (('cat_file', 'abc'), {'s': True})) | ||
| 34 | 44 | ||
| 35 | 45 | def test_mime_type_should_return_mime_type_for_known_types(self): | |
| 36 | 46 | blob = Blob(self.repo, **{'id': 'abc', 'name': 'foo.png'}) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments