@@ -1053,40 +1053,34 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr
1053
1053
return cb .commits ;
1054
1054
}
1055
1055
1056
- static int write_midx_bitmap (char * midx_name , unsigned char * midx_hash ,
1057
- struct write_midx_context * ctx ,
1058
- const char * refs_snapshot ,
1056
+ static int write_midx_bitmap (const char * midx_name ,
1057
+ const unsigned char * midx_hash ,
1058
+ struct packing_data * pdata ,
1059
+ struct commit * * commits ,
1060
+ uint32_t commits_nr ,
1061
+ uint32_t * pack_order ,
1059
1062
unsigned flags )
1060
1063
{
1061
- struct packing_data pdata ;
1062
- struct pack_idx_entry * * index ;
1063
- struct commit * * commits = NULL ;
1064
- uint32_t i , commits_nr ;
1064
+ int ret , i ;
1065
1065
uint16_t options = 0 ;
1066
- char * bitmap_name = xstrfmt ("%s-%s.bitmap" , midx_name , hash_to_hex (midx_hash ));
1067
- int ret ;
1068
-
1069
- if (!ctx -> entries_nr )
1070
- BUG ("cannot write a bitmap without any objects" );
1066
+ struct pack_idx_entry * * index ;
1067
+ char * bitmap_name = xstrfmt ("%s-%s.bitmap" , midx_name ,
1068
+ hash_to_hex (midx_hash ));
1071
1069
1072
1070
if (flags & MIDX_WRITE_BITMAP_HASH_CACHE )
1073
1071
options |= BITMAP_OPT_HASH_CACHE ;
1074
1072
1075
- prepare_midx_packing_data (& pdata , ctx );
1076
-
1077
- commits = find_commits_for_midx_bitmap (& commits_nr , refs_snapshot , ctx );
1078
-
1079
1073
/*
1080
1074
* Build the MIDX-order index based on pdata.objects (which is already
1081
1075
* in MIDX order; c.f., 'midx_pack_order_cmp()' for the definition of
1082
1076
* this order).
1083
1077
*/
1084
- ALLOC_ARRAY (index , pdata . nr_objects );
1085
- for (i = 0 ; i < pdata . nr_objects ; i ++ )
1086
- index [i ] = & pdata . objects [i ].idx ;
1078
+ ALLOC_ARRAY (index , pdata -> nr_objects );
1079
+ for (i = 0 ; i < pdata -> nr_objects ; i ++ )
1080
+ index [i ] = & pdata -> objects [i ].idx ;
1087
1081
1088
1082
bitmap_writer_show_progress (flags & MIDX_PROGRESS );
1089
- bitmap_writer_build_type_index (& pdata , index , pdata . nr_objects );
1083
+ bitmap_writer_build_type_index (pdata , index , pdata -> nr_objects );
1090
1084
1091
1085
/*
1092
1086
* bitmap_writer_finish expects objects in lex order, but pack_order
@@ -1101,16 +1095,16 @@ static int write_midx_bitmap(char *midx_name, unsigned char *midx_hash,
1101
1095
* happens between bitmap_writer_build_type_index() and
1102
1096
* bitmap_writer_finish().
1103
1097
*/
1104
- for (i = 0 ; i < pdata . nr_objects ; i ++ )
1105
- index [ctx -> pack_order [i ]] = & pdata . objects [i ].idx ;
1098
+ for (i = 0 ; i < pdata -> nr_objects ; i ++ )
1099
+ index [pack_order [i ]] = & pdata -> objects [i ].idx ;
1106
1100
1107
1101
bitmap_writer_select_commits (commits , commits_nr , -1 );
1108
- ret = bitmap_writer_build (& pdata );
1102
+ ret = bitmap_writer_build (pdata );
1109
1103
if (ret < 0 )
1110
1104
goto cleanup ;
1111
1105
1112
1106
bitmap_writer_set_checksum (midx_hash );
1113
- bitmap_writer_finish (index , pdata . nr_objects , bitmap_name , options );
1107
+ bitmap_writer_finish (index , pdata -> nr_objects , bitmap_name , options );
1114
1108
1115
1109
cleanup :
1116
1110
free (index );
@@ -1443,14 +1437,40 @@ static int write_midx_internal(const char *object_dir,
1443
1437
if (flags & MIDX_WRITE_REV_INDEX &&
1444
1438
git_env_bool ("GIT_TEST_MIDX_WRITE_REV" , 0 ))
1445
1439
write_midx_reverse_index (midx_name .buf , midx_hash , & ctx );
1440
+
1446
1441
if (flags & MIDX_WRITE_BITMAP ) {
1447
- if (write_midx_bitmap (midx_name .buf , midx_hash , & ctx ,
1448
- refs_snapshot , flags ) < 0 ) {
1442
+ struct packing_data pdata ;
1443
+ struct commit * * commits ;
1444
+ uint32_t commits_nr ;
1445
+
1446
+ if (!ctx .entries_nr )
1447
+ BUG ("cannot write a bitmap without any objects" );
1448
+
1449
+ prepare_midx_packing_data (& pdata , & ctx );
1450
+
1451
+ commits = find_commits_for_midx_bitmap (& commits_nr , refs_snapshot , & ctx );
1452
+
1453
+ /*
1454
+ * The previous steps translated the information from
1455
+ * 'entries' into information suitable for constructing
1456
+ * bitmaps. We no longer need that array, so clear it to
1457
+ * reduce memory pressure.
1458
+ */
1459
+ FREE_AND_NULL (ctx .entries );
1460
+ ctx .entries_nr = 0 ;
1461
+
1462
+ if (write_midx_bitmap (midx_name .buf , midx_hash , & pdata ,
1463
+ commits , commits_nr , ctx .pack_order ,
1464
+ flags ) < 0 ) {
1449
1465
error (_ ("could not write multi-pack bitmap" ));
1450
1466
result = 1 ;
1451
1467
goto cleanup ;
1452
1468
}
1453
1469
}
1470
+ /*
1471
+ * NOTE: Do not use ctx.entries beyond this point, since it might
1472
+ * have been freed in the previous if block.
1473
+ */
1454
1474
1455
1475
if (ctx .m )
1456
1476
close_object_store (the_repository -> objects );
0 commit comments