@@ -42,20 +42,6 @@ struct stream_vtbl {
4242 ssize_t read_istream_ ##name \
4343 (struct git_istream *st, char *buf, size_t sz)
4444
45- /* forward declaration */
46- static open_method_decl (incore );
47- static open_method_decl (loose );
48- static open_method_decl (pack_non_delta );
49- static struct git_istream * attach_stream_filter (struct git_istream * st ,
50- struct stream_filter * filter );
51-
52-
53- static open_istream_fn open_istream_tbl [] = {
54- open_istream_incore ,
55- open_istream_loose ,
56- open_istream_pack_non_delta ,
57- };
58-
5945#define FILTER_BUFFER (1024*16)
6046
6147struct filtered_istream {
@@ -97,80 +83,6 @@ struct git_istream {
9783 } u ;
9884};
9985
100- int close_istream (struct git_istream * st )
101- {
102- int r = st -> vtbl -> close (st );
103- free (st );
104- return r ;
105- }
106-
107- ssize_t read_istream (struct git_istream * st , void * buf , size_t sz )
108- {
109- return st -> vtbl -> read (st , buf , sz );
110- }
111-
112- static enum input_source istream_source (struct repository * r ,
113- const struct object_id * oid ,
114- enum object_type * type ,
115- struct object_info * oi )
116- {
117- unsigned long size ;
118- int status ;
119-
120- oi -> typep = type ;
121- oi -> sizep = & size ;
122- status = oid_object_info_extended (r , oid , oi , 0 );
123- if (status < 0 )
124- return stream_error ;
125-
126- switch (oi -> whence ) {
127- case OI_LOOSE :
128- return loose ;
129- case OI_PACKED :
130- if (!oi -> u .packed .is_delta && big_file_threshold < size )
131- return pack_non_delta ;
132- /* fallthru */
133- default :
134- return incore ;
135- }
136- }
137-
138- struct git_istream * open_istream (struct repository * r ,
139- const struct object_id * oid ,
140- enum object_type * type ,
141- unsigned long * size ,
142- struct stream_filter * filter )
143- {
144- struct git_istream * st ;
145- struct object_info oi = OBJECT_INFO_INIT ;
146- const struct object_id * real = lookup_replace_object (r , oid );
147- enum input_source src = istream_source (r , real , type , & oi );
148-
149- if (src < 0 )
150- return NULL ;
151-
152- st = xmalloc (sizeof (* st ));
153- if (open_istream_tbl [src ](st , r , & oi , real , type )) {
154- if (open_istream_incore (st , r , & oi , real , type )) {
155- free (st );
156- return NULL ;
157- }
158- }
159- if (filter ) {
160- /* Add "&& !is_null_stream_filter(filter)" for performance */
161- struct git_istream * nst = attach_stream_filter (st , filter );
162- if (!nst ) {
163- close_istream (st );
164- return NULL ;
165- }
166- st = nst ;
167- }
168-
169- * size = st -> size ;
170- return st ;
171- }
172-
173-
17486/*****************************************************************
17587 *
17688 * Common helpers
@@ -508,11 +420,94 @@ static open_method_decl(incore)
508420 return st -> u .incore .buf ? 0 : -1 ;
509421}
510422
423+ /*****************************************************************************
424+ * static helpers variables and functions for users of streaming interface
425+ *****************************************************************************/
426+
427+ static open_istream_fn open_istream_tbl [] = {
428+ open_istream_incore ,
429+ open_istream_loose ,
430+ open_istream_pack_non_delta ,
431+ };
432+
433+ static enum input_source istream_source (struct repository * r ,
434+ const struct object_id * oid ,
435+ enum object_type * type ,
436+ struct object_info * oi )
437+ {
438+ unsigned long size ;
439+ int status ;
440+
441+ oi -> typep = type ;
442+ oi -> sizep = & size ;
443+ status = oid_object_info_extended (r , oid , oi , 0 );
444+ if (status < 0 )
445+ return stream_error ;
446+
447+ switch (oi -> whence ) {
448+ case OI_LOOSE :
449+ return loose ;
450+ case OI_PACKED :
451+ if (!oi -> u .packed .is_delta && big_file_threshold < size )
452+ return pack_non_delta ;
453+ /* fallthru */
454+ default :
455+ return incore ;
456+ }
457+ }
458+
511459
512460/****************************************************************
513461 * Users of streaming interface
514462 ****************************************************************/
515463
464+ int close_istream (struct git_istream * st )
465+ {
466+ int r = st -> vtbl -> close (st );
467+ free (st );
468+ return r ;
469+ }
470+
471+ ssize_t read_istream (struct git_istream * st , void * buf , size_t sz )
472+ {
473+ return st -> vtbl -> read (st , buf , sz );
474+ }
475+
476+ struct git_istream * open_istream (struct repository * r ,
477+ const struct object_id * oid ,
478+ enum object_type * type ,
479+ unsigned long * size ,
480+ struct stream_filter * filter )
481+ {
482+ struct git_istream * st ;
483+ struct object_info oi = OBJECT_INFO_INIT ;
484+ const struct object_id * real = lookup_replace_object (r , oid );
485+ enum input_source src = istream_source (r , real , type , & oi );
486+
487+ if (src < 0 )
488+ return NULL ;
489+
490+ st = xmalloc (sizeof (* st ));
491+ if (open_istream_tbl [src ](st , r , & oi , real , type )) {
492+ if (open_istream_incore (st , r , & oi , real , type )) {
493+ free (st );
494+ return NULL ;
495+ }
496+ }
497+ if (filter ) {
498+ /* Add "&& !is_null_stream_filter(filter)" for performance */
499+ struct git_istream * nst = attach_stream_filter (st , filter );
500+ if (!nst ) {
501+ close_istream (st );
502+ return NULL ;
503+ }
504+ st = nst ;
505+ }
506+
507+ * size = st -> size ;
508+ return st ;
509+ }
510+
516511int stream_blob_to_fd (int fd , const struct object_id * oid , struct stream_filter * filter ,
517512 int can_seek )
518513{
0 commit comments