@@ -1022,29 +1022,13 @@ static int write_filtered_pack(const struct pack_objects_args *args,
1022
1022
return finish_pack_objects_cmd (& cmd , names , local );
1023
1023
}
1024
1024
1025
- static int existing_cruft_pack_cmp (const void * va , const void * vb )
1025
+ static void combine_small_cruft_packs (FILE * in , size_t combine_cruft_below_size ,
1026
+ struct existing_packs * existing )
1026
1027
{
1027
- struct packed_git * a = * (struct packed_git * * )va ;
1028
- struct packed_git * b = * (struct packed_git * * )vb ;
1029
-
1030
- if (a -> pack_size < b -> pack_size )
1031
- return -1 ;
1032
- if (a -> pack_size > b -> pack_size )
1033
- return 1 ;
1034
- return 0 ;
1035
- }
1036
-
1037
- static void collapse_small_cruft_packs (FILE * in , size_t max_size ,
1038
- struct existing_packs * existing )
1039
- {
1040
- struct packed_git * * existing_cruft , * p ;
1028
+ struct packed_git * p ;
1041
1029
struct strbuf buf = STRBUF_INIT ;
1042
- size_t total_size = 0 ;
1043
- size_t existing_cruft_nr = 0 ;
1044
1030
size_t i ;
1045
1031
1046
- ALLOC_ARRAY (existing_cruft , existing -> cruft_packs .nr );
1047
-
1048
1032
for (p = get_all_packs (the_repository ); p ; p = p -> next ) {
1049
1033
if (!(p -> is_cruft && p -> pack_local ))
1050
1034
continue ;
@@ -1056,24 +1040,7 @@ static void collapse_small_cruft_packs(FILE *in, size_t max_size,
1056
1040
if (!string_list_has_string (& existing -> cruft_packs , buf .buf ))
1057
1041
continue ;
1058
1042
1059
- if (existing_cruft_nr >= existing -> cruft_packs .nr )
1060
- BUG ("too many cruft packs (found %" PRIuMAX ", but knew "
1061
- "of %" PRIuMAX ")" ,
1062
- (uintmax_t )existing_cruft_nr + 1 ,
1063
- (uintmax_t )existing -> cruft_packs .nr );
1064
- existing_cruft [existing_cruft_nr ++ ] = p ;
1065
- }
1066
-
1067
- QSORT (existing_cruft , existing_cruft_nr , existing_cruft_pack_cmp );
1068
-
1069
- for (i = 0 ; i < existing_cruft_nr ; i ++ ) {
1070
- size_t proposed ;
1071
-
1072
- p = existing_cruft [i ];
1073
- proposed = st_add (total_size , p -> pack_size );
1074
-
1075
- if (proposed <= max_size ) {
1076
- total_size = proposed ;
1043
+ if (p -> pack_size < combine_cruft_below_size ) {
1077
1044
fprintf (in , "-%s\n" , pack_basename (p ));
1078
1045
} else {
1079
1046
retain_cruft_pack (existing , p );
@@ -1086,13 +1053,13 @@ static void collapse_small_cruft_packs(FILE *in, size_t max_size,
1086
1053
existing -> non_kept_packs .items [i ].string );
1087
1054
1088
1055
strbuf_release (& buf );
1089
- free (existing_cruft );
1090
1056
}
1091
1057
1092
1058
static int write_cruft_pack (const struct pack_objects_args * args ,
1093
1059
const char * destination ,
1094
1060
const char * pack_prefix ,
1095
1061
const char * cruft_expiration ,
1062
+ unsigned long combine_cruft_below_size ,
1096
1063
struct string_list * names ,
1097
1064
struct existing_packs * existing )
1098
1065
{
@@ -1135,8 +1102,9 @@ static int write_cruft_pack(const struct pack_objects_args *args,
1135
1102
in = xfdopen (cmd .in , "w" );
1136
1103
for_each_string_list_item (item , names )
1137
1104
fprintf (in , "%s-%s.pack\n" , pack_prefix , item -> string );
1138
- if (args -> max_pack_size && !cruft_expiration ) {
1139
- collapse_small_cruft_packs (in , args -> max_pack_size , existing );
1105
+ if (combine_cruft_below_size && !cruft_expiration ) {
1106
+ combine_small_cruft_packs (in , combine_cruft_below_size ,
1107
+ existing );
1140
1108
} else {
1141
1109
for_each_string_list_item (item , & existing -> non_kept_packs )
1142
1110
fprintf (in , "-%s.pack\n" , item -> string );
@@ -1190,6 +1158,7 @@ int cmd_repack(int argc,
1190
1158
const char * opt_window_memory = NULL ;
1191
1159
const char * opt_depth = NULL ;
1192
1160
const char * opt_threads = NULL ;
1161
+ unsigned long combine_cruft_below_size = 0ul ;
1193
1162
1194
1163
struct option builtin_repack_options [] = {
1195
1164
OPT_BIT ('a' , NULL , & pack_everything ,
@@ -1202,6 +1171,9 @@ int cmd_repack(int argc,
1202
1171
PACK_CRUFT ),
1203
1172
OPT_STRING (0 , "cruft-expiration" , & cruft_expiration , N_ ("approxidate" ),
1204
1173
N_ ("with --cruft, expire objects older than this" )),
1174
+ OPT_MAGNITUDE (0 , "combine-cruft-below-size" ,
1175
+ & combine_cruft_below_size ,
1176
+ N_ ("with --cruft, only repack cruft packs smaller than this" )),
1205
1177
OPT_MAGNITUDE (0 , "max-cruft-size" , & cruft_po_args .max_pack_size ,
1206
1178
N_ ("with --cruft, limit the size of new cruft packs" )),
1207
1179
OPT_BOOL ('d' , NULL , & delete_redundant ,
@@ -1445,7 +1417,8 @@ int cmd_repack(int argc,
1445
1417
cruft_po_args .quiet = po_args .quiet ;
1446
1418
1447
1419
ret = write_cruft_pack (& cruft_po_args , packtmp , pack_prefix ,
1448
- cruft_expiration , & names ,
1420
+ cruft_expiration ,
1421
+ combine_cruft_below_size , & names ,
1449
1422
& existing );
1450
1423
if (ret )
1451
1424
goto cleanup ;
@@ -1472,10 +1445,17 @@ int cmd_repack(int argc,
1472
1445
* generate an empty pack (since every object not in the
1473
1446
* cruft pack generated above will have an mtime older
1474
1447
* than the expiration).
1448
+ *
1449
+ * Pretend we don't have a `--combine-cruft-below-size`
1450
+ * argument, since we're not selectively combining
1451
+ * anything based on size to generate the limbo cruft
1452
+ * pack, but rather removing all cruft packs from the
1453
+ * main repository regardless of size.
1475
1454
*/
1476
1455
ret = write_cruft_pack (& cruft_po_args , expire_to ,
1477
1456
pack_prefix ,
1478
1457
NULL ,
1458
+ 0ul ,
1479
1459
& names ,
1480
1460
& existing );
1481
1461
if (ret )
0 commit comments