@@ -448,6 +448,8 @@ struct pack_list {
448448 uint32_t nr ;
449449 uint32_t alloc ;
450450 struct multi_pack_index * m ;
451+ struct progress * progress ;
452+ unsigned pack_paths_checked ;
451453};
452454
453455static void add_pack_to_midx (const char * full_path , size_t full_path_len ,
@@ -456,6 +458,7 @@ static void add_pack_to_midx(const char *full_path, size_t full_path_len,
456458 struct pack_list * packs = (struct pack_list * )data ;
457459
458460 if (ends_with (file_name , ".idx" )) {
461+ display_progress (packs -> progress , ++ packs -> pack_paths_checked );
459462 if (packs -> m && midx_contains_pack (packs -> m , file_name ))
460463 return ;
461464
@@ -785,7 +788,7 @@ static size_t write_midx_large_offsets(struct hashfile *f, uint32_t nr_large_off
785788}
786789
787790static int write_midx_internal (const char * object_dir , struct multi_pack_index * m ,
788- struct string_list * packs_to_drop )
791+ struct string_list * packs_to_drop , unsigned flags )
789792{
790793 unsigned char cur_chunk , num_chunks = 0 ;
791794 char * midx_name ;
@@ -799,6 +802,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
799802 uint64_t chunk_offsets [MIDX_MAX_CHUNKS + 1 ];
800803 uint32_t nr_entries , num_large_offsets = 0 ;
801804 struct pack_midx_entry * entries = NULL ;
805+ struct progress * progress = NULL ;
802806 int large_offsets_needed = 0 ;
803807 int pack_name_concat_len = 0 ;
804808 int dropped_packs = 0 ;
@@ -833,7 +837,14 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
833837 }
834838 }
835839
840+ packs .pack_paths_checked = 0 ;
841+ if (flags & MIDX_PROGRESS )
842+ packs .progress = start_progress (_ ("Adding packfiles to multi-pack-index" ), 0 );
843+ else
844+ packs .progress = NULL ;
845+
836846 for_each_file_in_pack_dir (object_dir , add_pack_to_midx , & packs );
847+ stop_progress (& packs .progress );
837848
838849 if (packs .m && packs .nr == packs .m -> num_packs && !packs_to_drop )
839850 goto cleanup ;
@@ -958,6 +969,9 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
958969 written += MIDX_CHUNKLOOKUP_WIDTH ;
959970 }
960971
972+ if (flags & MIDX_PROGRESS )
973+ progress = start_progress (_ ("Writing chunks to multi-pack-index" ),
974+ num_chunks );
961975 for (i = 0 ; i < num_chunks ; i ++ ) {
962976 if (written != chunk_offsets [i ])
963977 BUG ("incorrect chunk offset (%" PRIu64 " != %" PRIu64 ") for chunk id %" PRIx32 ,
@@ -990,7 +1004,10 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
9901004 BUG ("trying to write unknown chunk id %" PRIx32 ,
9911005 chunk_ids [i ]);
9921006 }
1007+
1008+ display_progress (progress , i + 1 );
9931009 }
1010+ stop_progress (& progress );
9941011
9951012 if (written != chunk_offsets [num_chunks ])
9961013 BUG ("incorrect final offset %" PRIu64 " != %" PRIu64 ,
@@ -1016,9 +1033,9 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
10161033 return result ;
10171034}
10181035
1019- int write_midx_file (const char * object_dir )
1036+ int write_midx_file (const char * object_dir , unsigned flags )
10201037{
1021- return write_midx_internal (object_dir , NULL , NULL );
1038+ return write_midx_internal (object_dir , NULL , NULL , flags );
10221039}
10231040
10241041void clear_midx_file (struct repository * r )
@@ -1076,19 +1093,20 @@ static int compare_pair_pos_vs_id(const void *_a, const void *_b)
10761093 display_progress(progress, _n); \
10771094 } while (0)
10781095
1079- int verify_midx_file (struct repository * r , const char * object_dir )
1096+ int verify_midx_file (struct repository * r , const char * object_dir , unsigned flags )
10801097{
10811098 struct pair_pos_vs_id * pairs = NULL ;
10821099 uint32_t i ;
1083- struct progress * progress ;
1100+ struct progress * progress = NULL ;
10841101 struct multi_pack_index * m = load_multi_pack_index (object_dir , 1 );
10851102 verify_midx_error = 0 ;
10861103
10871104 if (!m )
10881105 return 0 ;
10891106
1090- progress = start_progress (_ ("Looking for referenced packfiles" ),
1091- m -> num_packs );
1107+ if (flags & MIDX_PROGRESS )
1108+ progress = start_progress (_ ("Looking for referenced packfiles" ),
1109+ m -> num_packs );
10921110 for (i = 0 ; i < m -> num_packs ; i ++ ) {
10931111 if (prepare_midx_pack (r , m , i ))
10941112 midx_report ("failed to load pack in position %d" , i );
@@ -1106,8 +1124,9 @@ int verify_midx_file(struct repository *r, const char *object_dir)
11061124 i , oid_fanout1 , oid_fanout2 , i + 1 );
11071125 }
11081126
1109- progress = start_sparse_progress (_ ("Verifying OID order in MIDX" ),
1110- m -> num_objects - 1 );
1127+ if (flags & MIDX_PROGRESS )
1128+ progress = start_sparse_progress (_ ("Verifying OID order in multi-pack-index" ),
1129+ m -> num_objects - 1 );
11111130 for (i = 0 ; i < m -> num_objects - 1 ; i ++ ) {
11121131 struct object_id oid1 , oid2 ;
11131132
@@ -1134,13 +1153,15 @@ int verify_midx_file(struct repository *r, const char *object_dir)
11341153 pairs [i ].pack_int_id = nth_midxed_pack_int_id (m , i );
11351154 }
11361155
1137- progress = start_sparse_progress (_ ("Sorting objects by packfile" ),
1138- m -> num_objects );
1156+ if (flags & MIDX_PROGRESS )
1157+ progress = start_sparse_progress (_ ("Sorting objects by packfile" ),
1158+ m -> num_objects );
11391159 display_progress (progress , 0 ); /* TODO: Measure QSORT() progress */
11401160 QSORT (pairs , m -> num_objects , compare_pair_pos_vs_id );
11411161 stop_progress (& progress );
11421162
1143- progress = start_sparse_progress (_ ("Verifying object offsets" ), m -> num_objects );
1163+ if (flags & MIDX_PROGRESS )
1164+ progress = start_sparse_progress (_ ("Verifying object offsets" ), m -> num_objects );
11441165 for (i = 0 ; i < m -> num_objects ; i ++ ) {
11451166 struct object_id oid ;
11461167 struct pack_entry e ;
@@ -1183,23 +1204,34 @@ int verify_midx_file(struct repository *r, const char *object_dir)
11831204 return verify_midx_error ;
11841205}
11851206
1186- int expire_midx_packs (struct repository * r , const char * object_dir )
1207+ int expire_midx_packs (struct repository * r , const char * object_dir , unsigned flags )
11871208{
11881209 uint32_t i , * count , result = 0 ;
11891210 struct string_list packs_to_drop = STRING_LIST_INIT_DUP ;
11901211 struct multi_pack_index * m = load_multi_pack_index (object_dir , 1 );
1212+ struct progress * progress = NULL ;
11911213
11921214 if (!m )
11931215 return 0 ;
11941216
11951217 count = xcalloc (m -> num_packs , sizeof (uint32_t ));
1218+
1219+ if (flags & MIDX_PROGRESS )
1220+ progress = start_progress (_ ("Counting referenced objects" ),
1221+ m -> num_objects );
11961222 for (i = 0 ; i < m -> num_objects ; i ++ ) {
11971223 int pack_int_id = nth_midxed_pack_int_id (m , i );
11981224 count [pack_int_id ]++ ;
1225+ display_progress (progress , i + 1 );
11991226 }
1227+ stop_progress (& progress );
12001228
1229+ if (flags & MIDX_PROGRESS )
1230+ progress = start_progress (_ ("Finding and deleting unreferenced packfiles" ),
1231+ m -> num_packs );
12011232 for (i = 0 ; i < m -> num_packs ; i ++ ) {
12021233 char * pack_name ;
1234+ display_progress (progress , i + 1 );
12031235
12041236 if (count [i ])
12051237 continue ;
@@ -1217,11 +1249,12 @@ int expire_midx_packs(struct repository *r, const char *object_dir)
12171249 unlink_pack_path (pack_name , 0 );
12181250 free (pack_name );
12191251 }
1252+ stop_progress (& progress );
12201253
12211254 free (count );
12221255
12231256 if (packs_to_drop .nr )
1224- result = write_midx_internal (object_dir , m , & packs_to_drop );
1257+ result = write_midx_internal (object_dir , m , & packs_to_drop , flags );
12251258
12261259 string_list_clear (& packs_to_drop , 0 );
12271260 return result ;
@@ -1315,7 +1348,7 @@ static int fill_included_packs_batch(struct repository *r,
13151348 return 0 ;
13161349}
13171350
1318- int midx_repack (struct repository * r , const char * object_dir , size_t batch_size )
1351+ int midx_repack (struct repository * r , const char * object_dir , size_t batch_size , unsigned flags )
13191352{
13201353 int result = 0 ;
13211354 uint32_t i ;
@@ -1340,6 +1373,12 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size)
13401373 strbuf_addstr (& base_name , object_dir );
13411374 strbuf_addstr (& base_name , "/pack/pack" );
13421375 argv_array_push (& cmd .args , base_name .buf );
1376+
1377+ if (flags & MIDX_PROGRESS )
1378+ argv_array_push (& cmd .args , "--progress" );
1379+ else
1380+ argv_array_push (& cmd .args , "-q" );
1381+
13431382 strbuf_release (& base_name );
13441383
13451384 cmd .git_cmd = 1 ;
@@ -1370,7 +1409,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size)
13701409 goto cleanup ;
13711410 }
13721411
1373- result = write_midx_internal (object_dir , m , NULL );
1412+ result = write_midx_internal (object_dir , m , NULL , flags );
13741413 m = NULL ;
13751414
13761415cleanup :
0 commit comments