@@ -1078,14 +1078,20 @@ static bool midx_needs_update(struct multi_pack_index *midx, struct write_midx_c
10781078 return needed ;
10791079}
10801080
1081- static int write_midx_internal (struct odb_source * source ,
1082- struct string_list * packs_to_include ,
1083- struct string_list * packs_to_drop ,
1084- const char * preferred_pack_name ,
1085- const char * refs_snapshot ,
1086- unsigned flags )
1081+ struct write_midx_opts {
1082+ struct odb_source * source ; /* non-optional */
1083+
1084+ struct string_list * packs_to_include ;
1085+ struct string_list * packs_to_drop ;
1086+
1087+ const char * preferred_pack_name ;
1088+ const char * refs_snapshot ;
1089+ unsigned flags ;
1090+ };
1091+
1092+ static int write_midx_internal (struct write_midx_opts * opts )
10871093{
1088- struct repository * r = source -> odb -> repo ;
1094+ struct repository * r = opts -> source -> odb -> repo ;
10891095 struct strbuf midx_name = STRBUF_INIT ;
10901096 unsigned char midx_hash [GIT_MAX_RAWSZ ];
10911097 uint32_t start_pack ;
@@ -1106,22 +1112,22 @@ static int write_midx_internal(struct odb_source *source,
11061112 trace2_region_enter ("midx" , "write_midx_internal" , r );
11071113
11081114 ctx .repo = r ;
1109- ctx .source = source ;
1115+ ctx .source = opts -> source ;
11101116
1111- ctx .incremental = !!(flags & MIDX_WRITE_INCREMENTAL );
1117+ ctx .incremental = !!(opts -> flags & MIDX_WRITE_INCREMENTAL );
11121118
11131119 if (ctx .incremental )
11141120 strbuf_addf (& midx_name ,
11151121 "%s/pack/multi-pack-index.d/tmp_midx_XXXXXX" ,
1116- source -> path );
1122+ opts -> source -> path );
11171123 else
1118- get_midx_filename (source , & midx_name );
1124+ get_midx_filename (opts -> source , & midx_name );
11191125 if (safe_create_leading_directories (r , midx_name .buf ))
11201126 die_errno (_ ("unable to create leading directories of %s" ),
11211127 midx_name .buf );
11221128
1123- if (!packs_to_include || ctx .incremental ) {
1124- struct multi_pack_index * m = get_multi_pack_index (source );
1129+ if (!opts -> packs_to_include || ctx .incremental ) {
1130+ struct multi_pack_index * m = get_multi_pack_index (opts -> source );
11251131 if (m && !midx_checksum_valid (m )) {
11261132 warning (_ ("ignoring existing multi-pack-index; checksum mismatch" ));
11271133 m = NULL ;
@@ -1136,7 +1142,7 @@ static int write_midx_internal(struct odb_source *source,
11361142 */
11371143 if (ctx .incremental )
11381144 ctx .base_midx = m ;
1139- else if (!packs_to_include )
1145+ else if (!opts -> packs_to_include )
11401146 ctx .m = m ;
11411147 }
11421148 }
@@ -1149,7 +1155,7 @@ static int write_midx_internal(struct odb_source *source,
11491155 if (ctx .incremental ) {
11501156 struct multi_pack_index * m = ctx .base_midx ;
11511157 while (m ) {
1152- if (flags & MIDX_WRITE_BITMAP && load_midx_revindex (m )) {
1158+ if (opts -> flags & MIDX_WRITE_BITMAP && load_midx_revindex (m )) {
11531159 error (_ ("could not load reverse index for MIDX %s" ),
11541160 midx_get_checksum_hex (m ));
11551161 goto cleanup ;
@@ -1164,18 +1170,18 @@ static int write_midx_internal(struct odb_source *source,
11641170 start_pack = ctx .nr ;
11651171
11661172 ctx .pack_paths_checked = 0 ;
1167- if (flags & MIDX_PROGRESS )
1173+ if (opts -> flags & MIDX_PROGRESS )
11681174 ctx .progress = start_delayed_progress (r ,
11691175 _ ("Adding packfiles to multi-pack-index" ), 0 );
11701176 else
11711177 ctx .progress = NULL ;
11721178
1173- ctx .to_include = packs_to_include ;
1179+ ctx .to_include = opts -> packs_to_include ;
11741180
1175- for_each_file_in_pack_dir (source -> path , add_pack_to_midx , & ctx );
1181+ for_each_file_in_pack_dir (opts -> source -> path , add_pack_to_midx , & ctx );
11761182 stop_progress (& ctx .progress );
11771183
1178- if (!packs_to_drop ) {
1184+ if (!opts -> packs_to_drop ) {
11791185 /*
11801186 * If there is no MIDX then either it doesn't exist, or we're
11811187 * doing a geometric repack. Try to load it from the source to
@@ -1188,7 +1194,7 @@ static int write_midx_internal(struct odb_source *source,
11881194 if (midx && !midx_needs_update (midx , & ctx )) {
11891195 struct bitmap_index * bitmap_git ;
11901196 int bitmap_exists ;
1191- int want_bitmap = flags & MIDX_WRITE_BITMAP ;
1197+ int want_bitmap = opts -> flags & MIDX_WRITE_BITMAP ;
11921198
11931199 bitmap_git = prepare_midx_bitmap_git (midx );
11941200 bitmap_exists = bitmap_git && bitmap_is_midx (bitmap_git );
@@ -1200,7 +1206,7 @@ static int write_midx_internal(struct odb_source *source,
12001206 * corresponding bitmap (or one wasn't requested).
12011207 */
12021208 if (!want_bitmap )
1203- clear_midx_files_ext (source , "bitmap" , NULL );
1209+ clear_midx_files_ext (ctx . source , "bitmap" , NULL );
12041210 result = 0 ;
12051211 goto cleanup ;
12061212 }
@@ -1215,11 +1221,11 @@ static int write_midx_internal(struct odb_source *source,
12151221 goto cleanup ; /* nothing to do */
12161222 }
12171223
1218- if (preferred_pack_name ) {
1224+ if (opts -> preferred_pack_name ) {
12191225 ctx .preferred_pack_idx = NO_PREFERRED_PACK ;
12201226
12211227 for (size_t i = 0 ; i < ctx .nr ; i ++ ) {
1222- if (!cmp_idx_or_pack_name (preferred_pack_name ,
1228+ if (!cmp_idx_or_pack_name (opts -> preferred_pack_name ,
12231229 ctx .info [i ].pack_name )) {
12241230 ctx .preferred_pack_idx = i ;
12251231 break ;
@@ -1228,9 +1234,9 @@ static int write_midx_internal(struct odb_source *source,
12281234
12291235 if (ctx .preferred_pack_idx == NO_PREFERRED_PACK )
12301236 warning (_ ("unknown preferred pack: '%s'" ),
1231- preferred_pack_name );
1237+ opts -> preferred_pack_name );
12321238 } else if (ctx .nr &&
1233- (flags & (MIDX_WRITE_REV_INDEX | MIDX_WRITE_BITMAP ))) {
1239+ (opts -> flags & (MIDX_WRITE_REV_INDEX | MIDX_WRITE_BITMAP ))) {
12341240 struct packed_git * oldest = ctx .info [0 ].p ;
12351241 ctx .preferred_pack_idx = 0 ;
12361242
@@ -1241,7 +1247,7 @@ static int write_midx_internal(struct odb_source *source,
12411247 */
12421248 open_pack_index (oldest );
12431249
1244- if (packs_to_drop && packs_to_drop -> nr )
1250+ if (opts -> packs_to_drop && opts -> packs_to_drop -> nr )
12451251 BUG ("cannot write a MIDX bitmap during expiration" );
12461252
12471253 /*
@@ -1303,20 +1309,21 @@ static int write_midx_internal(struct odb_source *source,
13031309
13041310 QSORT (ctx .info , ctx .nr , pack_info_compare );
13051311
1306- if (packs_to_drop && packs_to_drop -> nr ) {
1312+ if (opts -> packs_to_drop && opts -> packs_to_drop -> nr ) {
13071313 size_t drop_index = 0 ;
13081314 int missing_drops = 0 ;
13091315
1310- for (size_t i = 0 ; i < ctx .nr && drop_index < packs_to_drop -> nr ; i ++ ) {
1316+ for (size_t i = 0 ;
1317+ i < ctx .nr && drop_index < opts -> packs_to_drop -> nr ; i ++ ) {
13111318 int cmp = strcmp (ctx .info [i ].pack_name ,
1312- packs_to_drop -> items [drop_index ].string );
1319+ opts -> packs_to_drop -> items [drop_index ].string );
13131320
13141321 if (!cmp ) {
13151322 drop_index ++ ;
13161323 ctx .info [i ].expired = 1 ;
13171324 } else if (cmp > 0 ) {
13181325 error (_ ("did not see pack-file %s to drop" ),
1319- packs_to_drop -> items [drop_index ].string );
1326+ opts -> packs_to_drop -> items [drop_index ].string );
13201327 drop_index ++ ;
13211328 missing_drops ++ ;
13221329 i -- ;
@@ -1353,16 +1360,16 @@ static int write_midx_internal(struct odb_source *source,
13531360 }
13541361
13551362 /* Check that the preferred pack wasn't expired (if given). */
1356- if (preferred_pack_name ) {
1357- struct pack_info * preferred = bsearch (preferred_pack_name ,
1363+ if (opts -> preferred_pack_name ) {
1364+ struct pack_info * preferred = bsearch (opts -> preferred_pack_name ,
13581365 ctx .info , ctx .nr ,
13591366 sizeof (* ctx .info ),
13601367 idx_or_pack_name_cmp );
13611368 if (preferred ) {
13621369 uint32_t perm = ctx .pack_perm [preferred -> orig_pack_int_id ];
13631370 if (perm == PACK_EXPIRED )
13641371 warning (_ ("preferred pack '%s' is expired" ),
1365- preferred_pack_name );
1372+ opts -> preferred_pack_name );
13661373 }
13671374 }
13681375
@@ -1376,15 +1383,15 @@ static int write_midx_internal(struct odb_source *source,
13761383 }
13771384
13781385 if (!ctx .entries_nr ) {
1379- if (flags & MIDX_WRITE_BITMAP )
1386+ if (opts -> flags & MIDX_WRITE_BITMAP )
13801387 warning (_ ("refusing to write multi-pack .bitmap without any objects" ));
1381- flags &= ~(MIDX_WRITE_REV_INDEX | MIDX_WRITE_BITMAP );
1388+ opts -> flags &= ~(MIDX_WRITE_REV_INDEX | MIDX_WRITE_BITMAP );
13821389 }
13831390
13841391 if (ctx .incremental ) {
13851392 struct strbuf lock_name = STRBUF_INIT ;
13861393
1387- get_midx_chain_filename (source , & lock_name );
1394+ get_midx_chain_filename (opts -> source , & lock_name );
13881395 hold_lock_file_for_update (& lk , lock_name .buf , LOCK_DIE_ON_ERROR );
13891396 strbuf_release (& lock_name );
13901397
@@ -1427,7 +1434,7 @@ static int write_midx_internal(struct odb_source *source,
14271434 MIDX_CHUNK_LARGE_OFFSET_WIDTH ),
14281435 write_midx_large_offsets );
14291436
1430- if (flags & (MIDX_WRITE_REV_INDEX | MIDX_WRITE_BITMAP )) {
1437+ if (opts -> flags & (MIDX_WRITE_REV_INDEX | MIDX_WRITE_BITMAP )) {
14311438 ctx .pack_order = midx_pack_order (& ctx );
14321439 add_chunk (cf , MIDX_CHUNKID_REVINDEX ,
14331440 st_mult (ctx .entries_nr , sizeof (uint32_t )),
@@ -1445,11 +1452,11 @@ static int write_midx_internal(struct odb_source *source,
14451452 CSUM_FSYNC | CSUM_HASH_IN_STREAM );
14461453 free_chunkfile (cf );
14471454
1448- if (flags & MIDX_WRITE_REV_INDEX &&
1455+ if (opts -> flags & MIDX_WRITE_REV_INDEX &&
14491456 git_env_bool ("GIT_TEST_MIDX_WRITE_REV" , 0 ))
14501457 write_midx_reverse_index (& ctx , midx_hash );
14511458
1452- if (flags & MIDX_WRITE_BITMAP ) {
1459+ if (opts -> flags & MIDX_WRITE_BITMAP ) {
14531460 struct packing_data pdata ;
14541461 struct commit_stack commits = COMMIT_STACK_INIT ;
14551462
@@ -1458,7 +1465,7 @@ static int write_midx_internal(struct odb_source *source,
14581465
14591466 prepare_midx_packing_data (& pdata , & ctx );
14601467
1461- find_commits_for_midx_bitmap (& commits , refs_snapshot , & ctx );
1468+ find_commits_for_midx_bitmap (& commits , opts -> refs_snapshot , & ctx );
14621469
14631470 /*
14641471 * The previous steps translated the information from
@@ -1469,8 +1476,8 @@ static int write_midx_internal(struct odb_source *source,
14691476 FREE_AND_NULL (ctx .entries );
14701477 ctx .entries_nr = 0 ;
14711478
1472- if (write_midx_bitmap (& ctx , midx_hash , & pdata ,
1473- commits .items , commits . nr , flags ) < 0 ) {
1479+ if (write_midx_bitmap (& ctx , midx_hash , & pdata , commits . items ,
1480+ commits .nr , opts -> flags ) < 0 ) {
14741481 error (_ ("could not write multi-pack bitmap" ));
14751482 clear_packing_data (& pdata );
14761483 commit_stack_clear (& commits );
@@ -1503,7 +1510,7 @@ static int write_midx_internal(struct odb_source *source,
15031510 if (link_midx_to_chain (ctx .base_midx ) < 0 )
15041511 goto cleanup ;
15051512
1506- get_split_midx_filename_ext (source , & final_midx_name ,
1513+ get_split_midx_filename_ext (opts -> source , & final_midx_name ,
15071514 midx_hash , MIDX_EXT_MIDX );
15081515
15091516 if (rename_tempfile (& incr , final_midx_name .buf ) < 0 ) {
@@ -1536,7 +1543,7 @@ static int write_midx_internal(struct odb_source *source,
15361543 if (commit_lock_file (& lk ) < 0 )
15371544 die_errno (_ ("could not write multi-pack-index" ));
15381545
1539- clear_midx_files (source , keep_hashes ,
1546+ clear_midx_files (opts -> source , keep_hashes ,
15401547 ctx .num_multi_pack_indexes_before + 1 ,
15411548 ctx .incremental );
15421549 result = 0 ;
@@ -1571,18 +1578,30 @@ int write_midx_file(struct odb_source *source,
15711578 const char * preferred_pack_name ,
15721579 const char * refs_snapshot , unsigned flags )
15731580{
1574- return write_midx_internal (source , NULL , NULL ,
1575- preferred_pack_name , refs_snapshot ,
1576- flags );
1581+ struct write_midx_opts opts = {
1582+ .source = source ,
1583+ .preferred_pack_name = preferred_pack_name ,
1584+ .refs_snapshot = refs_snapshot ,
1585+ .flags = flags ,
1586+ };
1587+
1588+ return write_midx_internal (& opts );
15771589}
15781590
15791591int write_midx_file_only (struct odb_source * source ,
15801592 struct string_list * packs_to_include ,
15811593 const char * preferred_pack_name ,
15821594 const char * refs_snapshot , unsigned flags )
15831595{
1584- return write_midx_internal (source , packs_to_include , NULL ,
1585- preferred_pack_name , refs_snapshot , flags );
1596+ struct write_midx_opts opts = {
1597+ .source = source ,
1598+ .packs_to_include = packs_to_include ,
1599+ .preferred_pack_name = preferred_pack_name ,
1600+ .refs_snapshot = refs_snapshot ,
1601+ .flags = flags ,
1602+ };
1603+
1604+ return write_midx_internal (& opts );
15861605}
15871606
15881607int expire_midx_packs (struct odb_source * source , unsigned flags )
@@ -1641,9 +1660,14 @@ int expire_midx_packs(struct odb_source *source, unsigned flags)
16411660
16421661 free (count );
16431662
1644- if (packs_to_drop .nr )
1645- result = write_midx_internal (source , NULL ,
1646- & packs_to_drop , NULL , NULL , flags );
1663+ if (packs_to_drop .nr ) {
1664+ struct write_midx_opts opts = {
1665+ .source = source ,
1666+ .packs_to_drop = & packs_to_drop ,
1667+ .flags = flags & MIDX_PROGRESS ,
1668+ };
1669+ result = write_midx_internal (& opts );
1670+ }
16471671
16481672 string_list_clear (& packs_to_drop , 0 );
16491673
@@ -1776,6 +1800,10 @@ int midx_repack(struct odb_source *source, size_t batch_size, unsigned flags)
17761800 struct child_process cmd = CHILD_PROCESS_INIT ;
17771801 FILE * cmd_in ;
17781802 struct multi_pack_index * m = get_multi_pack_index (source );
1803+ struct write_midx_opts opts = {
1804+ .source = source ,
1805+ .flags = flags ,
1806+ };
17791807
17801808 /*
17811809 * When updating the default for these configuration
@@ -1850,8 +1878,7 @@ int midx_repack(struct odb_source *source, size_t batch_size, unsigned flags)
18501878 goto cleanup ;
18511879 }
18521880
1853- result = write_midx_internal (source , NULL , NULL , NULL , NULL ,
1854- flags );
1881+ result = write_midx_internal (& opts );
18551882
18561883cleanup :
18571884 free (include_pack );
0 commit comments