4 #include "environment.h"
6 #include "parse-options.h"
10 #include "object-store-ll.h"
11 #include "replace-object.h"
13 #define BUILTIN_MIDX_WRITE_USAGE \
14 N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]" \
15 "[--refs-snapshot=<path>]")
17 #define BUILTIN_MIDX_VERIFY_USAGE \
18 N_("git multi-pack-index [<options>] verify")
20 #define BUILTIN_MIDX_EXPIRE_USAGE \
21 N_("git multi-pack-index [<options>] expire")
23 #define BUILTIN_MIDX_REPACK_USAGE \
24 N_("git multi-pack-index [<options>] repack [--batch-size=<size>]")
26 static char const * const builtin_multi_pack_index_write_usage
[] = {
27 BUILTIN_MIDX_WRITE_USAGE
,
30 static char const * const builtin_multi_pack_index_verify_usage
[] = {
31 BUILTIN_MIDX_VERIFY_USAGE
,
34 static char const * const builtin_multi_pack_index_expire_usage
[] = {
35 BUILTIN_MIDX_EXPIRE_USAGE
,
38 static char const * const builtin_multi_pack_index_repack_usage
[] = {
39 BUILTIN_MIDX_REPACK_USAGE
,
42 static char const * const builtin_multi_pack_index_usage
[] = {
43 BUILTIN_MIDX_WRITE_USAGE
,
44 BUILTIN_MIDX_VERIFY_USAGE
,
45 BUILTIN_MIDX_EXPIRE_USAGE
,
46 BUILTIN_MIDX_REPACK_USAGE
,
50 static struct opts_multi_pack_index
{
52 const char *preferred_pack
;
54 unsigned long batch_size
;
60 static int parse_object_dir(const struct option
*opt
, const char *arg
,
63 char **value
= opt
->value
;
66 *value
= xstrdup(get_object_directory());
68 *value
= real_pathdup(arg
, 1);
72 static struct option common_opts
[] = {
73 OPT_CALLBACK(0, "object-dir", &opts
.object_dir
,
75 N_("object directory containing set of packfile and pack-index pairs"),
80 static struct option
*add_common_options(struct option
*prev
)
82 return parse_options_concat(common_opts
, prev
);
85 static int git_multi_pack_index_write_config(const char *var
, const char *value
,
86 const struct config_context
*ctx UNUSED
,
89 if (!strcmp(var
, "pack.writebitmaphashcache")) {
90 if (git_config_bool(var
, value
))
91 opts
.flags
|= MIDX_WRITE_BITMAP_HASH_CACHE
;
93 opts
.flags
&= ~MIDX_WRITE_BITMAP_HASH_CACHE
;
96 if (!strcmp(var
, "pack.writebitmaplookuptable")) {
97 if (git_config_bool(var
, value
))
98 opts
.flags
|= MIDX_WRITE_BITMAP_LOOKUP_TABLE
;
100 opts
.flags
&= ~MIDX_WRITE_BITMAP_LOOKUP_TABLE
;
104 * We should never make a fall-back call to 'git_default_config', since
105 * this was already called in 'cmd_multi_pack_index()'.
110 static void read_packs_from_stdin(struct string_list
*to
)
112 struct strbuf buf
= STRBUF_INIT
;
113 while (strbuf_getline(&buf
, stdin
) != EOF
)
114 string_list_append(to
, buf
.buf
);
115 string_list_sort(to
);
117 strbuf_release(&buf
);
120 static int cmd_multi_pack_index_write(int argc
, const char **argv
,
123 struct option
*options
;
124 static struct option builtin_multi_pack_index_write_options
[] = {
125 OPT_STRING(0, "preferred-pack", &opts
.preferred_pack
,
126 N_("preferred-pack"),
127 N_("pack for reuse when computing a multi-pack bitmap")),
128 OPT_BIT(0, "bitmap", &opts
.flags
, N_("write multi-pack bitmap"),
129 MIDX_WRITE_BITMAP
| MIDX_WRITE_REV_INDEX
),
130 OPT_BIT(0, "progress", &opts
.flags
,
131 N_("force progress reporting"), MIDX_PROGRESS
),
132 OPT_BOOL(0, "stdin-packs", &opts
.stdin_packs
,
133 N_("write multi-pack index containing only given indexes")),
134 OPT_FILENAME(0, "refs-snapshot", &opts
.refs_snapshot
,
135 N_("refs snapshot for selecting bitmap commits")),
140 opts
.flags
|= MIDX_WRITE_BITMAP_HASH_CACHE
;
142 git_config(git_multi_pack_index_write_config
, NULL
);
144 options
= add_common_options(builtin_multi_pack_index_write_options
);
146 trace2_cmd_mode(argv
[0]);
149 opts
.flags
|= MIDX_PROGRESS
;
150 argc
= parse_options(argc
, argv
, prefix
,
151 options
, builtin_multi_pack_index_write_usage
,
154 usage_with_options(builtin_multi_pack_index_write_usage
,
157 FREE_AND_NULL(options
);
159 if (opts
.stdin_packs
) {
160 struct string_list packs
= STRING_LIST_INIT_DUP
;
162 read_packs_from_stdin(&packs
);
164 ret
= write_midx_file_only(opts
.object_dir
, &packs
,
166 opts
.refs_snapshot
, opts
.flags
);
168 string_list_clear(&packs
, 0);
169 free(opts
.refs_snapshot
);
175 ret
= write_midx_file(opts
.object_dir
, opts
.preferred_pack
,
176 opts
.refs_snapshot
, opts
.flags
);
178 free(opts
.refs_snapshot
);
182 static int cmd_multi_pack_index_verify(int argc
, const char **argv
,
185 struct option
*options
;
186 static struct option builtin_multi_pack_index_verify_options
[] = {
187 OPT_BIT(0, "progress", &opts
.flags
,
188 N_("force progress reporting"), MIDX_PROGRESS
),
191 options
= add_common_options(builtin_multi_pack_index_verify_options
);
193 trace2_cmd_mode(argv
[0]);
196 opts
.flags
|= MIDX_PROGRESS
;
197 argc
= parse_options(argc
, argv
, prefix
,
198 options
, builtin_multi_pack_index_verify_usage
,
201 usage_with_options(builtin_multi_pack_index_verify_usage
,
204 FREE_AND_NULL(options
);
206 return verify_midx_file(the_repository
, opts
.object_dir
, opts
.flags
);
209 static int cmd_multi_pack_index_expire(int argc
, const char **argv
,
212 struct option
*options
;
213 static struct option builtin_multi_pack_index_expire_options
[] = {
214 OPT_BIT(0, "progress", &opts
.flags
,
215 N_("force progress reporting"), MIDX_PROGRESS
),
218 options
= add_common_options(builtin_multi_pack_index_expire_options
);
220 trace2_cmd_mode(argv
[0]);
223 opts
.flags
|= MIDX_PROGRESS
;
224 argc
= parse_options(argc
, argv
, prefix
,
225 options
, builtin_multi_pack_index_expire_usage
,
228 usage_with_options(builtin_multi_pack_index_expire_usage
,
231 FREE_AND_NULL(options
);
233 return expire_midx_packs(the_repository
, opts
.object_dir
, opts
.flags
);
236 static int cmd_multi_pack_index_repack(int argc
, const char **argv
,
239 struct option
*options
;
240 static struct option builtin_multi_pack_index_repack_options
[] = {
241 OPT_MAGNITUDE(0, "batch-size", &opts
.batch_size
,
242 N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
243 OPT_BIT(0, "progress", &opts
.flags
,
244 N_("force progress reporting"), MIDX_PROGRESS
),
248 options
= add_common_options(builtin_multi_pack_index_repack_options
);
250 trace2_cmd_mode(argv
[0]);
253 opts
.flags
|= MIDX_PROGRESS
;
254 argc
= parse_options(argc
, argv
, prefix
,
256 builtin_multi_pack_index_repack_usage
,
259 usage_with_options(builtin_multi_pack_index_repack_usage
,
262 FREE_AND_NULL(options
);
264 return midx_repack(the_repository
, opts
.object_dir
,
265 (size_t)opts
.batch_size
, opts
.flags
);
268 int cmd_multi_pack_index(int argc
, const char **argv
,
272 parse_opt_subcommand_fn
*fn
= NULL
;
273 struct option builtin_multi_pack_index_options
[] = {
274 OPT_SUBCOMMAND("repack", &fn
, cmd_multi_pack_index_repack
),
275 OPT_SUBCOMMAND("write", &fn
, cmd_multi_pack_index_write
),
276 OPT_SUBCOMMAND("verify", &fn
, cmd_multi_pack_index_verify
),
277 OPT_SUBCOMMAND("expire", &fn
, cmd_multi_pack_index_expire
),
280 struct option
*options
= parse_options_concat(builtin_multi_pack_index_options
, common_opts
);
282 disable_replace_refs();
284 git_config(git_default_config
, NULL
);
286 if (the_repository
&&
287 the_repository
->objects
&&
288 the_repository
->objects
->odb
)
289 opts
.object_dir
= xstrdup(the_repository
->objects
->odb
->path
);
291 argc
= parse_options(argc
, argv
, prefix
, options
,
292 builtin_multi_pack_index_usage
, 0);
293 FREE_AND_NULL(options
);
295 res
= fn(argc
, argv
, prefix
);
297 free(opts
.object_dir
);