@@ -525,6 +525,93 @@ static int append_to_pack(git_indexer *idx, const void *data, size_t size)
525525 return write_at (idx , data , idx -> pack -> mwf .size , size );
526526}
527527
528+ static int read_stream_object (git_indexer * idx , git_transfer_progress * stats )
529+ {
530+ git_packfile_stream * stream = & idx -> stream ;
531+ git_off_t entry_start = idx -> off ;
532+ size_t entry_size ;
533+ git_otype type ;
534+ git_mwindow * w = NULL ;
535+ int error ;
536+
537+ if (idx -> pack -> mwf .size <= idx -> off + 20 )
538+ return GIT_EBUFS ;
539+
540+ if (!idx -> have_stream ) {
541+ error = git_packfile_unpack_header (& entry_size , & type , & idx -> pack -> mwf , & w , & idx -> off );
542+ if (error == GIT_EBUFS ) {
543+ idx -> off = entry_start ;
544+ return error ;
545+ }
546+ if (error < 0 )
547+ return error ;
548+
549+ git_mwindow_close (& w );
550+ idx -> entry_start = entry_start ;
551+ git_hash_init (& idx -> hash_ctx );
552+
553+ if (type == GIT_OBJ_REF_DELTA || type == GIT_OBJ_OFS_DELTA ) {
554+ error = advance_delta_offset (idx , type );
555+ if (error == GIT_EBUFS ) {
556+ idx -> off = entry_start ;
557+ return error ;
558+ }
559+ if (error < 0 )
560+ return error ;
561+
562+ idx -> have_delta = 1 ;
563+ } else {
564+ idx -> have_delta = 0 ;
565+
566+ error = hash_header (& idx -> hash_ctx , entry_size , type );
567+ if (error < 0 )
568+ return error ;
569+ }
570+
571+ idx -> have_stream = 1 ;
572+
573+ error = git_packfile_stream_open (stream , idx -> pack , idx -> off );
574+ if (error < 0 )
575+ return error ;
576+ }
577+
578+ if (idx -> have_delta ) {
579+ error = read_object_stream (idx , stream );
580+ } else {
581+ error = hash_object_stream (idx , stream );
582+ }
583+
584+ idx -> off = stream -> curpos ;
585+ if (error == GIT_EBUFS )
586+ return error ;
587+
588+ /* We want to free the stream reasorces no matter what here */
589+ idx -> have_stream = 0 ;
590+ git_packfile_stream_dispose (stream );
591+
592+ if (error < 0 )
593+ return error ;
594+
595+ if (idx -> have_delta ) {
596+ error = store_delta (idx );
597+ } else {
598+ error = store_object (idx );
599+ }
600+
601+ if (error < 0 )
602+ return error ;
603+
604+ if (!idx -> have_delta ) {
605+ stats -> indexed_objects ++ ;
606+ }
607+ stats -> received_objects ++ ;
608+
609+ if ((error = do_progress_callback (idx , stats )) != 0 )
610+ return error ;
611+
612+ return 0 ;
613+ }
614+
528615int git_indexer_append (git_indexer * idx , const void * data , size_t size , git_transfer_progress * stats )
529616{
530617 int error = -1 ;
@@ -588,86 +675,12 @@ int git_indexer_append(git_indexer *idx, const void *data, size_t size, git_tran
588675 git_mwindow_free_all (mwf );
589676
590677 while (stats -> indexed_objects < idx -> nr_objects ) {
591- git_packfile_stream * stream = & idx -> stream ;
592- git_off_t entry_start = idx -> off ;
593- size_t entry_size ;
594- git_otype type ;
595- git_mwindow * w = NULL ;
596-
597- if (idx -> pack -> mwf .size <= idx -> off + 20 )
598- return 0 ;
599-
600- if (!idx -> have_stream ) {
601- error = git_packfile_unpack_header (& entry_size , & type , mwf , & w , & idx -> off );
602- if (error == GIT_EBUFS ) {
603- idx -> off = entry_start ;
604- return 0 ;
605- }
606- if (error < 0 )
678+ if ((error = read_stream_object (idx , stats )) != 0 ) {
679+ if (error == GIT_EBUFS )
680+ break ;
681+ else
607682 goto on_error ;
608-
609- git_mwindow_close (& w );
610- idx -> entry_start = entry_start ;
611- git_hash_init (& idx -> hash_ctx );
612-
613- if (type == GIT_OBJ_REF_DELTA || type == GIT_OBJ_OFS_DELTA ) {
614- error = advance_delta_offset (idx , type );
615- if (error == GIT_EBUFS ) {
616- idx -> off = entry_start ;
617- return 0 ;
618- }
619- if (error < 0 )
620- goto on_error ;
621-
622- idx -> have_delta = 1 ;
623- } else {
624- idx -> have_delta = 0 ;
625-
626- error = hash_header (& idx -> hash_ctx , entry_size , type );
627- if (error < 0 )
628- goto on_error ;
629- }
630-
631- idx -> have_stream = 1 ;
632-
633- error = git_packfile_stream_open (stream , idx -> pack , idx -> off );
634- if (error < 0 )
635- goto on_error ;
636- }
637-
638- if (idx -> have_delta ) {
639- error = read_object_stream (idx , stream );
640- } else {
641- error = hash_object_stream (idx , stream );
642683 }
643-
644- idx -> off = stream -> curpos ;
645- if (error == GIT_EBUFS )
646- return 0 ;
647-
648- /* We want to free the stream reasorces no matter what here */
649- idx -> have_stream = 0 ;
650- git_packfile_stream_dispose (stream );
651-
652- if (error < 0 )
653- goto on_error ;
654-
655- if (idx -> have_delta ) {
656- error = store_delta (idx );
657- } else {
658- error = store_object (idx );
659- }
660-
661- if (error < 0 )
662- goto on_error ;
663-
664- if (!idx -> have_delta ) {
665- stats -> indexed_objects ++ ;
666- }
667- stats -> received_objects ++ ;
668-
669- if ((error = do_progress_callback (idx , stats )) != 0 )
670- goto on_error ;
671684 }
672685
673686 return 0 ;
0 commit comments