1 #define USE_THE_REPOSITORY_VARIABLE
6 #include "parse-options.h"
10 #include "object-store-ll.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
,
124 struct option
*options
;
125 static struct option builtin_multi_pack_index_write_options
[] = {
126 OPT_STRING(0, "preferred-pack", &opts
.preferred_pack
,
127 N_("preferred-pack"),
128 N_("pack for reuse when computing a multi-pack bitmap")),
129 OPT_BIT(0, "bitmap", &opts
.flags
, N_("write multi-pack bitmap"),
130 MIDX_WRITE_BITMAP
| MIDX_WRITE_REV_INDEX
),
131 OPT_BIT(0, "progress", &opts
.flags
,
132 N_("force progress reporting"), MIDX_PROGRESS
),
133 OPT_BIT(0, "incremental", &opts
.flags
,
134 N_("write a new incremental MIDX"), MIDX_WRITE_INCREMENTAL
),
135 OPT_BOOL(0, "stdin-packs", &opts
.stdin_packs
,
136 N_("write multi-pack index containing only given indexes")),
137 OPT_FILENAME(0, "refs-snapshot", &opts
.refs_snapshot
,
138 N_("refs snapshot for selecting bitmap commits")),
143 opts
.flags
|= MIDX_WRITE_BITMAP_HASH_CACHE
;
145 git_config(git_multi_pack_index_write_config
, NULL
);
147 options
= add_common_options(builtin_multi_pack_index_write_options
);
149 trace2_cmd_mode(argv
[0]);
152 opts
.flags
|= MIDX_PROGRESS
;
153 argc
= parse_options(argc
, argv
, prefix
,
154 options
, builtin_multi_pack_index_write_usage
,
157 usage_with_options(builtin_multi_pack_index_write_usage
,
160 FREE_AND_NULL(options
);
162 if (opts
.stdin_packs
) {
163 struct string_list packs
= STRING_LIST_INIT_DUP
;
165 read_packs_from_stdin(&packs
);
167 ret
= write_midx_file_only(opts
.object_dir
, &packs
,
169 opts
.refs_snapshot
, opts
.flags
);
171 string_list_clear(&packs
, 0);
172 free(opts
.refs_snapshot
);
178 ret
= write_midx_file(opts
.object_dir
, opts
.preferred_pack
,
179 opts
.refs_snapshot
, opts
.flags
);
181 free(opts
.refs_snapshot
);
185 static int cmd_multi_pack_index_verify(int argc
, const char **argv
,
188 struct option
*options
;
189 static struct option builtin_multi_pack_index_verify_options
[] = {
190 OPT_BIT(0, "progress", &opts
.flags
,
191 N_("force progress reporting"), MIDX_PROGRESS
),
194 options
= add_common_options(builtin_multi_pack_index_verify_options
);
196 trace2_cmd_mode(argv
[0]);
199 opts
.flags
|= MIDX_PROGRESS
;
200 argc
= parse_options(argc
, argv
, prefix
,
201 options
, builtin_multi_pack_index_verify_usage
,
204 usage_with_options(builtin_multi_pack_index_verify_usage
,
207 FREE_AND_NULL(options
);
209 return verify_midx_file(the_repository
, opts
.object_dir
, opts
.flags
);
212 static int cmd_multi_pack_index_expire(int argc
, const char **argv
,
215 struct option
*options
;
216 static struct option builtin_multi_pack_index_expire_options
[] = {
217 OPT_BIT(0, "progress", &opts
.flags
,
218 N_("force progress reporting"), MIDX_PROGRESS
),
221 options
= add_common_options(builtin_multi_pack_index_expire_options
);
223 trace2_cmd_mode(argv
[0]);
226 opts
.flags
|= MIDX_PROGRESS
;
227 argc
= parse_options(argc
, argv
, prefix
,
228 options
, builtin_multi_pack_index_expire_usage
,
231 usage_with_options(builtin_multi_pack_index_expire_usage
,
234 FREE_AND_NULL(options
);
236 return expire_midx_packs(the_repository
, opts
.object_dir
, opts
.flags
);
239 static int cmd_multi_pack_index_repack(int argc
, const char **argv
,
242 struct option
*options
;
243 static struct option builtin_multi_pack_index_repack_options
[] = {
244 OPT_MAGNITUDE(0, "batch-size", &opts
.batch_size
,
245 N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
246 OPT_BIT(0, "progress", &opts
.flags
,
247 N_("force progress reporting"), MIDX_PROGRESS
),
251 options
= add_common_options(builtin_multi_pack_index_repack_options
);
253 trace2_cmd_mode(argv
[0]);
256 opts
.flags
|= MIDX_PROGRESS
;
257 argc
= parse_options(argc
, argv
, prefix
,
259 builtin_multi_pack_index_repack_usage
,
262 usage_with_options(builtin_multi_pack_index_repack_usage
,
265 FREE_AND_NULL(options
);
267 return midx_repack(the_repository
, opts
.object_dir
,
268 (size_t)opts
.batch_size
, opts
.flags
);
271 int cmd_multi_pack_index(int argc
,
274 struct repository
*repo UNUSED
)
277 parse_opt_subcommand_fn
*fn
= NULL
;
278 struct option builtin_multi_pack_index_options
[] = {
279 OPT_SUBCOMMAND("repack", &fn
, cmd_multi_pack_index_repack
),
280 OPT_SUBCOMMAND("write", &fn
, cmd_multi_pack_index_write
),
281 OPT_SUBCOMMAND("verify", &fn
, cmd_multi_pack_index_verify
),
282 OPT_SUBCOMMAND("expire", &fn
, cmd_multi_pack_index_expire
),
285 struct option
*options
= parse_options_concat(builtin_multi_pack_index_options
, common_opts
);
287 disable_replace_refs();
289 git_config(git_default_config
, NULL
);
291 if (the_repository
&&
292 the_repository
->objects
&&
293 the_repository
->objects
->odb
)
294 opts
.object_dir
= xstrdup(the_repository
->objects
->odb
->path
);
296 argc
= parse_options(argc
, argv
, prefix
, options
,
297 builtin_multi_pack_index_usage
, 0);
298 FREE_AND_NULL(options
);
300 res
= fn(argc
, argv
, prefix
);
302 free(opts
.object_dir
);