]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/pack-refs.c
Start the 2.46 cycle
[thirdparty/git.git] / builtin / pack-refs.c
CommitLineData
c2e86add 1#include "builtin.h"
8e712ef6 2#include "config.h"
f394e093 3#include "gettext.h"
b2565ae5 4#include "parse-options.h"
32d462ce 5#include "refs.h"
23a3f0cb 6#include "repository.h"
826ae79f 7#include "revision.h"
96884601 8
b2565ae5 9static char const * const pack_refs_usage[] = {
6dcffc68 10 N_("git pack-refs [--all] [--no-prune] [--auto] [--include <pattern>] [--exclude <pattern>]"),
b2565ae5
PH
11 NULL
12};
13
99b5a79e
LT
14int cmd_pack_refs(int argc, const char **argv, const char *prefix)
15{
a75dc71f
PS
16 struct ref_exclusions excludes = REF_EXCLUSIONS_INIT;
17 struct string_list included_refs = STRING_LIST_INIT_NODUP;
18 struct pack_refs_opts pack_refs_opts = {
19 .exclusions = &excludes,
20 .includes = &included_refs,
21 .flags = PACK_REFS_PRUNE,
22 };
23 struct string_list option_excluded_refs = STRING_LIST_INIT_NODUP;
826ae79f 24 struct string_list_item *item;
35aeabd6 25 int pack_all = 0;
a75dc71f 26 int ret;
826ae79f 27
b2565ae5 28 struct option opts[] = {
35aeabd6 29 OPT_BOOL(0, "all", &pack_all, N_("pack everything")),
826ae79f 30 OPT_BIT(0, "prune", &pack_refs_opts.flags, N_("prune loose refs (default)"), PACK_REFS_PRUNE),
6dcffc68 31 OPT_BIT(0, "auto", &pack_refs_opts.flags, N_("auto-pack refs as needed"), PACK_REFS_AUTO),
4fe42f32
JC
32 OPT_STRING_LIST(0, "include", pack_refs_opts.includes, N_("pattern"),
33 N_("references to include")),
826ae79f
JC
34 OPT_STRING_LIST(0, "exclude", &option_excluded_refs, N_("pattern"),
35 N_("references to exclude")),
b2565ae5
PH
36 OPT_END(),
37 };
8e712ef6 38 git_config(git_default_config, NULL);
37782920 39 if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))
b2565ae5 40 usage_with_options(pack_refs_usage, opts);
826ae79f
JC
41
42 for_each_string_list_item(item, &option_excluded_refs)
43 add_ref_exclusion(pack_refs_opts.exclusions, item->string);
44
35aeabd6 45 if (pack_all)
4fe42f32
JC
46 string_list_append(pack_refs_opts.includes, "*");
47
48 if (!pack_refs_opts.includes->nr)
49 string_list_append(pack_refs_opts.includes, "refs/tags/*");
50
a75dc71f
PS
51 ret = refs_pack_refs(get_main_ref_store(the_repository), &pack_refs_opts);
52
53 clear_ref_exclusions(&excludes);
54 string_list_clear(&included_refs, 0);
55 string_list_clear(&option_excluded_refs, 0);
56 return ret;
e1e22e37 57}