Git fork
1#include "builtin.h"
2#include "config.h"
3#include "environment.h"
4#include "pack-refs.h"
5#include "parse-options.h"
6#include "refs.h"
7#include "revision.h"
8
9int pack_refs_core(int argc,
10 const char **argv,
11 const char *prefix,
12 struct repository *repo,
13 const char * const *usage_opts)
14{
15 struct ref_exclusions excludes = REF_EXCLUSIONS_INIT;
16 struct string_list included_refs = STRING_LIST_INIT_NODUP;
17 struct pack_refs_opts pack_refs_opts = {
18 .exclusions = &excludes,
19 .includes = &included_refs,
20 .flags = PACK_REFS_PRUNE,
21 };
22 struct string_list option_excluded_refs = STRING_LIST_INIT_NODUP;
23 struct string_list_item *item;
24 int pack_all = 0;
25 int ret;
26
27 struct option opts[] = {
28 OPT_BOOL(0, "all", &pack_all, N_("pack everything")),
29 OPT_BIT(0, "prune", &pack_refs_opts.flags, N_("prune loose refs (default)"), PACK_REFS_PRUNE),
30 OPT_BIT(0, "auto", &pack_refs_opts.flags, N_("auto-pack refs as needed"), PACK_REFS_AUTO),
31 OPT_STRING_LIST(0, "include", pack_refs_opts.includes, N_("pattern"),
32 N_("references to include")),
33 OPT_STRING_LIST(0, "exclude", &option_excluded_refs, N_("pattern"),
34 N_("references to exclude")),
35 OPT_END(),
36 };
37 repo_config(repo, git_default_config, NULL);
38 if (parse_options(argc, argv, prefix, opts, usage_opts, 0))
39 usage_with_options(usage_opts, opts);
40
41 for_each_string_list_item(item, &option_excluded_refs)
42 add_ref_exclusion(pack_refs_opts.exclusions, item->string);
43
44 if (pack_all)
45 string_list_append(pack_refs_opts.includes, "*");
46
47 if (!pack_refs_opts.includes->nr)
48 string_list_append(pack_refs_opts.includes, "refs/tags/*");
49
50 ret = refs_optimize(get_main_ref_store(repo), &pack_refs_opts);
51
52 clear_ref_exclusions(&excludes);
53 string_list_clear(&included_refs, 0);
54 string_list_clear(&option_excluded_refs, 0);
55 return ret;
56}