@@ -137,6 +137,8 @@ static void collect_pack_filenames(struct string_list *fname_nonkept_list,
137
137
string_list_append_nodup (fname_nonkept_list , fname );
138
138
}
139
139
closedir (dir );
140
+
141
+ string_list_sort (fname_kept_list );
140
142
}
141
143
142
144
static void remove_redundant_pack (const char * dir_name , const char * base_name )
@@ -332,17 +334,38 @@ static int geometry_cmp(const void *va, const void *vb)
332
334
return 0 ;
333
335
}
334
336
335
- static void init_pack_geometry (struct pack_geometry * * geometry_p )
337
+ static void init_pack_geometry (struct pack_geometry * * geometry_p ,
338
+ struct string_list * existing_kept_packs )
336
339
{
337
340
struct packed_git * p ;
338
341
struct pack_geometry * geometry ;
342
+ struct strbuf buf = STRBUF_INIT ;
339
343
340
344
* geometry_p = xcalloc (1 , sizeof (struct pack_geometry ));
341
345
geometry = * geometry_p ;
342
346
343
347
for (p = get_all_packs (the_repository ); p ; p = p -> next ) {
344
- if (!pack_kept_objects && p -> pack_keep )
345
- continue ;
348
+ if (!pack_kept_objects ) {
349
+ /*
350
+ * Any pack that has its pack_keep bit set will appear
351
+ * in existing_kept_packs below, but this saves us from
352
+ * doing a more expensive check.
353
+ */
354
+ if (p -> pack_keep )
355
+ continue ;
356
+
357
+ /*
358
+ * The pack may be kept via the --keep-pack option;
359
+ * check 'existing_kept_packs' to determine whether to
360
+ * ignore it.
361
+ */
362
+ strbuf_reset (& buf );
363
+ strbuf_addstr (& buf , pack_basename (p ));
364
+ strbuf_strip_suffix (& buf , ".pack" );
365
+
366
+ if (string_list_has_string (existing_kept_packs , buf .buf ))
367
+ continue ;
368
+ }
346
369
347
370
ALLOC_GROW (geometry -> pack ,
348
371
geometry -> pack_nr + 1 ,
@@ -353,6 +376,7 @@ static void init_pack_geometry(struct pack_geometry **geometry_p)
353
376
}
354
377
355
378
QSORT (geometry -> pack , geometry -> pack_nr , geometry_cmp );
379
+ strbuf_release (& buf );
356
380
}
357
381
358
382
static void split_pack_geometry (struct pack_geometry * geometry , int factor )
@@ -714,17 +738,20 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
714
738
strbuf_release (& path );
715
739
}
716
740
741
+ packdir = mkpathdup ("%s/pack" , get_object_directory ());
742
+ packtmp_name = xstrfmt (".tmp-%d-pack" , (int )getpid ());
743
+ packtmp = mkpathdup ("%s/%s" , packdir , packtmp_name );
744
+
745
+ collect_pack_filenames (& existing_nonkept_packs , & existing_kept_packs ,
746
+ & keep_pack_list );
747
+
717
748
if (geometric_factor ) {
718
749
if (pack_everything )
719
750
die (_ ("options '%s' and '%s' cannot be used together" ), "--geometric" , "-A/-a" );
720
- init_pack_geometry (& geometry );
751
+ init_pack_geometry (& geometry , & existing_kept_packs );
721
752
split_pack_geometry (geometry , geometric_factor );
722
753
}
723
754
724
- packdir = mkpathdup ("%s/pack" , get_object_directory ());
725
- packtmp_name = xstrfmt (".tmp-%d-pack" , (int )getpid ());
726
- packtmp = mkpathdup ("%s/%s" , packdir , packtmp_name );
727
-
728
755
sigchain_push_common (remove_pack_on_signal );
729
756
730
757
prepare_pack_objects (& cmd , & po_args );
@@ -764,9 +791,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
764
791
if (use_delta_islands )
765
792
strvec_push (& cmd .args , "--delta-islands" );
766
793
767
- collect_pack_filenames (& existing_nonkept_packs , & existing_kept_packs ,
768
- & keep_pack_list );
769
-
770
794
if (pack_everything & ALL_INTO_ONE ) {
771
795
repack_promisor_objects (& po_args , & names );
772
796
@@ -832,6 +856,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
832
856
if (!names .nr && !po_args .quiet )
833
857
printf_ln (_ ("Nothing new to pack." ));
834
858
859
+ string_list_sort (& names );
860
+
835
861
for_each_string_list_item (item , & names ) {
836
862
item -> util = (void * )(uintptr_t )populate_pack_exts (item -> string );
837
863
}
@@ -872,7 +898,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
872
898
873
899
if (delete_redundant && pack_everything & ALL_INTO_ONE ) {
874
900
const int hexsz = the_hash_algo -> hexsz ;
875
- string_list_sort (& names );
876
901
for_each_string_list_item (item , & existing_nonkept_packs ) {
877
902
char * sha1 ;
878
903
size_t len = strlen (item -> string );
0 commit comments