gc: handle a corner case in gc.bigPackThreshold
[gitweb.git] / builtin / gc.c
index 81ecdc5ffa5006391db7ec9c7585f19a4016d24f..23c17ba7e99bce4e6dabd789a89deddc14abd15d 100644 (file)
@@ -253,8 +253,14 @@ static int need_to_gc(void)
        if (too_many_packs()) {
                struct string_list keep_pack = STRING_LIST_INIT_NODUP;
 
-               if (big_pack_threshold)
+               if (big_pack_threshold) {
                        find_base_packs(&keep_pack, big_pack_threshold);
+                       if (keep_pack.nr >= gc_auto_pack_limit) {
+                               big_pack_threshold = 0;
+                               string_list_clear(&keep_pack, 0);
+                               find_base_packs(&keep_pack, 0);
+                       }
+               }
 
                add_repack_all_option(&keep_pack);
                string_list_clear(&keep_pack, 0);