@@ -15,11 +15,6 @@ typedef int (*open_istream_fn)(struct git_istream *,
15
15
typedef int (* close_istream_fn )(struct git_istream * );
16
16
typedef ssize_t (* read_istream_fn )(struct git_istream * , char * , size_t );
17
17
18
- struct stream_vtbl {
19
- close_istream_fn close ;
20
- read_istream_fn read ;
21
- };
22
-
23
18
#define FILTER_BUFFER (1024*16)
24
19
25
20
struct filtered_istream {
@@ -33,7 +28,10 @@ struct filtered_istream {
33
28
};
34
29
35
30
struct git_istream {
36
- const struct stream_vtbl * vtbl ;
31
+ open_istream_fn open ;
32
+ close_istream_fn close ;
33
+ read_istream_fn read ;
34
+
37
35
unsigned long size ; /* inflated size of full object */
38
36
git_zstream z ;
39
37
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,
146
144
return filled ;
147
145
}
148
146
149
- static struct stream_vtbl filtered_vtbl = {
150
- close_istream_filtered ,
151
- read_istream_filtered ,
152
- };
153
-
154
147
static struct git_istream * attach_stream_filter (struct git_istream * st ,
155
148
struct stream_filter * filter )
156
149
{
157
150
struct git_istream * ifs = xmalloc (sizeof (* ifs ));
158
151
struct filtered_istream * fs = & (ifs -> u .filtered );
159
152
160
- ifs -> vtbl = & filtered_vtbl ;
153
+ ifs -> close = close_istream_filtered ;
154
+ ifs -> read = read_istream_filtered ;
161
155
fs -> upstream = st ;
162
156
fs -> filter = filter ;
163
157
fs -> i_end = fs -> i_ptr = 0 ;
@@ -225,11 +219,6 @@ static int close_istream_loose(struct git_istream *st)
225
219
return 0 ;
226
220
}
227
221
228
- static struct stream_vtbl loose_vtbl = {
229
- close_istream_loose ,
230
- read_istream_loose ,
231
- };
232
-
233
222
static int open_istream_loose (struct git_istream * st , struct repository * r ,
234
223
const struct object_id * oid ,
235
224
enum object_type * type )
@@ -251,8 +240,9 @@ static int open_istream_loose(struct git_istream *st, struct repository *r,
251
240
st -> u .loose .hdr_used = strlen (st -> u .loose .hdr ) + 1 ;
252
241
st -> u .loose .hdr_avail = st -> z .total_out ;
253
242
st -> z_state = z_used ;
243
+ st -> close = close_istream_loose ;
244
+ st -> read = read_istream_loose ;
254
245
255
- st -> vtbl = & loose_vtbl ;
256
246
return 0 ;
257
247
}
258
248
@@ -328,11 +318,6 @@ static int close_istream_pack_non_delta(struct git_istream *st)
328
318
return 0 ;
329
319
}
330
320
331
- static struct stream_vtbl pack_non_delta_vtbl = {
332
- close_istream_pack_non_delta ,
333
- read_istream_pack_non_delta ,
334
- };
335
-
336
321
static int open_istream_pack_non_delta (struct git_istream * st ,
337
322
struct repository * r ,
338
323
const struct object_id * oid ,
@@ -358,7 +343,9 @@ static int open_istream_pack_non_delta(struct git_istream *st,
358
343
break ;
359
344
}
360
345
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
+
362
349
return 0 ;
363
350
}
364
351
@@ -389,17 +376,13 @@ static ssize_t read_istream_incore(struct git_istream *st, char *buf, size_t sz)
389
376
return read_size ;
390
377
}
391
378
392
- static struct stream_vtbl incore_vtbl = {
393
- close_istream_incore ,
394
- read_istream_incore ,
395
- };
396
-
397
379
static int open_istream_incore (struct git_istream * st , struct repository * r ,
398
380
const struct object_id * oid , enum object_type * type )
399
381
{
400
382
st -> u .incore .buf = read_object_file_extended (r , oid , type , & st -> size , 0 );
401
383
st -> u .incore .read_ptr = 0 ;
402
- st -> vtbl = & incore_vtbl ;
384
+ st -> close = close_istream_incore ;
385
+ st -> read = read_istream_incore ;
403
386
404
387
return st -> u .incore .buf ? 0 : -1 ;
405
388
}
@@ -408,10 +391,10 @@ static int open_istream_incore(struct git_istream *st, struct repository *r,
408
391
* static helpers variables and functions for users of streaming interface
409
392
*****************************************************************************/
410
393
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 )
415
398
{
416
399
unsigned long size ;
417
400
int status ;
@@ -421,20 +404,23 @@ static open_istream_fn istream_source(struct git_istream *st,
421
404
oi .sizep = & size ;
422
405
status = oid_object_info_extended (r , oid , & oi , 0 );
423
406
if (status < 0 )
424
- return NULL ;
407
+ return status ;
425
408
426
409
switch (oi .whence ) {
427
410
case OI_LOOSE :
428
- return open_istream_loose ;
411
+ st -> open = open_istream_loose ;
412
+ return 0 ;
429
413
case OI_PACKED :
430
414
if (!oi .u .packed .is_delta && big_file_threshold < size ) {
431
415
st -> u .in_pack .pack = oi .u .packed .pack ;
432
416
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 ;
434
419
}
435
420
/* fallthru */
436
421
default :
437
- return open_istream_incore ;
422
+ st -> open = open_istream_incore ;
423
+ return 0 ;
438
424
}
439
425
}
440
426
@@ -444,14 +430,14 @@ static open_istream_fn istream_source(struct git_istream *st,
444
430
445
431
int close_istream (struct git_istream * st )
446
432
{
447
- int r = st -> vtbl -> close (st );
433
+ int r = st -> close (st );
448
434
free (st );
449
435
return r ;
450
436
}
451
437
452
438
ssize_t read_istream (struct git_istream * st , void * buf , size_t sz )
453
439
{
454
- return st -> vtbl -> read (st , buf , sz );
440
+ return st -> read (st , buf , sz );
455
441
}
456
442
457
443
struct git_istream * open_istream (struct repository * r ,
@@ -462,14 +448,14 @@ struct git_istream *open_istream(struct repository *r,
462
448
{
463
449
struct git_istream * st = xmalloc (sizeof (* st ));
464
450
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 );
466
452
467
- if (! open_fn ) {
453
+ if (ret ) {
468
454
free (st );
469
455
return NULL ;
470
456
}
471
457
472
- if (open_fn (st , r , real , type )) {
458
+ if (st -> open (st , r , real , type )) {
473
459
if (open_istream_incore (st , r , real , type )) {
474
460
free (st );
475
461
return NULL ;
0 commit comments