Stephen Boyd | c2e86ad | 2011-03-22 00:51:05 -0700 | [diff] [blame] | 1 | #include "builtin.h" |
Elijah Newren | 8e712ef | 2019-04-25 07:58:54 -0700 | [diff] [blame] | 2 | #include "config.h" |
Elijah Newren | f394e09 | 2023-03-21 06:25:54 +0000 | [diff] [blame] | 3 | #include "gettext.h" |
Pierre Habouzit | b2565ae | 2007-10-15 23:06:02 +0200 | [diff] [blame] | 4 | #include "parse-options.h" |
Michael Haggerty | 32d462c | 2013-04-22 21:52:32 +0200 | [diff] [blame] | 5 | #include "refs.h" |
Stefan Beller | 23a3f0c | 2018-04-11 17:21:09 -0700 | [diff] [blame] | 6 | #include "repository.h" |
John Cai | 826ae79 | 2023-05-12 21:34:41 +0000 | [diff] [blame] | 7 | #include "revision.h" |
Linus Torvalds | 99b5a79 | 2007-05-26 09:25:31 -0700 | [diff] [blame] | 8 | |
Pierre Habouzit | b2565ae | 2007-10-15 23:06:02 +0200 | [diff] [blame] | 9 | static char const * const pack_refs_usage[] = { |
Patrick Steinhardt | 6dcffc6 | 2024-03-25 11:03:20 +0100 | [diff] [blame] | 10 | N_("git pack-refs [--all] [--no-prune] [--auto] [--include <pattern>] [--exclude <pattern>]"), |
Pierre Habouzit | b2565ae | 2007-10-15 23:06:02 +0200 | [diff] [blame] | 11 | NULL |
| 12 | }; |
| 13 | |
Linus Torvalds | 99b5a79 | 2007-05-26 09:25:31 -0700 | [diff] [blame] | 14 | int cmd_pack_refs(int argc, const char **argv, const char *prefix) |
| 15 | { |
Patrick Steinhardt | a75dc71 | 2024-03-25 11:03:15 +0100 | [diff] [blame] | 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; |
John Cai | 826ae79 | 2023-05-12 21:34:41 +0000 | [diff] [blame] | 24 | struct string_list_item *item; |
Patrick Steinhardt | 35aeabd | 2024-03-25 11:03:07 +0100 | [diff] [blame] | 25 | int pack_all = 0; |
Patrick Steinhardt | a75dc71 | 2024-03-25 11:03:15 +0100 | [diff] [blame] | 26 | int ret; |
John Cai | 826ae79 | 2023-05-12 21:34:41 +0000 | [diff] [blame] | 27 | |
Pierre Habouzit | b2565ae | 2007-10-15 23:06:02 +0200 | [diff] [blame] | 28 | struct option opts[] = { |
Patrick Steinhardt | 35aeabd | 2024-03-25 11:03:07 +0100 | [diff] [blame] | 29 | OPT_BOOL(0, "all", &pack_all, N_("pack everything")), |
John Cai | 826ae79 | 2023-05-12 21:34:41 +0000 | [diff] [blame] | 30 | OPT_BIT(0, "prune", &pack_refs_opts.flags, N_("prune loose refs (default)"), PACK_REFS_PRUNE), |
Patrick Steinhardt | 6dcffc6 | 2024-03-25 11:03:20 +0100 | [diff] [blame] | 31 | OPT_BIT(0, "auto", &pack_refs_opts.flags, N_("auto-pack refs as needed"), PACK_REFS_AUTO), |
John Cai | 4fe42f3 | 2023-05-12 21:34:42 +0000 | [diff] [blame] | 32 | OPT_STRING_LIST(0, "include", pack_refs_opts.includes, N_("pattern"), |
| 33 | N_("references to include")), |
John Cai | 826ae79 | 2023-05-12 21:34:41 +0000 | [diff] [blame] | 34 | OPT_STRING_LIST(0, "exclude", &option_excluded_refs, N_("pattern"), |
| 35 | N_("references to exclude")), |
Pierre Habouzit | b2565ae | 2007-10-15 23:06:02 +0200 | [diff] [blame] | 36 | OPT_END(), |
| 37 | }; |
Elijah Newren | 8e712ef | 2019-04-25 07:58:54 -0700 | [diff] [blame] | 38 | git_config(git_default_config, NULL); |
Stephen Boyd | 3778292 | 2009-05-23 11:53:12 -0700 | [diff] [blame] | 39 | if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0)) |
Pierre Habouzit | b2565ae | 2007-10-15 23:06:02 +0200 | [diff] [blame] | 40 | usage_with_options(pack_refs_usage, opts); |
John Cai | 826ae79 | 2023-05-12 21:34:41 +0000 | [diff] [blame] | 41 | |
| 42 | for_each_string_list_item(item, &option_excluded_refs) |
| 43 | add_ref_exclusion(pack_refs_opts.exclusions, item->string); |
| 44 | |
Patrick Steinhardt | 35aeabd | 2024-03-25 11:03:07 +0100 | [diff] [blame] | 45 | if (pack_all) |
John Cai | 4fe42f3 | 2023-05-12 21:34:42 +0000 | [diff] [blame] | 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 | |
Patrick Steinhardt | a75dc71 | 2024-03-25 11:03:15 +0100 | [diff] [blame] | 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; |
Linus Torvalds | 99b5a79 | 2007-05-26 09:25:31 -0700 | [diff] [blame] | 57 | } |