@@ -33,6 +33,11 @@ struct tree_walk_context {
33
33
git_buf buf ;
34
34
};
35
35
36
+ struct pack_write_context {
37
+ git_indexer_stream * indexer ;
38
+ git_transfer_progress * stats ;
39
+ };
40
+
36
41
#ifdef GIT_THREADS
37
42
38
43
#define GIT_PACKBUILDER__MUTEX_OP (pb , mtx , op ) do { \
@@ -620,26 +625,6 @@ static int write_pack_buf(void *buf, size_t size, void *data)
620
625
return git_buf_put (b , buf , size );
621
626
}
622
627
623
- static int write_pack_to_file (void * buf , size_t size , void * data )
624
- {
625
- git_filebuf * file = (git_filebuf * )data ;
626
- return git_filebuf_write (file , buf , size );
627
- }
628
-
629
- static int write_pack_file (git_packbuilder * pb , const char * path )
630
- {
631
- git_filebuf file = GIT_FILEBUF_INIT ;
632
-
633
- if (git_filebuf_open (& file , path , 0 ) < 0 ||
634
- write_pack (pb , & write_pack_to_file , & file ) < 0 ||
635
- git_filebuf_commit (& file , GIT_PACK_FILE_MODE ) < 0 ) {
636
- git_filebuf_cleanup (& file );
637
- return -1 ;
638
- }
639
-
640
- return 0 ;
641
- }
642
-
643
628
static int type_size_sort (const void * _a , const void * _b )
644
629
{
645
630
const git_pobject * a = (git_pobject * )_a ;
@@ -1259,10 +1244,39 @@ int git_packbuilder_write_buf(git_buf *buf, git_packbuilder *pb)
1259
1244
return write_pack (pb , & write_pack_buf , buf );
1260
1245
}
1261
1246
1262
- int git_packbuilder_write ( git_packbuilder * pb , const char * path )
1247
+ static int write_cb ( void * buf , size_t len , void * payload )
1263
1248
{
1249
+ struct pack_write_context * ctx = payload ;
1250
+ return git_indexer_stream_add (ctx -> indexer , buf , len , ctx -> stats );
1251
+ }
1252
+
1253
+ int git_packbuilder_write (
1254
+ git_packbuilder * pb ,
1255
+ const char * path ,
1256
+ git_transfer_progress_callback progress_cb ,
1257
+ void * progress_cb_payload )
1258
+ {
1259
+ git_indexer_stream * indexer ;
1260
+ git_transfer_progress stats ;
1261
+ struct pack_write_context ctx ;
1262
+
1264
1263
PREPARE_PACK ;
1265
- return write_pack_file (pb , path );
1264
+
1265
+ if (git_indexer_stream_new (
1266
+ & indexer , path , progress_cb , progress_cb_payload ) < 0 )
1267
+ return -1 ;
1268
+
1269
+ ctx .indexer = indexer ;
1270
+ ctx .stats = & stats ;
1271
+
1272
+ if (git_packbuilder_foreach (pb , write_cb , & ctx ) < 0 ||
1273
+ git_indexer_stream_finalize (indexer , & stats ) < 0 ) {
1274
+ git_indexer_stream_free (indexer );
1275
+ return -1 ;
1276
+ }
1277
+
1278
+ git_indexer_stream_free (indexer );
1279
+ return 0 ;
1266
1280
}
1267
1281
1268
1282
#undef PREPARE_PACK
0 commit comments