@@ -15,17 +15,16 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix)
{
unsigned int flags = PACK_REFS_PRUNE;
static struct ref_visibility visibility = REF_VISIBILITY_INIT;
- static struct string_list included_refs = STRING_LIST_INIT_NODUP;
struct pack_refs_opts pack_refs_opts = { .visibility = &visibility,
- .includes = &included_refs,
.flags = flags };
static struct string_list option_excluded_refs = STRING_LIST_INIT_NODUP;
+ static struct string_list option_included_refs = STRING_LIST_INIT_NODUP;
struct string_list_item *item;
struct option opts[] = {
OPT_BIT(0, "all", &pack_refs_opts.flags, N_("pack everything"), PACK_REFS_ALL),
OPT_BIT(0, "prune", &pack_refs_opts.flags, N_("prune loose refs (default)"), PACK_REFS_PRUNE),
- OPT_STRING_LIST(0, "include", pack_refs_opts.includes, N_("pattern"),
+ OPT_STRING_LIST(0, "include", &option_included_refs, N_("pattern"),
N_("references to include")),
OPT_STRING_LIST(0, "exclude", &option_excluded_refs, N_("pattern"),
N_("references to exclude")),
@@ -38,11 +37,14 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix)
for_each_string_list_item(item, &option_excluded_refs)
add_ref_exclusion(pack_refs_opts.visibility, item->string);
+ for_each_string_list_item(item, &option_included_refs)
+ add_ref_inclusion(pack_refs_opts.visibility, item->string);
+
if (pack_refs_opts.flags & PACK_REFS_ALL)
- string_list_append(pack_refs_opts.includes, "*");
+ add_ref_inclusion(pack_refs_opts.visibility, "*");
- if (!pack_refs_opts.includes->nr)
- string_list_append(pack_refs_opts.includes, "refs/tags/*");
+ if (!option_included_refs.nr)
+ add_ref_inclusion(pack_refs_opts.visibility, "refs/tags/*");
return refs_pack_refs(get_main_ref_store(the_repository), &pack_refs_opts);
}
@@ -1179,8 +1179,6 @@ static int should_pack_ref(const char *refname,
const struct object_id *oid, unsigned int ref_flags,
struct pack_refs_opts *opts)
{
- struct string_list_item *item;
-
/* Do not pack per-worktree refs: */
if (parse_worktree_ref(refname, NULL, NULL, NULL) !=
REF_WORKTREE_SHARED)
@@ -1194,14 +1192,7 @@ static int should_pack_ref(const char *refname,
if (!ref_resolves_to_object(refname, the_repository, oid, ref_flags))
return 0;
- if (ref_excluded(opts->visibility, refname))
- return 0;
-
- for_each_string_list_item(item, opts->includes)
- if (!wildmatch(item->string, refname, 0))
- return 1;
-
- return 0;
+ return ref_visible(opts->visibility, refname);
}
static int files_pack_refs(struct ref_store *ref_store,
@@ -118,13 +118,11 @@ static int cmd_pack_refs(struct ref_store *refs, const char **argv)
{
unsigned int flags = arg_flags(*argv++, "flags", pack_flags);
static struct ref_visibility visibility = REF_VISIBILITY_INIT;
- static struct string_list included_refs = STRING_LIST_INIT_NODUP;
struct pack_refs_opts pack_opts = { .flags = flags,
- .visibility = &visibility,
- .includes = &included_refs };
+ .visibility = &visibility };
if (pack_opts.flags & PACK_REFS_ALL)
- string_list_append(pack_opts.includes, "*");
+ add_ref_inclusion(&visibility, "*");
return refs_pack_refs(refs, &pack_opts);
}