@@ -854,67 +854,30 @@ static void start_packfile(void)
854
854
all_packs [pack_id ] = p ;
855
855
}
856
856
857
- static int oecmp ( const void * a_ , const void * b_ )
857
+ static const char * create_index ( void )
858
858
{
859
- struct object_entry * a = * ((struct object_entry * * )a_ );
860
- struct object_entry * b = * ((struct object_entry * * )b_ );
861
- return hashcmp (a -> idx .sha1 , b -> idx .sha1 );
862
- }
863
-
864
- static char * create_index (void )
865
- {
866
- static char tmpfile [PATH_MAX ];
867
- git_SHA_CTX ctx ;
868
- struct sha1file * f ;
869
- struct object_entry * * idx , * * c , * * last , * e ;
859
+ const char * tmpfile ;
860
+ struct pack_idx_entry * * idx , * * c , * * last ;
861
+ struct object_entry * e ;
870
862
struct object_entry_pool * o ;
871
- uint32_t array [256 ];
872
- int i , idx_fd ;
873
863
874
- /* Build the sorted table of object IDs. */
875
- idx = xmalloc (object_count * sizeof (struct object_entry * ));
864
+ /* Build the table of object IDs. */
865
+ idx = xmalloc (object_count * sizeof (* idx ));
876
866
c = idx ;
877
867
for (o = blocks ; o ; o = o -> next_pool )
878
868
for (e = o -> next_free ; e -- != o -> entries ;)
879
869
if (pack_id == e -> pack_id )
880
- * c ++ = e ;
870
+ * c ++ = & e -> idx ;
881
871
last = idx + object_count ;
882
872
if (c != last )
883
873
die ("internal consistency error creating the index" );
884
- qsort (idx , object_count , sizeof (struct object_entry * ), oecmp );
885
874
886
- /* Generate the fan-out array. */
887
- c = idx ;
888
- for (i = 0 ; i < 256 ; i ++ ) {
889
- struct object_entry * * next = c ;
890
- while (next < last ) {
891
- if ((* next )-> idx .sha1 [0 ] != i )
892
- break ;
893
- next ++ ;
894
- }
895
- array [i ] = htonl (next - idx );
896
- c = next ;
897
- }
898
-
899
- idx_fd = odb_mkstemp (tmpfile , sizeof (tmpfile ),
900
- "pack/tmp_idx_XXXXXX" );
901
- f = sha1fd (idx_fd , tmpfile );
902
- sha1write (f , array , 256 * sizeof (int ));
903
- git_SHA1_Init (& ctx );
904
- for (c = idx ; c != last ; c ++ ) {
905
- uint32_t offset = htonl ((* c )-> idx .offset );
906
- sha1write (f , & offset , 4 );
907
- sha1write (f , (* c )-> idx .sha1 , sizeof ((* c )-> idx .sha1 ));
908
- git_SHA1_Update (& ctx , (* c )-> idx .sha1 , 20 );
909
- }
910
- sha1write (f , pack_data -> sha1 , sizeof (pack_data -> sha1 ));
911
- sha1close (f , NULL , CSUM_FSYNC );
875
+ tmpfile = write_idx_file (NULL , idx , object_count , pack_data -> sha1 );
912
876
free (idx );
913
- git_SHA1_Final (pack_data -> sha1 , & ctx );
914
877
return tmpfile ;
915
878
}
916
879
917
- static char * keep_pack (char * curr_index_name )
880
+ static char * keep_pack (const char * curr_index_name )
918
881
{
919
882
static char name [PATH_MAX ];
920
883
static const char * keep_msg = "fast-import" ;
@@ -936,6 +899,7 @@ static char *keep_pack(char *curr_index_name)
936
899
get_object_directory (), sha1_to_hex (pack_data -> sha1 ));
937
900
if (move_temp_to_file (curr_index_name , name ))
938
901
die ("cannot store index file" );
902
+ free ((void * )curr_index_name );
939
903
return name ;
940
904
}
941
905
@@ -1134,6 +1098,8 @@ static int store_object(
1134
1098
object_count ++ ;
1135
1099
object_count_by_type [type ]++ ;
1136
1100
1101
+ crc32_begin (pack_file );
1102
+
1137
1103
if (delta ) {
1138
1104
unsigned long ofs = e -> idx .offset - last -> offset ;
1139
1105
unsigned pos = sizeof (hdr ) - 1 ;
@@ -1160,6 +1126,8 @@ static int store_object(
1160
1126
sha1write (pack_file , out , s .total_out );
1161
1127
pack_size += s .total_out ;
1162
1128
1129
+ e -> idx .crc32 = crc32_end (pack_file );
1130
+
1163
1131
free (out );
1164
1132
free (delta );
1165
1133
if (last ) {
@@ -1219,6 +1187,8 @@ static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark)
1219
1187
git_SHA1_Init (& c );
1220
1188
git_SHA1_Update (& c , out_buf , hdrlen );
1221
1189
1190
+ crc32_begin (pack_file );
1191
+
1222
1192
memset (& s , 0 , sizeof (s ));
1223
1193
deflateInit (& s , pack_compression_level );
1224
1194
@@ -1288,6 +1258,7 @@ static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark)
1288
1258
e -> type = OBJ_BLOB ;
1289
1259
e -> pack_id = pack_id ;
1290
1260
e -> idx .offset = offset ;
1261
+ e -> idx .crc32 = crc32_end (pack_file );
1291
1262
object_count ++ ;
1292
1263
object_count_by_type [OBJ_BLOB ]++ ;
1293
1264
}
0 commit comments