@@ -15,11 +15,6 @@ typedef int (*open_istream_fn)(struct git_istream *,
1515typedef int (* close_istream_fn )(struct git_istream * );
1616typedef ssize_t (* read_istream_fn )(struct git_istream * , char * , size_t );
1717
18- struct stream_vtbl {
19- close_istream_fn close ;
20- read_istream_fn read ;
21- };
22-
2318#define FILTER_BUFFER (1024*16)
2419
2520struct filtered_istream {
@@ -33,7 +28,10 @@ struct filtered_istream {
3328};
3429
3530struct git_istream {
36- const struct stream_vtbl * vtbl ;
31+ open_istream_fn open ;
32+ close_istream_fn close ;
33+ read_istream_fn read ;
34+
3735 unsigned long size ; /* inflated size of full object */
3836 git_zstream z ;
3937 enum { z_unused , z_used , z_done , z_error } z_state ;
@@ -146,18 +144,14 @@ static ssize_t read_istream_filtered(struct git_istream *st, char *buf,
146144 return filled ;
147145}
148146
149- static struct stream_vtbl filtered_vtbl = {
150- close_istream_filtered ,
151- read_istream_filtered ,
152- };
153-
154147static struct git_istream * attach_stream_filter (struct git_istream * st ,
155148 struct stream_filter * filter )
156149{
157150 struct git_istream * ifs = xmalloc (sizeof (* ifs ));
158151 struct filtered_istream * fs = & (ifs -> u .filtered );
159152
160- ifs -> vtbl = & filtered_vtbl ;
153+ ifs -> close = close_istream_filtered ;
154+ ifs -> read = read_istream_filtered ;
161155 fs -> upstream = st ;
162156 fs -> filter = filter ;
163157 fs -> i_end = fs -> i_ptr = 0 ;
@@ -225,11 +219,6 @@ static int close_istream_loose(struct git_istream *st)
225219 return 0 ;
226220}
227221
228- static struct stream_vtbl loose_vtbl = {
229- close_istream_loose ,
230- read_istream_loose ,
231- };
232-
233222static int open_istream_loose (struct git_istream * st , struct repository * r ,
234223 const struct object_id * oid ,
235224 enum object_type * type )
@@ -251,8 +240,9 @@ static int open_istream_loose(struct git_istream *st, struct repository *r,
251240 st -> u .loose .hdr_used = strlen (st -> u .loose .hdr ) + 1 ;
252241 st -> u .loose .hdr_avail = st -> z .total_out ;
253242 st -> z_state = z_used ;
243+ st -> close = close_istream_loose ;
244+ st -> read = read_istream_loose ;
254245
255- st -> vtbl = & loose_vtbl ;
256246 return 0 ;
257247}
258248
@@ -328,11 +318,6 @@ static int close_istream_pack_non_delta(struct git_istream *st)
328318 return 0 ;
329319}
330320
331- static struct stream_vtbl pack_non_delta_vtbl = {
332- close_istream_pack_non_delta ,
333- read_istream_pack_non_delta ,
334- };
335-
336321static int open_istream_pack_non_delta (struct git_istream * st ,
337322 struct repository * r ,
338323 const struct object_id * oid ,
@@ -358,7 +343,9 @@ static int open_istream_pack_non_delta(struct git_istream *st,
358343 break ;
359344 }
360345 st -> z_state = z_unused ;
361- st -> vtbl = & pack_non_delta_vtbl ;
346+ st -> close = close_istream_pack_non_delta ;
347+ st -> read = read_istream_pack_non_delta ;
348+
362349 return 0 ;
363350}
364351
@@ -389,17 +376,13 @@ static ssize_t read_istream_incore(struct git_istream *st, char *buf, size_t sz)
389376 return read_size ;
390377}
391378
392- static struct stream_vtbl incore_vtbl = {
393- close_istream_incore ,
394- read_istream_incore ,
395- };
396-
397379static int open_istream_incore (struct git_istream * st , struct repository * r ,
398380 const struct object_id * oid , enum object_type * type )
399381{
400382 st -> u .incore .buf = read_object_file_extended (r , oid , type , & st -> size , 0 );
401383 st -> u .incore .read_ptr = 0 ;
402- st -> vtbl = & incore_vtbl ;
384+ st -> close = close_istream_incore ;
385+ st -> read = read_istream_incore ;
403386
404387 return st -> u .incore .buf ? 0 : -1 ;
405388}
@@ -408,10 +391,10 @@ static int open_istream_incore(struct git_istream *st, struct repository *r,
408391 * static helpers variables and functions for users of streaming interface
409392 *****************************************************************************/
410393
411- static open_istream_fn istream_source (struct git_istream * st ,
412- struct repository * r ,
413- const struct object_id * oid ,
414- enum object_type * type )
394+ static int istream_source (struct git_istream * st ,
395+ struct repository * r ,
396+ const struct object_id * oid ,
397+ enum object_type * type )
415398{
416399 unsigned long size ;
417400 int status ;
@@ -421,20 +404,23 @@ static open_istream_fn istream_source(struct git_istream *st,
421404 oi .sizep = & size ;
422405 status = oid_object_info_extended (r , oid , & oi , 0 );
423406 if (status < 0 )
424- return NULL ;
407+ return status ;
425408
426409 switch (oi .whence ) {
427410 case OI_LOOSE :
428- return open_istream_loose ;
411+ st -> open = open_istream_loose ;
412+ return 0 ;
429413 case OI_PACKED :
430414 if (!oi .u .packed .is_delta && big_file_threshold < size ) {
431415 st -> u .in_pack .pack = oi .u .packed .pack ;
432416 st -> u .in_pack .pos = oi .u .packed .offset ;
433- return open_istream_pack_non_delta ;
417+ st -> open = open_istream_pack_non_delta ;
418+ return 0 ;
434419 }
435420 /* fallthru */
436421 default :
437- return open_istream_incore ;
422+ st -> open = open_istream_incore ;
423+ return 0 ;
438424 }
439425}
440426
@@ -444,14 +430,14 @@ static open_istream_fn istream_source(struct git_istream *st,
444430
445431int close_istream (struct git_istream * st )
446432{
447- int r = st -> vtbl -> close (st );
433+ int r = st -> close (st );
448434 free (st );
449435 return r ;
450436}
451437
452438ssize_t read_istream (struct git_istream * st , void * buf , size_t sz )
453439{
454- return st -> vtbl -> read (st , buf , sz );
440+ return st -> read (st , buf , sz );
455441}
456442
457443struct git_istream * open_istream (struct repository * r ,
@@ -462,14 +448,14 @@ struct git_istream *open_istream(struct repository *r,
462448{
463449 struct git_istream * st = xmalloc (sizeof (* st ));
464450 const struct object_id * real = lookup_replace_object (r , oid );
465- open_istream_fn open_fn = istream_source (st , r , real , type );
451+ int ret = istream_source (st , r , real , type );
466452
467- if (! open_fn ) {
453+ if (ret ) {
468454 free (st );
469455 return NULL ;
470456 }
471457
472- if (open_fn (st , r , real , type )) {
458+ if (st -> open (st , r , real , type )) {
473459 if (open_istream_incore (st , r , real , type )) {
474460 free (st );
475461 return NULL ;
0 commit comments