@@ -448,6 +448,8 @@ struct pack_list {
448
448
uint32_t nr ;
449
449
uint32_t alloc ;
450
450
struct multi_pack_index * m ;
451
+ struct progress * progress ;
452
+ unsigned pack_paths_checked ;
451
453
};
452
454
453
455
static 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,
456
458
struct pack_list * packs = (struct pack_list * )data ;
457
459
458
460
if (ends_with (file_name , ".idx" )) {
461
+ display_progress (packs -> progress , ++ packs -> pack_paths_checked );
459
462
if (packs -> m && midx_contains_pack (packs -> m , file_name ))
460
463
return ;
461
464
@@ -785,7 +788,7 @@ static size_t write_midx_large_offsets(struct hashfile *f, uint32_t nr_large_off
785
788
}
786
789
787
790
static 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 )
789
792
{
790
793
unsigned char cur_chunk , num_chunks = 0 ;
791
794
char * midx_name ;
@@ -799,6 +802,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
799
802
uint64_t chunk_offsets [MIDX_MAX_CHUNKS + 1 ];
800
803
uint32_t nr_entries , num_large_offsets = 0 ;
801
804
struct pack_midx_entry * entries = NULL ;
805
+ struct progress * progress = NULL ;
802
806
int large_offsets_needed = 0 ;
803
807
int pack_name_concat_len = 0 ;
804
808
int dropped_packs = 0 ;
@@ -833,7 +837,14 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
833
837
}
834
838
}
835
839
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
+
836
846
for_each_file_in_pack_dir (object_dir , add_pack_to_midx , & packs );
847
+ stop_progress (& packs .progress );
837
848
838
849
if (packs .m && packs .nr == packs .m -> num_packs && !packs_to_drop )
839
850
goto cleanup ;
@@ -958,6 +969,9 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
958
969
written += MIDX_CHUNKLOOKUP_WIDTH ;
959
970
}
960
971
972
+ if (flags & MIDX_PROGRESS )
973
+ progress = start_progress (_ ("Writing chunks to multi-pack-index" ),
974
+ num_chunks );
961
975
for (i = 0 ; i < num_chunks ; i ++ ) {
962
976
if (written != chunk_offsets [i ])
963
977
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 *
990
1004
BUG ("trying to write unknown chunk id %" PRIx32 ,
991
1005
chunk_ids [i ]);
992
1006
}
1007
+
1008
+ display_progress (progress , i + 1 );
993
1009
}
1010
+ stop_progress (& progress );
994
1011
995
1012
if (written != chunk_offsets [num_chunks ])
996
1013
BUG ("incorrect final offset %" PRIu64 " != %" PRIu64 ,
@@ -1016,9 +1033,9 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
1016
1033
return result ;
1017
1034
}
1018
1035
1019
- int write_midx_file (const char * object_dir )
1036
+ int write_midx_file (const char * object_dir , unsigned flags )
1020
1037
{
1021
- return write_midx_internal (object_dir , NULL , NULL );
1038
+ return write_midx_internal (object_dir , NULL , NULL , flags );
1022
1039
}
1023
1040
1024
1041
void clear_midx_file (struct repository * r )
@@ -1076,19 +1093,20 @@ static int compare_pair_pos_vs_id(const void *_a, const void *_b)
1076
1093
display_progress(progress, _n); \
1077
1094
} while (0)
1078
1095
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 )
1080
1097
{
1081
1098
struct pair_pos_vs_id * pairs = NULL ;
1082
1099
uint32_t i ;
1083
- struct progress * progress ;
1100
+ struct progress * progress = NULL ;
1084
1101
struct multi_pack_index * m = load_multi_pack_index (object_dir , 1 );
1085
1102
verify_midx_error = 0 ;
1086
1103
1087
1104
if (!m )
1088
1105
return 0 ;
1089
1106
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 );
1092
1110
for (i = 0 ; i < m -> num_packs ; i ++ ) {
1093
1111
if (prepare_midx_pack (r , m , i ))
1094
1112
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)
1106
1124
i , oid_fanout1 , oid_fanout2 , i + 1 );
1107
1125
}
1108
1126
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 );
1111
1130
for (i = 0 ; i < m -> num_objects - 1 ; i ++ ) {
1112
1131
struct object_id oid1 , oid2 ;
1113
1132
@@ -1134,13 +1153,15 @@ int verify_midx_file(struct repository *r, const char *object_dir)
1134
1153
pairs [i ].pack_int_id = nth_midxed_pack_int_id (m , i );
1135
1154
}
1136
1155
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 );
1139
1159
display_progress (progress , 0 ); /* TODO: Measure QSORT() progress */
1140
1160
QSORT (pairs , m -> num_objects , compare_pair_pos_vs_id );
1141
1161
stop_progress (& progress );
1142
1162
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 );
1144
1165
for (i = 0 ; i < m -> num_objects ; i ++ ) {
1145
1166
struct object_id oid ;
1146
1167
struct pack_entry e ;
@@ -1183,23 +1204,34 @@ int verify_midx_file(struct repository *r, const char *object_dir)
1183
1204
return verify_midx_error ;
1184
1205
}
1185
1206
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 )
1187
1208
{
1188
1209
uint32_t i , * count , result = 0 ;
1189
1210
struct string_list packs_to_drop = STRING_LIST_INIT_DUP ;
1190
1211
struct multi_pack_index * m = load_multi_pack_index (object_dir , 1 );
1212
+ struct progress * progress = NULL ;
1191
1213
1192
1214
if (!m )
1193
1215
return 0 ;
1194
1216
1195
1217
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 );
1196
1222
for (i = 0 ; i < m -> num_objects ; i ++ ) {
1197
1223
int pack_int_id = nth_midxed_pack_int_id (m , i );
1198
1224
count [pack_int_id ]++ ;
1225
+ display_progress (progress , i + 1 );
1199
1226
}
1227
+ stop_progress (& progress );
1200
1228
1229
+ if (flags & MIDX_PROGRESS )
1230
+ progress = start_progress (_ ("Finding and deleting unreferenced packfiles" ),
1231
+ m -> num_packs );
1201
1232
for (i = 0 ; i < m -> num_packs ; i ++ ) {
1202
1233
char * pack_name ;
1234
+ display_progress (progress , i + 1 );
1203
1235
1204
1236
if (count [i ])
1205
1237
continue ;
@@ -1217,11 +1249,12 @@ int expire_midx_packs(struct repository *r, const char *object_dir)
1217
1249
unlink_pack_path (pack_name , 0 );
1218
1250
free (pack_name );
1219
1251
}
1252
+ stop_progress (& progress );
1220
1253
1221
1254
free (count );
1222
1255
1223
1256
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 );
1225
1258
1226
1259
string_list_clear (& packs_to_drop , 0 );
1227
1260
return result ;
@@ -1315,7 +1348,7 @@ static int fill_included_packs_batch(struct repository *r,
1315
1348
return 0 ;
1316
1349
}
1317
1350
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 )
1319
1352
{
1320
1353
int result = 0 ;
1321
1354
uint32_t i ;
@@ -1340,6 +1373,12 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size)
1340
1373
strbuf_addstr (& base_name , object_dir );
1341
1374
strbuf_addstr (& base_name , "/pack/pack" );
1342
1375
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
+
1343
1382
strbuf_release (& base_name );
1344
1383
1345
1384
cmd .git_cmd = 1 ;
@@ -1370,7 +1409,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size)
1370
1409
goto cleanup ;
1371
1410
}
1372
1411
1373
- result = write_midx_internal (object_dir , m , NULL );
1412
+ result = write_midx_internal (object_dir , m , NULL , flags );
1374
1413
m = NULL ;
1375
1414
1376
1415
cleanup :
0 commit comments