@@ -303,6 +303,8 @@ struct pack_geometry {
303
303
struct packed_git * * pack ;
304
304
uint32_t pack_nr , pack_alloc ;
305
305
uint32_t split ;
306
+
307
+ int split_factor ;
306
308
};
307
309
308
310
static uint32_t geometry_pack_weight (struct packed_git * p )
@@ -324,17 +326,13 @@ static int geometry_cmp(const void *va, const void *vb)
324
326
return 0 ;
325
327
}
326
328
327
- static void init_pack_geometry (struct pack_geometry * * geometry_p ,
329
+ static void init_pack_geometry (struct pack_geometry * geometry ,
328
330
struct string_list * existing_kept_packs ,
329
331
const struct pack_objects_args * args )
330
332
{
331
333
struct packed_git * p ;
332
- struct pack_geometry * geometry ;
333
334
struct strbuf buf = STRBUF_INIT ;
334
335
335
- * geometry_p = xcalloc (1 , sizeof (struct pack_geometry ));
336
- geometry = * geometry_p ;
337
-
338
336
for (p = get_all_packs (the_repository ); p ; p = p -> next ) {
339
337
if (args -> local && !p -> pack_local )
340
338
/*
@@ -380,7 +378,7 @@ static void init_pack_geometry(struct pack_geometry **geometry_p,
380
378
strbuf_release (& buf );
381
379
}
382
380
383
- static void split_pack_geometry (struct pack_geometry * geometry , int factor )
381
+ static void split_pack_geometry (struct pack_geometry * geometry )
384
382
{
385
383
uint32_t i ;
386
384
uint32_t split ;
@@ -399,12 +397,14 @@ static void split_pack_geometry(struct pack_geometry *geometry, int factor)
399
397
struct packed_git * ours = geometry -> pack [i ];
400
398
struct packed_git * prev = geometry -> pack [i - 1 ];
401
399
402
- if (unsigned_mult_overflows (factor , geometry_pack_weight (prev )))
400
+ if (unsigned_mult_overflows (geometry -> split_factor ,
401
+ geometry_pack_weight (prev )))
403
402
die (_ ("pack %s too large to consider in geometric "
404
403
"progression" ),
405
404
prev -> pack_name );
406
405
407
- if (geometry_pack_weight (ours ) < factor * geometry_pack_weight (prev ))
406
+ if (geometry_pack_weight (ours ) <
407
+ geometry -> split_factor * geometry_pack_weight (prev ))
408
408
break ;
409
409
}
410
410
@@ -439,10 +439,12 @@ static void split_pack_geometry(struct pack_geometry *geometry, int factor)
439
439
for (i = split ; i < geometry -> pack_nr ; i ++ ) {
440
440
struct packed_git * ours = geometry -> pack [i ];
441
441
442
- if (unsigned_mult_overflows (factor , total_size ))
442
+ if (unsigned_mult_overflows (geometry -> split_factor ,
443
+ total_size ))
443
444
die (_ ("pack %s too large to roll up" ), ours -> pack_name );
444
445
445
- if (geometry_pack_weight (ours ) < factor * total_size ) {
446
+ if (geometry_pack_weight (ours ) <
447
+ geometry -> split_factor * total_size ) {
446
448
if (unsigned_add_overflows (total_size ,
447
449
geometry_pack_weight (ours )))
448
450
die (_ ("pack %s too large to roll up" ),
@@ -498,7 +500,6 @@ static void free_pack_geometry(struct pack_geometry *geometry)
498
500
return ;
499
501
500
502
free (geometry -> pack );
501
- free (geometry );
502
503
}
503
504
504
505
struct midx_snapshot_ref_data {
@@ -575,7 +576,7 @@ static void midx_included_packs(struct string_list *include,
575
576
string_list_insert (include , xstrfmt ("%s.idx" , item -> string ));
576
577
for_each_string_list_item (item , names )
577
578
string_list_insert (include , xstrfmt ("pack-%s.idx" , item -> string ));
578
- if (geometry ) {
579
+ if (geometry -> split_factor ) {
579
580
struct strbuf buf = STRBUF_INIT ;
580
581
uint32_t i ;
581
582
for (i = geometry -> split ; i < geometry -> pack_nr ; i ++ ) {
@@ -779,7 +780,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
779
780
struct string_list names = STRING_LIST_INIT_DUP ;
780
781
struct string_list existing_nonkept_packs = STRING_LIST_INIT_DUP ;
781
782
struct string_list existing_kept_packs = STRING_LIST_INIT_DUP ;
782
- struct pack_geometry * geometry = NULL ;
783
+ struct pack_geometry geometry = { 0 } ;
783
784
struct strbuf line = STRBUF_INIT ;
784
785
struct tempfile * refs_snapshot = NULL ;
785
786
int i , ext , ret ;
@@ -793,7 +794,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
793
794
struct string_list keep_pack_list = STRING_LIST_INIT_NODUP ;
794
795
struct pack_objects_args po_args = {NULL };
795
796
struct pack_objects_args cruft_po_args = {NULL };
796
- int geometric_factor = 0 ;
797
797
int write_midx = 0 ;
798
798
const char * cruft_expiration = NULL ;
799
799
const char * expire_to = NULL ;
@@ -842,7 +842,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
842
842
N_ ("repack objects in packs marked with .keep" )),
843
843
OPT_STRING_LIST (0 , "keep-pack" , & keep_pack_list , N_ ("name" ),
844
844
N_ ("do not repack this pack" )),
845
- OPT_INTEGER ('g' , "geometric" , & geometric_factor ,
845
+ OPT_INTEGER ('g' , "geometric" , & geometry . split_factor ,
846
846
N_ ("find a geometric progression with factor <N>" )),
847
847
OPT_BOOL ('m' , "write-midx" , & write_midx ,
848
848
N_ ("write a multi-pack index of the resulting packs" )),
@@ -918,11 +918,11 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
918
918
collect_pack_filenames (& existing_nonkept_packs , & existing_kept_packs ,
919
919
& keep_pack_list );
920
920
921
- if (geometric_factor ) {
921
+ if (geometry . split_factor ) {
922
922
if (pack_everything )
923
923
die (_ ("options '%s' and '%s' cannot be used together" ), "--geometric" , "-A/-a" );
924
924
init_pack_geometry (& geometry , & existing_kept_packs , & po_args );
925
- split_pack_geometry (geometry , geometric_factor );
925
+ split_pack_geometry (& geometry );
926
926
}
927
927
928
928
prepare_pack_objects (& cmd , & po_args , packtmp );
@@ -936,7 +936,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
936
936
strvec_pushf (& cmd .args , "--keep-pack=%s" ,
937
937
keep_pack_list .items [i ].string );
938
938
strvec_push (& cmd .args , "--non-empty" );
939
- if (!geometry ) {
939
+ if (!geometry . split_factor ) {
940
940
/*
941
941
* We need to grab all reachable objects, including those that
942
942
* are reachable from reflogs and the index.
@@ -983,15 +983,15 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
983
983
strvec_push (& cmd .args , "--pack-loose-unreachable" );
984
984
}
985
985
}
986
- } else if (geometry ) {
986
+ } else if (geometry . split_factor ) {
987
987
strvec_push (& cmd .args , "--stdin-packs" );
988
988
strvec_push (& cmd .args , "--unpacked" );
989
989
} else {
990
990
strvec_push (& cmd .args , "--unpacked" );
991
991
strvec_push (& cmd .args , "--incremental" );
992
992
}
993
993
994
- if (geometry )
994
+ if (geometry . split_factor )
995
995
cmd .in = -1 ;
996
996
else
997
997
cmd .no_stdin = 1 ;
@@ -1000,17 +1000,17 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
1000
1000
if (ret )
1001
1001
goto cleanup ;
1002
1002
1003
- if (geometry ) {
1003
+ if (geometry . split_factor ) {
1004
1004
FILE * in = xfdopen (cmd .in , "w" );
1005
1005
/*
1006
1006
* The resulting pack should contain all objects in packs that
1007
1007
* are going to be rolled up, but exclude objects in packs which
1008
1008
* are being left alone.
1009
1009
*/
1010
- for (i = 0 ; i < geometry -> split ; i ++ )
1011
- fprintf (in , "%s\n" , pack_basename (geometry -> pack [i ]));
1012
- for (i = geometry -> split ; i < geometry -> pack_nr ; i ++ )
1013
- fprintf (in , "^%s\n" , pack_basename (geometry -> pack [i ]));
1010
+ for (i = 0 ; i < geometry . split ; i ++ )
1011
+ fprintf (in , "%s\n" , pack_basename (geometry . pack [i ]));
1012
+ for (i = geometry . split ; i < geometry . pack_nr ; i ++ )
1013
+ fprintf (in , "^%s\n" , pack_basename (geometry . pack [i ]));
1014
1014
fclose (in );
1015
1015
}
1016
1016
@@ -1153,9 +1153,9 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
1153
1153
if (write_midx ) {
1154
1154
struct string_list include = STRING_LIST_INIT_NODUP ;
1155
1155
midx_included_packs (& include , & existing_nonkept_packs ,
1156
- & existing_kept_packs , & names , geometry );
1156
+ & existing_kept_packs , & names , & geometry );
1157
1157
1158
- ret = write_midx_included_packs (& include , geometry ,
1158
+ ret = write_midx_included_packs (& include , & geometry ,
1159
1159
refs_snapshot ? get_tempfile_path (refs_snapshot ) : NULL ,
1160
1160
show_progress , write_bitmaps > 0 );
1161
1161
@@ -1178,12 +1178,12 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
1178
1178
remove_redundant_pack (packdir , item -> string );
1179
1179
}
1180
1180
1181
- if (geometry ) {
1181
+ if (geometry . split_factor ) {
1182
1182
struct strbuf buf = STRBUF_INIT ;
1183
1183
1184
1184
uint32_t i ;
1185
- for (i = 0 ; i < geometry -> split ; i ++ ) {
1186
- struct packed_git * p = geometry -> pack [i ];
1185
+ for (i = 0 ; i < geometry . split ; i ++ ) {
1186
+ struct packed_git * p = geometry . pack [i ];
1187
1187
if (string_list_has_string (& names ,
1188
1188
hash_to_hex (p -> hash )))
1189
1189
continue ;
@@ -1226,7 +1226,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
1226
1226
string_list_clear (& names , 1 );
1227
1227
string_list_clear (& existing_nonkept_packs , 0 );
1228
1228
string_list_clear (& existing_kept_packs , 0 );
1229
- free_pack_geometry (geometry );
1229
+ free_pack_geometry (& geometry );
1230
1230
1231
1231
return ret ;
1232
1232
}
0 commit comments