userdiff-cpp: tighten word regex
[git/debian.git] / builtin / multi-pack-index.c
blob0fb2439b0f403fc384e2be8bf66334dbe10ebd77
1 #include "builtin.h"
2 #include "cache.h"
3 #include "config.h"
4 #include "parse-options.h"
5 #include "midx.h"
6 #include "trace2.h"
7 #include "object-store.h"
9 #define BUILTIN_MIDX_WRITE_USAGE \
10 N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]")
12 #define BUILTIN_MIDX_VERIFY_USAGE \
13 N_("git multi-pack-index [<options>] verify")
15 #define BUILTIN_MIDX_EXPIRE_USAGE \
16 N_("git multi-pack-index [<options>] expire")
18 #define BUILTIN_MIDX_REPACK_USAGE \
19 N_("git multi-pack-index [<options>] repack [--batch-size=<size>]")
21 static char const * const builtin_multi_pack_index_write_usage[] = {
22 BUILTIN_MIDX_WRITE_USAGE,
23 NULL
25 static char const * const builtin_multi_pack_index_verify_usage[] = {
26 BUILTIN_MIDX_VERIFY_USAGE,
27 NULL
29 static char const * const builtin_multi_pack_index_expire_usage[] = {
30 BUILTIN_MIDX_EXPIRE_USAGE,
31 NULL
33 static char const * const builtin_multi_pack_index_repack_usage[] = {
34 BUILTIN_MIDX_REPACK_USAGE,
35 NULL
37 static char const * const builtin_multi_pack_index_usage[] = {
38 BUILTIN_MIDX_WRITE_USAGE,
39 BUILTIN_MIDX_VERIFY_USAGE,
40 BUILTIN_MIDX_EXPIRE_USAGE,
41 BUILTIN_MIDX_REPACK_USAGE,
42 NULL
45 static struct opts_multi_pack_index {
46 const char *object_dir;
47 const char *preferred_pack;
48 unsigned long batch_size;
49 unsigned flags;
50 } opts;
52 static struct option common_opts[] = {
53 OPT_FILENAME(0, "object-dir", &opts.object_dir,
54 N_("object directory containing set of packfile and pack-index pairs")),
55 OPT_END(),
58 static struct option *add_common_options(struct option *prev)
60 return parse_options_concat(common_opts, prev);
63 static int cmd_multi_pack_index_write(int argc, const char **argv)
65 struct option *options;
66 static struct option builtin_multi_pack_index_write_options[] = {
67 OPT_STRING(0, "preferred-pack", &opts.preferred_pack,
68 N_("preferred-pack"),
69 N_("pack for reuse when computing a multi-pack bitmap")),
70 OPT_BIT(0, "bitmap", &opts.flags, N_("write multi-pack bitmap"),
71 MIDX_WRITE_BITMAP | MIDX_WRITE_REV_INDEX),
72 OPT_BIT(0, "progress", &opts.flags,
73 N_("force progress reporting"), MIDX_PROGRESS),
74 OPT_END(),
77 options = add_common_options(builtin_multi_pack_index_write_options);
79 trace2_cmd_mode(argv[0]);
81 if (isatty(2))
82 opts.flags |= MIDX_PROGRESS;
83 argc = parse_options(argc, argv, NULL,
84 options, builtin_multi_pack_index_write_usage,
85 PARSE_OPT_KEEP_UNKNOWN);
86 if (argc)
87 usage_with_options(builtin_multi_pack_index_write_usage,
88 options);
90 FREE_AND_NULL(options);
92 return write_midx_file(opts.object_dir, opts.preferred_pack,
93 opts.flags);
96 static int cmd_multi_pack_index_verify(int argc, const char **argv)
98 struct option *options;
99 static struct option builtin_multi_pack_index_verify_options[] = {
100 OPT_BIT(0, "progress", &opts.flags,
101 N_("force progress reporting"), MIDX_PROGRESS),
102 OPT_END(),
104 options = add_common_options(builtin_multi_pack_index_verify_options);
106 trace2_cmd_mode(argv[0]);
108 if (isatty(2))
109 opts.flags |= MIDX_PROGRESS;
110 argc = parse_options(argc, argv, NULL,
111 options, builtin_multi_pack_index_verify_usage,
112 PARSE_OPT_KEEP_UNKNOWN);
113 if (argc)
114 usage_with_options(builtin_multi_pack_index_verify_usage,
115 options);
117 return verify_midx_file(the_repository, opts.object_dir, opts.flags);
120 static int cmd_multi_pack_index_expire(int argc, const char **argv)
122 struct option *options;
123 static struct option builtin_multi_pack_index_expire_options[] = {
124 OPT_BIT(0, "progress", &opts.flags,
125 N_("force progress reporting"), MIDX_PROGRESS),
126 OPT_END(),
128 options = add_common_options(builtin_multi_pack_index_expire_options);
130 trace2_cmd_mode(argv[0]);
132 if (isatty(2))
133 opts.flags |= MIDX_PROGRESS;
134 argc = parse_options(argc, argv, NULL,
135 options, builtin_multi_pack_index_expire_usage,
136 PARSE_OPT_KEEP_UNKNOWN);
137 if (argc)
138 usage_with_options(builtin_multi_pack_index_expire_usage,
139 options);
141 return expire_midx_packs(the_repository, opts.object_dir, opts.flags);
144 static int cmd_multi_pack_index_repack(int argc, const char **argv)
146 struct option *options;
147 static struct option builtin_multi_pack_index_repack_options[] = {
148 OPT_MAGNITUDE(0, "batch-size", &opts.batch_size,
149 N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
150 OPT_BIT(0, "progress", &opts.flags,
151 N_("force progress reporting"), MIDX_PROGRESS),
152 OPT_END(),
155 options = add_common_options(builtin_multi_pack_index_repack_options);
157 trace2_cmd_mode(argv[0]);
159 if (isatty(2))
160 opts.flags |= MIDX_PROGRESS;
161 argc = parse_options(argc, argv, NULL,
162 options,
163 builtin_multi_pack_index_repack_usage,
164 PARSE_OPT_KEEP_UNKNOWN);
165 if (argc)
166 usage_with_options(builtin_multi_pack_index_repack_usage,
167 options);
169 FREE_AND_NULL(options);
171 return midx_repack(the_repository, opts.object_dir,
172 (size_t)opts.batch_size, opts.flags);
175 int cmd_multi_pack_index(int argc, const char **argv,
176 const char *prefix)
178 struct option *builtin_multi_pack_index_options = common_opts;
180 git_config(git_default_config, NULL);
182 argc = parse_options(argc, argv, prefix,
183 builtin_multi_pack_index_options,
184 builtin_multi_pack_index_usage,
185 PARSE_OPT_STOP_AT_NON_OPTION);
187 if (!opts.object_dir)
188 opts.object_dir = get_object_directory();
190 if (!argc)
191 goto usage;
193 if (!strcmp(argv[0], "repack"))
194 return cmd_multi_pack_index_repack(argc, argv);
195 else if (!strcmp(argv[0], "write"))
196 return cmd_multi_pack_index_write(argc, argv);
197 else if (!strcmp(argv[0], "verify"))
198 return cmd_multi_pack_index_verify(argc, argv);
199 else if (!strcmp(argv[0], "expire"))
200 return cmd_multi_pack_index_expire(argc, argv);
202 error(_("unrecognized subcommand: %s"), argv[0]);
203 usage:
204 usage_with_options(builtin_multi_pack_index_usage,
205 builtin_multi_pack_index_options);