2121#include "../worktree.h"
2222#include "../wrapper.h"
2323#include "../write-or-die.h"
24+ #include "../revision.h"
25+ #include <wildmatch.h>
2426
2527/*
2628 * This backend uses the following flags in `ref_update::flags` for
@@ -1175,17 +1177,15 @@ static void prune_refs(struct files_ref_store *refs, struct ref_to_prune **refs_
11751177 */
11761178static int should_pack_ref (const char * refname ,
11771179 const struct object_id * oid , unsigned int ref_flags ,
1178- unsigned int pack_flags )
1180+ struct pack_refs_opts * opts )
11791181{
1182+ struct string_list_item * item ;
1183+
11801184 /* Do not pack per-worktree refs: */
11811185 if (parse_worktree_ref (refname , NULL , NULL , NULL ) !=
11821186 REF_WORKTREE_SHARED )
11831187 return 0 ;
11841188
1185- /* Do not pack non-tags unless PACK_REFS_ALL is set: */
1186- if (!(pack_flags & PACK_REFS_ALL ) && !starts_with (refname , "refs/tags/" ))
1187- return 0 ;
1188-
11891189 /* Do not pack symbolic refs: */
11901190 if (ref_flags & REF_ISSYMREF )
11911191 return 0 ;
@@ -1194,10 +1194,18 @@ static int should_pack_ref(const char *refname,
11941194 if (!ref_resolves_to_object (refname , the_repository , oid , ref_flags ))
11951195 return 0 ;
11961196
1197- return 1 ;
1197+ if (ref_excluded (opts -> exclusions , refname ))
1198+ return 0 ;
1199+
1200+ for_each_string_list_item (item , opts -> includes )
1201+ if (!wildmatch (item -> string , refname , 0 ))
1202+ return 1 ;
1203+
1204+ return 0 ;
11981205}
11991206
1200- static int files_pack_refs (struct ref_store * ref_store , unsigned int flags )
1207+ static int files_pack_refs (struct ref_store * ref_store ,
1208+ struct pack_refs_opts * opts )
12011209{
12021210 struct files_ref_store * refs =
12031211 files_downcast (ref_store , REF_STORE_WRITE | REF_STORE_ODB ,
@@ -1222,8 +1230,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
12221230 * in the packed ref cache. If the reference should be
12231231 * pruned, also add it to refs_to_prune.
12241232 */
1225- if (!should_pack_ref (iter -> refname , iter -> oid , iter -> flags ,
1226- flags ))
1233+ if (!should_pack_ref (iter -> refname , iter -> oid , iter -> flags , opts ))
12271234 continue ;
12281235
12291236 /*
@@ -1237,7 +1244,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags)
12371244 iter -> refname , err .buf );
12381245
12391246 /* Schedule the loose reference for pruning if requested. */
1240- if ((flags & PACK_REFS_PRUNE )) {
1247+ if ((opts -> flags & PACK_REFS_PRUNE )) {
12411248 struct ref_to_prune * n ;
12421249 FLEX_ALLOC_STR (n , name , iter -> refname );
12431250 oidcpy (& n -> oid , iter -> oid );
0 commit comments