3030#include "list.h"
3131#include "packfile.h"
3232#include "object-store.h"
33+ #include "dir.h"
3334
3435static const char * pack_usage [] = {
3536 N_ ("git pack-objects --stdout [<options>...] [< <ref-list> | < <object-list>]" ),
@@ -55,7 +56,8 @@ static int pack_loose_unreachable;
5556static int local ;
5657static int have_non_local_packs ;
5758static int incremental ;
58- static int ignore_packed_keep ;
59+ static int ignore_packed_keep_on_disk ;
60+ static int ignore_packed_keep_in_core ;
5961static int allow_ofs_delta ;
6062static struct pack_idx_option pack_idx_opts ;
6163static const char * base_name ;
@@ -982,13 +984,16 @@ static int want_found_object(int exclude, struct packed_git *p)
982984 * Otherwise, we signal "-1" at the end to tell the caller that we do
983985 * not know either way, and it needs to check more packs.
984986 */
985- if (!ignore_packed_keep &&
987+ if (!ignore_packed_keep_on_disk &&
988+ !ignore_packed_keep_in_core &&
986989 (!local || !have_non_local_packs ))
987990 return 1 ;
988991
989992 if (local && !p -> pack_local )
990993 return 0 ;
991- if (ignore_packed_keep && p -> pack_local && p -> pack_keep )
994+ if (p -> pack_local &&
995+ ((ignore_packed_keep_on_disk && p -> pack_keep ) ||
996+ (ignore_packed_keep_in_core && p -> pack_keep_in_core )))
992997 return 0 ;
993998
994999 /* we don't know yet; keep looking for more packs */
@@ -2675,7 +2680,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)
26752680 struct object_id oid ;
26762681 struct object * o ;
26772682
2678- if (!p -> pack_local || p -> pack_keep )
2683+ if (!p -> pack_local || p -> pack_keep || p -> pack_keep_in_core )
26792684 continue ;
26802685 if (open_pack_index (p ))
26812686 die ("cannot open pack index" );
@@ -2738,7 +2743,8 @@ static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
27382743 get_packed_git (the_repository );
27392744
27402745 while (p ) {
2741- if ((!p -> pack_local || p -> pack_keep ) &&
2746+ if ((!p -> pack_local || p -> pack_keep ||
2747+ p -> pack_keep_in_core ) &&
27422748 find_pack_entry_one (oid -> hash , p )) {
27432749 last_found = p ;
27442750 return 1 ;
@@ -2781,7 +2787,7 @@ static void loosen_unused_packed_objects(struct rev_info *revs)
27812787 struct object_id oid ;
27822788
27832789 for (p = get_packed_git (the_repository ); p ; p = p -> next ) {
2784- if (!p -> pack_local || p -> pack_keep )
2790+ if (!p -> pack_local || p -> pack_keep || p -> pack_keep_in_core )
27852791 continue ;
27862792
27872793 if (open_pack_index (p ))
@@ -2807,7 +2813,8 @@ static int pack_options_allow_reuse(void)
28072813{
28082814 return pack_to_stdout &&
28092815 allow_ofs_delta &&
2810- !ignore_packed_keep &&
2816+ !ignore_packed_keep_on_disk &&
2817+ !ignore_packed_keep_in_core &&
28112818 (!local || !have_non_local_packs ) &&
28122819 !incremental ;
28132820}
@@ -2916,6 +2923,32 @@ static void get_object_list(int ac, const char **av)
29162923 oid_array_clear (& recent_objects );
29172924}
29182925
2926+ static void add_extra_kept_packs (const struct string_list * names )
2927+ {
2928+ struct packed_git * p ;
2929+
2930+ if (!names -> nr )
2931+ return ;
2932+
2933+ for (p = get_packed_git (the_repository ); p ; p = p -> next ) {
2934+ const char * name = basename (p -> pack_name );
2935+ int i ;
2936+
2937+ if (!p -> pack_local )
2938+ continue ;
2939+
2940+ for (i = 0 ; i < names -> nr ; i ++ )
2941+ if (!fspathcmp (name , names -> items [i ].string ))
2942+ break ;
2943+
2944+ if (i < names -> nr ) {
2945+ p -> pack_keep_in_core = 1 ;
2946+ ignore_packed_keep_in_core = 1 ;
2947+ continue ;
2948+ }
2949+ }
2950+ }
2951+
29192952static int option_parse_index_version (const struct option * opt ,
29202953 const char * arg , int unset )
29212954{
@@ -2955,6 +2988,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
29552988 struct argv_array rp = ARGV_ARRAY_INIT ;
29562989 int rev_list_unpacked = 0 , rev_list_all = 0 , rev_list_reflog = 0 ;
29572990 int rev_list_index = 0 ;
2991+ struct string_list keep_pack_list = STRING_LIST_INIT_NODUP ;
29582992 struct option pack_objects_options [] = {
29592993 OPT_SET_INT ('q' , "quiet" , & progress ,
29602994 N_ ("do not show progress meter" ), 0 ),
@@ -3019,8 +3053,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
30193053 N_ ("create thin packs" )),
30203054 OPT_BOOL (0 , "shallow" , & shallow ,
30213055 N_ ("create packs suitable for shallow fetches" )),
3022- OPT_BOOL (0 , "honor-pack-keep" , & ignore_packed_keep ,
3056+ OPT_BOOL (0 , "honor-pack-keep" , & ignore_packed_keep_on_disk ,
30233057 N_ ("ignore packs that have companion .keep file" )),
3058+ OPT_STRING_LIST (0 , "keep-pack" , & keep_pack_list , N_ ("name" ),
3059+ N_ ("ignore this pack" )),
30243060 OPT_INTEGER (0 , "compression" , & pack_compression_level ,
30253061 N_ ("pack compression level" )),
30263062 OPT_SET_INT (0 , "keep-true-parents" , & grafts_replace_parents ,
@@ -3148,19 +3184,20 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
31483184 if (progress && all_progress_implied )
31493185 progress = 2 ;
31503186
3151- if (ignore_packed_keep ) {
3187+ add_extra_kept_packs (& keep_pack_list );
3188+ if (ignore_packed_keep_on_disk ) {
31523189 struct packed_git * p ;
31533190 for (p = get_packed_git (the_repository ); p ; p = p -> next )
31543191 if (p -> pack_local && p -> pack_keep )
31553192 break ;
31563193 if (!p ) /* no keep-able packs found */
3157- ignore_packed_keep = 0 ;
3194+ ignore_packed_keep_on_disk = 0 ;
31583195 }
31593196 if (local ) {
31603197 /*
3161- * unlike ignore_packed_keep above, we do not want to
3162- * unset "local" based on looking at packs, as it
3163- * also covers non-local objects
3198+ * unlike ignore_packed_keep_on_disk above, we do not
3199+ * want to unset "local" based on looking at packs, as
3200+ * it also covers non-local objects
31643201 */
31653202 struct packed_git * p ;
31663203 for (p = get_packed_git (the_repository ); p ; p = p -> next ) {
0 commit comments