@@ -39,14 +39,6 @@ struct odb_read_stream {
3939 enum { z_unused , z_used , z_done , z_error } z_state ;
4040
4141 union {
42- struct {
43- void * mapped ;
44- unsigned long mapsize ;
45- char hdr [32 ];
46- int hdr_avail ;
47- int hdr_used ;
48- } loose ;
49-
5042 struct {
5143 struct packed_git * pack ;
5244 off_t pos ;
@@ -165,11 +157,21 @@ static struct odb_read_stream *attach_stream_filter(struct odb_read_stream *st,
165157 *
166158 *****************************************************************/
167159
168- static ssize_t read_istream_loose (struct odb_read_stream * st , char * buf , size_t sz )
160+ struct odb_loose_read_stream {
161+ struct odb_read_stream base ;
162+ void * mapped ;
163+ unsigned long mapsize ;
164+ char hdr [32 ];
165+ int hdr_avail ;
166+ int hdr_used ;
167+ };
168+
169+ static ssize_t read_istream_loose (struct odb_read_stream * _st , char * buf , size_t sz )
169170{
171+ struct odb_loose_read_stream * st = (struct odb_loose_read_stream * )_st ;
170172 size_t total_read = 0 ;
171173
172- switch (st -> z_state ) {
174+ switch (st -> base . z_state ) {
173175 case z_done :
174176 return 0 ;
175177 case z_error :
@@ -178,42 +180,43 @@ static ssize_t read_istream_loose(struct odb_read_stream *st, char *buf, size_t
178180 break ;
179181 }
180182
181- if (st -> u . loose . hdr_used < st -> u . loose . hdr_avail ) {
182- size_t to_copy = st -> u . loose . hdr_avail - st -> u . loose . hdr_used ;
183+ if (st -> hdr_used < st -> hdr_avail ) {
184+ size_t to_copy = st -> hdr_avail - st -> hdr_used ;
183185 if (sz < to_copy )
184186 to_copy = sz ;
185- memcpy (buf , st -> u . loose . hdr + st -> u . loose . hdr_used , to_copy );
186- st -> u . loose . hdr_used += to_copy ;
187+ memcpy (buf , st -> hdr + st -> hdr_used , to_copy );
188+ st -> hdr_used += to_copy ;
187189 total_read += to_copy ;
188190 }
189191
190192 while (total_read < sz ) {
191193 int status ;
192194
193- st -> z .next_out = (unsigned char * )buf + total_read ;
194- st -> z .avail_out = sz - total_read ;
195- status = git_inflate (& st -> z , Z_FINISH );
195+ st -> base . z .next_out = (unsigned char * )buf + total_read ;
196+ st -> base . z .avail_out = sz - total_read ;
197+ status = git_inflate (& st -> base . z , Z_FINISH );
196198
197- total_read = st -> z .next_out - (unsigned char * )buf ;
199+ total_read = st -> base . z .next_out - (unsigned char * )buf ;
198200
199201 if (status == Z_STREAM_END ) {
200- git_inflate_end (& st -> z );
201- st -> z_state = z_done ;
202+ git_inflate_end (& st -> base . z );
203+ st -> base . z_state = z_done ;
202204 break ;
203205 }
204206 if (status != Z_OK && (status != Z_BUF_ERROR || total_read < sz )) {
205- git_inflate_end (& st -> z );
206- st -> z_state = z_error ;
207+ git_inflate_end (& st -> base . z );
208+ st -> base . z_state = z_error ;
207209 return -1 ;
208210 }
209211 }
210212 return total_read ;
211213}
212214
213- static int close_istream_loose (struct odb_read_stream * st )
215+ static int close_istream_loose (struct odb_read_stream * _st )
214216{
215- close_deflated_stream (st );
216- munmap (st -> u .loose .mapped , st -> u .loose .mapsize );
217+ struct odb_loose_read_stream * st = (struct odb_loose_read_stream * )_st ;
218+ close_deflated_stream (& st -> base );
219+ munmap (st -> mapped , st -> mapsize );
217220 return 0 ;
218221}
219222
@@ -222,7 +225,7 @@ static int open_istream_loose(struct odb_read_stream **out,
222225 const struct object_id * oid )
223226{
224227 struct object_info oi = OBJECT_INFO_INIT ;
225- struct odb_read_stream * st ;
228+ struct odb_loose_read_stream * st ;
226229 struct odb_source * source ;
227230 unsigned long mapsize ;
228231 void * mapped ;
@@ -244,35 +247,35 @@ static int open_istream_loose(struct odb_read_stream **out,
244247 */
245248 CALLOC_ARRAY (st , 1 );
246249
247- switch (unpack_loose_header (& st -> z , mapped , mapsize , st -> u . loose . hdr ,
248- sizeof (st -> u . loose . hdr ))) {
250+ switch (unpack_loose_header (& st -> base . z , mapped , mapsize , st -> hdr ,
251+ sizeof (st -> hdr ))) {
249252 case ULHR_OK :
250253 break ;
251254 case ULHR_BAD :
252255 case ULHR_TOO_LONG :
253256 goto error ;
254257 }
255258
256- oi .sizep = & st -> size ;
257- oi .typep = & st -> type ;
259+ oi .sizep = & st -> base . size ;
260+ oi .typep = & st -> base . type ;
258261
259- if (parse_loose_header (st -> u . loose . hdr , & oi ) < 0 || st -> type < 0 )
262+ if (parse_loose_header (st -> hdr , & oi ) < 0 || st -> base . type < 0 )
260263 goto error ;
261264
262- st -> u . loose . mapped = mapped ;
263- st -> u . loose . mapsize = mapsize ;
264- st -> u . loose . hdr_used = strlen (st -> u . loose . hdr ) + 1 ;
265- st -> u . loose . hdr_avail = st -> z .total_out ;
266- st -> z_state = z_used ;
267- st -> close = close_istream_loose ;
268- st -> read = read_istream_loose ;
265+ st -> mapped = mapped ;
266+ st -> mapsize = mapsize ;
267+ st -> hdr_used = strlen (st -> hdr ) + 1 ;
268+ st -> hdr_avail = st -> base . z .total_out ;
269+ st -> base . z_state = z_used ;
270+ st -> base . close = close_istream_loose ;
271+ st -> base . read = read_istream_loose ;
269272
270- * out = st ;
273+ * out = & st -> base ;
271274
272275 return 0 ;
273276error :
274- git_inflate_end (& st -> z );
275- munmap (st -> u . loose . mapped , st -> u . loose . mapsize );
277+ git_inflate_end (& st -> base . z );
278+ munmap (st -> mapped , st -> mapsize );
276279 free (st );
277280 return -1 ;
278281}
0 commit comments