|
4 | 4 | # This module is part of GitPython and is released under |
5 | 5 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php |
6 | 6 | import os |
7 | | -from git.utils import LazyMixin, join_path_native |
| 7 | +from git.utils import LazyMixin, join_path_native, stream_copy |
8 | 8 | import utils |
9 | 9 |
|
10 | 10 | _assertion_msg_format = "Created object %r whose python type %r disagrees with the acutal git object type %r" |
@@ -76,10 +76,11 @@ def _set_cache_(self, attr): |
76 | 76 | Retrieve object information |
77 | 77 | """ |
78 | 78 | if attr == "size": |
79 | | - hexsha, typename, self.size = self.repo.git.get_object_header(self.sha) |
| 79 | + typename, self.size = self.repo.odb.object_info(self.sha) |
80 | 80 | assert typename == self.type, _assertion_msg_format % (self.sha, typename, self.type) |
81 | 81 | elif attr == "data": |
82 | | - hexsha, typename, self.size, self.data = self.repo.git.get_object_data(self.sha) |
| 82 | + typename, self.size, stream = self.repo.odb.object(self.sha) |
| 83 | + self.data = stream.read() # once we have an own odb, we can delay reading |
83 | 84 | assert typename == self.type, _assertion_msg_format % (self.sha, typename, self.type) |
84 | 85 | else: |
85 | 86 | super(Object,self)._set_cache_(attr) |
@@ -121,24 +122,17 @@ def __repr__(self): |
121 | 122 |
|
122 | 123 | @property |
123 | 124 | def data_stream(self): |
124 | | - """ |
125 | | - Returns |
126 | | - File Object compatible stream to the uncompressed raw data of the object |
127 | | - """ |
128 | | - proc = self.repo.git.cat_file(self.type, self.sha, as_process=True) |
129 | | - return utils.ProcessStreamAdapter(proc, "stdout") |
| 125 | + """ :return: File Object compatible stream to the uncompressed raw data of the object |
| 126 | + :note: returned streams must be read in order""" |
| 127 | + type, size, stream = self.repo.odb.object(self.sha) |
| 128 | + return stream |
130 | 129 |
|
131 | 130 | def stream_data(self, ostream): |
132 | | - """ |
133 | | - Writes our data directly to the given output stream |
134 | | - |
135 | | - ``ostream`` |
136 | | - File object compatible stream object. |
137 | | - |
138 | | - Returns |
139 | | - self |
140 | | - """ |
141 | | - self.repo.git.cat_file(self.type, self.sha, output_stream=ostream) |
| 131 | + """Writes our data directly to the given output stream |
| 132 | + :param ostream: File object compatible stream object. |
| 133 | + :return: self""" |
| 134 | + type, size, istream = self.repo.odb.object(self.sha) |
| 135 | + stream_copy(istream, ostream) |
142 | 136 | return self |
143 | 137 |
|
144 | 138 |
|
|
0 commit comments