@@ -461,6 +461,9 @@ struct write_midx_context {
461
461
462
462
struct pack_midx_entry * entries ;
463
463
uint32_t entries_nr ;
464
+
465
+ uint32_t * pack_perm ;
466
+ unsigned large_offsets_needed :1 ;
464
467
};
465
468
466
469
static void add_pack_to_midx (const char * full_path , size_t full_path_len ,
@@ -736,27 +739,27 @@ static size_t write_midx_oid_lookup(struct hashfile *f,
736
739
return written ;
737
740
}
738
741
739
- static size_t write_midx_object_offsets (struct hashfile * f , int large_offset_needed ,
740
- uint32_t * perm ,
741
- struct pack_midx_entry * objects , uint32_t nr_objects )
742
+ static size_t write_midx_object_offsets (struct hashfile * f ,
743
+ void * data )
742
744
{
743
- struct pack_midx_entry * list = objects ;
745
+ struct write_midx_context * ctx = data ;
746
+ struct pack_midx_entry * list = ctx -> entries ;
744
747
uint32_t i , nr_large_offset = 0 ;
745
748
size_t written = 0 ;
746
749
747
- for (i = 0 ; i < nr_objects ; i ++ ) {
750
+ for (i = 0 ; i < ctx -> entries_nr ; i ++ ) {
748
751
struct pack_midx_entry * obj = list ++ ;
749
752
750
- if (perm [obj -> pack_int_id ] == PACK_EXPIRED )
753
+ if (ctx -> pack_perm [obj -> pack_int_id ] == PACK_EXPIRED )
751
754
BUG ("object %s is in an expired pack with int-id %d" ,
752
755
oid_to_hex (& obj -> oid ),
753
756
obj -> pack_int_id );
754
757
755
- hashwrite_be32 (f , perm [obj -> pack_int_id ]);
758
+ hashwrite_be32 (f , ctx -> pack_perm [obj -> pack_int_id ]);
756
759
757
- if (large_offset_needed && obj -> offset >> 31 )
760
+ if (ctx -> large_offsets_needed && obj -> offset >> 31 )
758
761
hashwrite_be32 (f , MIDX_LARGE_OFFSET_NEEDED | nr_large_offset ++ );
759
- else if (!large_offset_needed && obj -> offset >> 32 )
762
+ else if (!ctx -> large_offsets_needed && obj -> offset >> 32 )
760
763
BUG ("object %s requires a large offset (%" PRIx64 ") but the MIDX is not writing large offsets!" ,
761
764
oid_to_hex (& obj -> oid ),
762
765
obj -> offset );
@@ -805,13 +808,11 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
805
808
struct hashfile * f = NULL ;
806
809
struct lock_file lk ;
807
810
struct write_midx_context ctx = { 0 };
808
- uint32_t * pack_perm = NULL ;
809
811
uint64_t written = 0 ;
810
812
uint32_t chunk_ids [MIDX_MAX_CHUNKS + 1 ];
811
813
uint64_t chunk_offsets [MIDX_MAX_CHUNKS + 1 ];
812
814
uint32_t num_large_offsets = 0 ;
813
815
struct progress * progress = NULL ;
814
- int large_offsets_needed = 0 ;
815
816
int pack_name_concat_len = 0 ;
816
817
int dropped_packs = 0 ;
817
818
int result = 0 ;
@@ -857,11 +858,12 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
857
858
858
859
ctx .entries = get_sorted_entries (ctx .m , ctx .info , ctx .nr , & ctx .entries_nr );
859
860
861
+ ctx .large_offsets_needed = 0 ;
860
862
for (i = 0 ; i < ctx .entries_nr ; i ++ ) {
861
863
if (ctx .entries [i ].offset > 0x7fffffff )
862
864
num_large_offsets ++ ;
863
865
if (ctx .entries [i ].offset > 0xffffffff )
864
- large_offsets_needed = 1 ;
866
+ ctx . large_offsets_needed = 1 ;
865
867
}
866
868
867
869
QSORT (ctx .info , ctx .nr , pack_info_compare );
@@ -900,13 +902,13 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
900
902
*
901
903
* pack_perm[old_id] = new_id
902
904
*/
903
- ALLOC_ARRAY (pack_perm , ctx .nr );
905
+ ALLOC_ARRAY (ctx . pack_perm , ctx .nr );
904
906
for (i = 0 ; i < ctx .nr ; i ++ ) {
905
907
if (ctx .info [i ].expired ) {
906
908
dropped_packs ++ ;
907
- pack_perm [ctx .info [i ].orig_pack_int_id ] = PACK_EXPIRED ;
909
+ ctx . pack_perm [ctx .info [i ].orig_pack_int_id ] = PACK_EXPIRED ;
908
910
} else {
909
- pack_perm [ctx .info [i ].orig_pack_int_id ] = i - dropped_packs ;
911
+ ctx . pack_perm [ctx .info [i ].orig_pack_int_id ] = i - dropped_packs ;
910
912
}
911
913
}
912
914
@@ -927,7 +929,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
927
929
close_midx (ctx .m );
928
930
929
931
cur_chunk = 0 ;
930
- num_chunks = large_offsets_needed ? 5 : 4 ;
932
+ num_chunks = ctx . large_offsets_needed ? 5 : 4 ;
931
933
932
934
if (ctx .nr - dropped_packs == 0 ) {
933
935
error (_ ("no pack files to index." ));
@@ -954,7 +956,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
954
956
955
957
cur_chunk ++ ;
956
958
chunk_offsets [cur_chunk ] = chunk_offsets [cur_chunk - 1 ] + ctx .entries_nr * MIDX_CHUNK_OFFSET_WIDTH ;
957
- if (large_offsets_needed ) {
959
+ if (ctx . large_offsets_needed ) {
958
960
chunk_ids [cur_chunk ] = MIDX_CHUNKID_LARGEOFFSETS ;
959
961
960
962
cur_chunk ++ ;
@@ -1004,7 +1006,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
1004
1006
break ;
1005
1007
1006
1008
case MIDX_CHUNKID_OBJECTOFFSETS :
1007
- written += write_midx_object_offsets (f , large_offsets_needed , pack_perm , ctx . entries , ctx . entries_nr );
1009
+ written += write_midx_object_offsets (f , & ctx );
1008
1010
break ;
1009
1011
1010
1012
case MIDX_CHUNKID_LARGEOFFSETS :
@@ -1039,7 +1041,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
1039
1041
1040
1042
free (ctx .info );
1041
1043
free (ctx .entries );
1042
- free (pack_perm );
1044
+ free (ctx . pack_perm );
1043
1045
free (midx_name );
1044
1046
return result ;
1045
1047
}
0 commit comments