1 #define USE_THE_REPOSITORY_VARIABLE
6 #include "parse-options.h"
10 #include "object-store.h"
11 #include "replace-object.h"
12 #include "repository.h"
14 #define BUILTIN_MIDX_WRITE_USAGE \
15 N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]" \
16 "[--refs-snapshot=<path>]")
18 #define BUILTIN_MIDX_VERIFY_USAGE \
19 N_("git multi-pack-index [<options>] verify")
21 #define BUILTIN_MIDX_EXPIRE_USAGE \
22 N_("git multi-pack-index [<options>] expire")
24 #define BUILTIN_MIDX_REPACK_USAGE \
25 N_("git multi-pack-index [<options>] repack [--batch-size=<size>]")
27 static char const * const builtin_multi_pack_index_write_usage
[] = {
28 BUILTIN_MIDX_WRITE_USAGE
,
31 static char const * const builtin_multi_pack_index_verify_usage
[] = {
32 BUILTIN_MIDX_VERIFY_USAGE
,
35 static char const * const builtin_multi_pack_index_expire_usage
[] = {
36 BUILTIN_MIDX_EXPIRE_USAGE
,
39 static char const * const builtin_multi_pack_index_repack_usage
[] = {
40 BUILTIN_MIDX_REPACK_USAGE
,
43 static char const * const builtin_multi_pack_index_usage
[] = {
44 BUILTIN_MIDX_WRITE_USAGE
,
45 BUILTIN_MIDX_VERIFY_USAGE
,
46 BUILTIN_MIDX_EXPIRE_USAGE
,
47 BUILTIN_MIDX_REPACK_USAGE
,
51 static struct opts_multi_pack_index
{
53 const char *preferred_pack
;
55 unsigned long batch_size
;
61 static int parse_object_dir(const struct option
*opt
, const char *arg
,
64 char **value
= opt
->value
;
67 *value
= xstrdup(repo_get_object_directory(the_repository
));
69 *value
= real_pathdup(arg
, 1);
73 static struct option common_opts
[] = {
74 OPT_CALLBACK(0, "object-dir", &opts
.object_dir
,
76 N_("object directory containing set of packfile and pack-index pairs"),
81 static struct option
*add_common_options(struct option
*prev
)
83 return parse_options_concat(common_opts
, prev
);
86 static int git_multi_pack_index_write_config(const char *var
, const char *value
,
87 const struct config_context
*ctx UNUSED
,
90 if (!strcmp(var
, "pack.writebitmaphashcache")) {
91 if (git_config_bool(var
, value
))
92 opts
.flags
|= MIDX_WRITE_BITMAP_HASH_CACHE
;
94 opts
.flags
&= ~MIDX_WRITE_BITMAP_HASH_CACHE
;
97 if (!strcmp(var
, "pack.writebitmaplookuptable")) {
98 if (git_config_bool(var
, value
))
99 opts
.flags
|= MIDX_WRITE_BITMAP_LOOKUP_TABLE
;
101 opts
.flags
&= ~MIDX_WRITE_BITMAP_LOOKUP_TABLE
;
105 * We should never make a fall-back call to 'git_default_config', since
106 * this was already called in 'cmd_multi_pack_index()'.
111 static void read_packs_from_stdin(struct string_list
*to
)
113 struct strbuf buf
= STRBUF_INIT
;
114 while (strbuf_getline(&buf
, stdin
) != EOF
)
115 string_list_append(to
, buf
.buf
);
116 string_list_sort(to
);
118 strbuf_release(&buf
);
121 static int cmd_multi_pack_index_write(int argc
, const char **argv
,
123 struct repository
*repo
)
125 struct option
*options
;
126 static struct option builtin_multi_pack_index_write_options
[] = {
127 OPT_STRING(0, "preferred-pack", &opts
.preferred_pack
,
128 N_("preferred-pack"),
129 N_("pack for reuse when computing a multi-pack bitmap")),
130 OPT_BIT(0, "bitmap", &opts
.flags
, N_("write multi-pack bitmap"),
131 MIDX_WRITE_BITMAP
| MIDX_WRITE_REV_INDEX
),
132 OPT_BIT(0, "progress", &opts
.flags
,
133 N_("force progress reporting"), MIDX_PROGRESS
),
134 OPT_BIT(0, "incremental", &opts
.flags
,
135 N_("write a new incremental MIDX"), MIDX_WRITE_INCREMENTAL
),
136 OPT_BOOL(0, "stdin-packs", &opts
.stdin_packs
,
137 N_("write multi-pack index containing only given indexes")),
138 OPT_FILENAME(0, "refs-snapshot", &opts
.refs_snapshot
,
139 N_("refs snapshot for selecting bitmap commits")),
144 opts
.flags
|= MIDX_WRITE_BITMAP_HASH_CACHE
;
146 git_config(git_multi_pack_index_write_config
, NULL
);
148 options
= add_common_options(builtin_multi_pack_index_write_options
);
150 trace2_cmd_mode(argv
[0]);
153 opts
.flags
|= MIDX_PROGRESS
;
154 argc
= parse_options(argc
, argv
, prefix
,
155 options
, builtin_multi_pack_index_write_usage
,
158 usage_with_options(builtin_multi_pack_index_write_usage
,
161 FREE_AND_NULL(options
);
163 if (opts
.stdin_packs
) {
164 struct string_list packs
= STRING_LIST_INIT_DUP
;
166 read_packs_from_stdin(&packs
);
168 ret
= write_midx_file_only(repo
, opts
.object_dir
, &packs
,
170 opts
.refs_snapshot
, opts
.flags
);
172 string_list_clear(&packs
, 0);
173 free(opts
.refs_snapshot
);
179 ret
= write_midx_file(repo
, opts
.object_dir
, opts
.preferred_pack
,
180 opts
.refs_snapshot
, opts
.flags
);
182 free(opts
.refs_snapshot
);
186 static int cmd_multi_pack_index_verify(int argc
, const char **argv
,
188 struct repository
*repo UNUSED
)
190 struct option
*options
;
191 static struct option builtin_multi_pack_index_verify_options
[] = {
192 OPT_BIT(0, "progress", &opts
.flags
,
193 N_("force progress reporting"), MIDX_PROGRESS
),
196 options
= add_common_options(builtin_multi_pack_index_verify_options
);
198 trace2_cmd_mode(argv
[0]);
201 opts
.flags
|= MIDX_PROGRESS
;
202 argc
= parse_options(argc
, argv
, prefix
,
203 options
, builtin_multi_pack_index_verify_usage
,
206 usage_with_options(builtin_multi_pack_index_verify_usage
,
209 FREE_AND_NULL(options
);
211 return verify_midx_file(the_repository
, opts
.object_dir
, opts
.flags
);
214 static int cmd_multi_pack_index_expire(int argc
, const char **argv
,
216 struct repository
*repo UNUSED
)
218 struct option
*options
;
219 static struct option builtin_multi_pack_index_expire_options
[] = {
220 OPT_BIT(0, "progress", &opts
.flags
,
221 N_("force progress reporting"), MIDX_PROGRESS
),
224 options
= add_common_options(builtin_multi_pack_index_expire_options
);
226 trace2_cmd_mode(argv
[0]);
229 opts
.flags
|= MIDX_PROGRESS
;
230 argc
= parse_options(argc
, argv
, prefix
,
231 options
, builtin_multi_pack_index_expire_usage
,
234 usage_with_options(builtin_multi_pack_index_expire_usage
,
237 FREE_AND_NULL(options
);
239 return expire_midx_packs(the_repository
, opts
.object_dir
, opts
.flags
);
242 static int cmd_multi_pack_index_repack(int argc
, const char **argv
,
244 struct repository
*repo UNUSED
)
246 struct option
*options
;
247 static struct option builtin_multi_pack_index_repack_options
[] = {
248 OPT_UNSIGNED(0, "batch-size", &opts
.batch_size
,
249 N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
250 OPT_BIT(0, "progress", &opts
.flags
,
251 N_("force progress reporting"), MIDX_PROGRESS
),
255 options
= add_common_options(builtin_multi_pack_index_repack_options
);
257 trace2_cmd_mode(argv
[0]);
260 opts
.flags
|= MIDX_PROGRESS
;
261 argc
= parse_options(argc
, argv
, prefix
,
263 builtin_multi_pack_index_repack_usage
,
266 usage_with_options(builtin_multi_pack_index_repack_usage
,
269 FREE_AND_NULL(options
);
271 return midx_repack(the_repository
, opts
.object_dir
,
272 (size_t)opts
.batch_size
, opts
.flags
);
275 int cmd_multi_pack_index(int argc
,
278 struct repository
*repo
)
281 parse_opt_subcommand_fn
*fn
= NULL
;
282 struct option builtin_multi_pack_index_options
[] = {
283 OPT_SUBCOMMAND("repack", &fn
, cmd_multi_pack_index_repack
),
284 OPT_SUBCOMMAND("write", &fn
, cmd_multi_pack_index_write
),
285 OPT_SUBCOMMAND("verify", &fn
, cmd_multi_pack_index_verify
),
286 OPT_SUBCOMMAND("expire", &fn
, cmd_multi_pack_index_expire
),
289 struct option
*options
= parse_options_concat(builtin_multi_pack_index_options
, common_opts
);
291 disable_replace_refs();
293 git_config(git_default_config
, NULL
);
295 if (the_repository
&&
296 the_repository
->objects
&&
297 the_repository
->objects
->odb
)
298 opts
.object_dir
= xstrdup(the_repository
->objects
->odb
->path
);
300 argc
= parse_options(argc
, argv
, prefix
, options
,
301 builtin_multi_pack_index_usage
, 0);
302 FREE_AND_NULL(options
);
304 res
= fn(argc
, argv
, prefix
, repo
);
306 free(opts
.object_dir
);