builtin/show: do not prune by pathspec
[git/mjg.git] / builtin / pack-refs.c
blob2d83c1ed2ac8c7fcf5568e46f56ae308447cfadf
1 #define USE_THE_REPOSITORY_VARIABLE
2 #include "builtin.h"
3 #include "config.h"
4 #include "gettext.h"
5 #include "parse-options.h"
6 #include "refs.h"
7 #include "revision.h"
9 static char const * const pack_refs_usage[] = {
10 N_("git pack-refs [--all] [--no-prune] [--auto] [--include <pattern>] [--exclude <pattern>]"),
11 NULL
14 int cmd_pack_refs(int argc,
15 const char **argv,
16 const char *prefix,
17 struct repository *repo UNUSED)
19 struct ref_exclusions excludes = REF_EXCLUSIONS_INIT;
20 struct string_list included_refs = STRING_LIST_INIT_NODUP;
21 struct pack_refs_opts pack_refs_opts = {
22 .exclusions = &excludes,
23 .includes = &included_refs,
24 .flags = PACK_REFS_PRUNE,
26 struct string_list option_excluded_refs = STRING_LIST_INIT_NODUP;
27 struct string_list_item *item;
28 int pack_all = 0;
29 int ret;
31 struct option opts[] = {
32 OPT_BOOL(0, "all", &pack_all, N_("pack everything")),
33 OPT_BIT(0, "prune", &pack_refs_opts.flags, N_("prune loose refs (default)"), PACK_REFS_PRUNE),
34 OPT_BIT(0, "auto", &pack_refs_opts.flags, N_("auto-pack refs as needed"), PACK_REFS_AUTO),
35 OPT_STRING_LIST(0, "include", pack_refs_opts.includes, N_("pattern"),
36 N_("references to include")),
37 OPT_STRING_LIST(0, "exclude", &option_excluded_refs, N_("pattern"),
38 N_("references to exclude")),
39 OPT_END(),
41 git_config(git_default_config, NULL);
42 if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))
43 usage_with_options(pack_refs_usage, opts);
45 for_each_string_list_item(item, &option_excluded_refs)
46 add_ref_exclusion(pack_refs_opts.exclusions, item->string);
48 if (pack_all)
49 string_list_append(pack_refs_opts.includes, "*");
51 if (!pack_refs_opts.includes->nr)
52 string_list_append(pack_refs_opts.includes, "refs/tags/*");
54 ret = refs_pack_refs(get_main_ref_store(the_repository), &pack_refs_opts);
56 clear_ref_exclusions(&excludes);
57 string_list_clear(&included_refs, 0);
58 string_list_clear(&option_excluded_refs, 0);
59 return ret;