@@ -650,7 +650,7 @@ static struct pack_midx_entry *get_sorted_entries(struct multi_pack_index *m,
650
650
return deduplicated_entries ;
651
651
}
652
652
653
- static size_t write_midx_pack_names (struct hashfile * f , void * data )
653
+ static int write_midx_pack_names (struct hashfile * f , void * data )
654
654
{
655
655
struct write_midx_context * ctx = data ;
656
656
uint32_t i ;
@@ -678,14 +678,13 @@ static size_t write_midx_pack_names(struct hashfile *f, void *data)
678
678
if (i < MIDX_CHUNK_ALIGNMENT ) {
679
679
memset (padding , 0 , sizeof (padding ));
680
680
hashwrite (f , padding , i );
681
- written += i ;
682
681
}
683
682
684
- return written ;
683
+ return 0 ;
685
684
}
686
685
687
- static size_t write_midx_oid_fanout (struct hashfile * f ,
688
- void * data )
686
+ static int write_midx_oid_fanout (struct hashfile * f ,
687
+ void * data )
689
688
{
690
689
struct write_midx_context * ctx = data ;
691
690
struct pack_midx_entry * list = ctx -> entries ;
@@ -710,17 +709,16 @@ static size_t write_midx_oid_fanout(struct hashfile *f,
710
709
list = next ;
711
710
}
712
711
713
- return MIDX_CHUNK_FANOUT_SIZE ;
712
+ return 0 ;
714
713
}
715
714
716
- static size_t write_midx_oid_lookup (struct hashfile * f ,
717
- void * data )
715
+ static int write_midx_oid_lookup (struct hashfile * f ,
716
+ void * data )
718
717
{
719
718
struct write_midx_context * ctx = data ;
720
719
unsigned char hash_len = the_hash_algo -> rawsz ;
721
720
struct pack_midx_entry * list = ctx -> entries ;
722
721
uint32_t i ;
723
- size_t written = 0 ;
724
722
725
723
for (i = 0 ; i < ctx -> entries_nr ; i ++ ) {
726
724
struct pack_midx_entry * obj = list ++ ;
@@ -734,19 +732,17 @@ static size_t write_midx_oid_lookup(struct hashfile *f,
734
732
}
735
733
736
734
hashwrite (f , obj -> oid .hash , (int )hash_len );
737
- written += hash_len ;
738
735
}
739
736
740
- return written ;
737
+ return 0 ;
741
738
}
742
739
743
- static size_t write_midx_object_offsets (struct hashfile * f ,
744
- void * data )
740
+ static int write_midx_object_offsets (struct hashfile * f ,
741
+ void * data )
745
742
{
746
743
struct write_midx_context * ctx = data ;
747
744
struct pack_midx_entry * list = ctx -> entries ;
748
745
uint32_t i , nr_large_offset = 0 ;
749
- size_t written = 0 ;
750
746
751
747
for (i = 0 ; i < ctx -> entries_nr ; i ++ ) {
752
748
struct pack_midx_entry * obj = list ++ ;
@@ -766,20 +762,17 @@ static size_t write_midx_object_offsets(struct hashfile *f,
766
762
obj -> offset );
767
763
else
768
764
hashwrite_be32 (f , (uint32_t )obj -> offset );
769
-
770
- written += MIDX_CHUNK_OFFSET_WIDTH ;
771
765
}
772
766
773
- return written ;
767
+ return 0 ;
774
768
}
775
769
776
- static size_t write_midx_large_offsets (struct hashfile * f ,
777
- void * data )
770
+ static int write_midx_large_offsets (struct hashfile * f ,
771
+ void * data )
778
772
{
779
773
struct write_midx_context * ctx = data ;
780
774
struct pack_midx_entry * list = ctx -> entries ;
781
775
struct pack_midx_entry * end = ctx -> entries + ctx -> entries_nr ;
782
- size_t written = 0 ;
783
776
uint32_t nr_large_offset = ctx -> num_large_offsets ;
784
777
785
778
while (nr_large_offset ) {
@@ -795,12 +788,12 @@ static size_t write_midx_large_offsets(struct hashfile *f,
795
788
if (!(offset >> 31 ))
796
789
continue ;
797
790
798
- written += hashwrite_be64 (f , offset );
791
+ hashwrite_be64 (f , offset );
799
792
800
793
nr_large_offset -- ;
801
794
}
802
795
803
- return written ;
796
+ return 0 ;
804
797
}
805
798
806
799
static int write_midx_internal (const char * object_dir , struct multi_pack_index * m ,
@@ -812,7 +805,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
812
805
struct hashfile * f = NULL ;
813
806
struct lock_file lk ;
814
807
struct write_midx_context ctx = { 0 };
815
- uint64_t written = 0 ;
808
+ uint64_t header_size = 0 ;
816
809
uint32_t chunk_ids [MIDX_MAX_CHUNKS + 1 ];
817
810
uint64_t chunk_offsets [MIDX_MAX_CHUNKS + 1 ];
818
811
struct progress * progress = NULL ;
@@ -940,10 +933,10 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
940
933
goto cleanup ;
941
934
}
942
935
943
- written = write_midx_header (f , num_chunks , ctx .nr - dropped_packs );
936
+ header_size = write_midx_header (f , num_chunks , ctx .nr - dropped_packs );
944
937
945
938
chunk_ids [cur_chunk ] = MIDX_CHUNKID_PACKNAMES ;
946
- chunk_offsets [cur_chunk ] = written + (num_chunks + 1 ) * MIDX_CHUNKLOOKUP_WIDTH ;
939
+ chunk_offsets [cur_chunk ] = header_size + (num_chunks + 1 ) * MIDX_CHUNKLOOKUP_WIDTH ;
947
940
948
941
cur_chunk ++ ;
949
942
chunk_ids [cur_chunk ] = MIDX_CHUNKID_OIDFANOUT ;
@@ -981,39 +974,37 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
981
974
982
975
hashwrite_be32 (f , chunk_ids [i ]);
983
976
hashwrite_be64 (f , chunk_offsets [i ]);
984
-
985
- written += MIDX_CHUNKLOOKUP_WIDTH ;
986
977
}
987
978
988
979
if (flags & MIDX_PROGRESS )
989
980
progress = start_delayed_progress (_ ("Writing chunks to multi-pack-index" ),
990
981
num_chunks );
991
982
for (i = 0 ; i < num_chunks ; i ++ ) {
992
- if (written != chunk_offsets [i ])
983
+ if (f -> total + f -> offset != chunk_offsets [i ])
993
984
BUG ("incorrect chunk offset (%" PRIu64 " != %" PRIu64 ") for chunk id %" PRIx32 ,
994
985
chunk_offsets [i ],
995
- written ,
986
+ f -> total + f -> offset ,
996
987
chunk_ids [i ]);
997
988
998
989
switch (chunk_ids [i ]) {
999
990
case MIDX_CHUNKID_PACKNAMES :
1000
- written += write_midx_pack_names (f , & ctx );
991
+ write_midx_pack_names (f , & ctx );
1001
992
break ;
1002
993
1003
994
case MIDX_CHUNKID_OIDFANOUT :
1004
- written += write_midx_oid_fanout (f , & ctx );
995
+ write_midx_oid_fanout (f , & ctx );
1005
996
break ;
1006
997
1007
998
case MIDX_CHUNKID_OIDLOOKUP :
1008
- written += write_midx_oid_lookup (f , & ctx );
999
+ write_midx_oid_lookup (f , & ctx );
1009
1000
break ;
1010
1001
1011
1002
case MIDX_CHUNKID_OBJECTOFFSETS :
1012
- written += write_midx_object_offsets (f , & ctx );
1003
+ write_midx_object_offsets (f , & ctx );
1013
1004
break ;
1014
1005
1015
1006
case MIDX_CHUNKID_LARGEOFFSETS :
1016
- written += write_midx_large_offsets (f , & ctx );
1007
+ write_midx_large_offsets (f , & ctx );
1017
1008
break ;
1018
1009
1019
1010
default :
@@ -1025,9 +1016,9 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
1025
1016
}
1026
1017
stop_progress (& progress );
1027
1018
1028
- if (written != chunk_offsets [num_chunks ])
1019
+ if (hashfile_total ( f ) != chunk_offsets [num_chunks ])
1029
1020
BUG ("incorrect final offset %" PRIu64 " != %" PRIu64 ,
1030
- written ,
1021
+ hashfile_total ( f ) ,
1031
1022
chunk_offsets [num_chunks ]);
1032
1023
1033
1024
finalize_hashfile (f , NULL , CSUM_FSYNC | CSUM_HASH_IN_STREAM );
0 commit comments