4 #include "environment.h"
6 #include "parse-options.h"
10 #include "object-store-ll.h"
12 #define BUILTIN_MIDX_WRITE_USAGE \
13 N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]" \
14 "[--refs-snapshot=<path>]")
16 #define BUILTIN_MIDX_VERIFY_USAGE \
17 N_("git multi-pack-index [<options>] verify")
19 #define BUILTIN_MIDX_EXPIRE_USAGE \
20 N_("git multi-pack-index [<options>] expire")
22 #define BUILTIN_MIDX_REPACK_USAGE \
23 N_("git multi-pack-index [<options>] repack [--batch-size=<size>]")
25 static char const * const builtin_multi_pack_index_write_usage
[] = {
26 BUILTIN_MIDX_WRITE_USAGE
,
29 static char const * const builtin_multi_pack_index_verify_usage
[] = {
30 BUILTIN_MIDX_VERIFY_USAGE
,
33 static char const * const builtin_multi_pack_index_expire_usage
[] = {
34 BUILTIN_MIDX_EXPIRE_USAGE
,
37 static char const * const builtin_multi_pack_index_repack_usage
[] = {
38 BUILTIN_MIDX_REPACK_USAGE
,
41 static char const * const builtin_multi_pack_index_usage
[] = {
42 BUILTIN_MIDX_WRITE_USAGE
,
43 BUILTIN_MIDX_VERIFY_USAGE
,
44 BUILTIN_MIDX_EXPIRE_USAGE
,
45 BUILTIN_MIDX_REPACK_USAGE
,
49 static struct opts_multi_pack_index
{
51 const char *preferred_pack
;
52 const char *refs_snapshot
;
53 unsigned long batch_size
;
59 static int parse_object_dir(const struct option
*opt
, const char *arg
,
62 char **value
= opt
->value
;
65 *value
= xstrdup(get_object_directory());
67 *value
= real_pathdup(arg
, 1);
71 static struct option common_opts
[] = {
72 OPT_CALLBACK(0, "object-dir", &opts
.object_dir
,
74 N_("object directory containing set of packfile and pack-index pairs"),
79 static struct option
*add_common_options(struct option
*prev
)
81 return parse_options_concat(common_opts
, prev
);
84 static int git_multi_pack_index_write_config(const char *var
, const char *value
,
85 const struct config_context
*ctx UNUSED
,
88 if (!strcmp(var
, "pack.writebitmaphashcache")) {
89 if (git_config_bool(var
, value
))
90 opts
.flags
|= MIDX_WRITE_BITMAP_HASH_CACHE
;
92 opts
.flags
&= ~MIDX_WRITE_BITMAP_HASH_CACHE
;
95 if (!strcmp(var
, "pack.writebitmaplookuptable")) {
96 if (git_config_bool(var
, value
))
97 opts
.flags
|= MIDX_WRITE_BITMAP_LOOKUP_TABLE
;
99 opts
.flags
&= ~MIDX_WRITE_BITMAP_LOOKUP_TABLE
;
103 * We should never make a fall-back call to 'git_default_config', since
104 * this was already called in 'cmd_multi_pack_index()'.
109 static void read_packs_from_stdin(struct string_list
*to
)
111 struct strbuf buf
= STRBUF_INIT
;
112 while (strbuf_getline(&buf
, stdin
) != EOF
)
113 string_list_append(to
, buf
.buf
);
114 string_list_sort(to
);
116 strbuf_release(&buf
);
119 static int cmd_multi_pack_index_write(int argc
, const char **argv
,
122 struct option
*options
;
123 static struct option builtin_multi_pack_index_write_options
[] = {
124 OPT_STRING(0, "preferred-pack", &opts
.preferred_pack
,
125 N_("preferred-pack"),
126 N_("pack for reuse when computing a multi-pack bitmap")),
127 OPT_BIT(0, "bitmap", &opts
.flags
, N_("write multi-pack bitmap"),
128 MIDX_WRITE_BITMAP
| MIDX_WRITE_REV_INDEX
),
129 OPT_BIT(0, "progress", &opts
.flags
,
130 N_("force progress reporting"), MIDX_PROGRESS
),
131 OPT_BOOL(0, "stdin-packs", &opts
.stdin_packs
,
132 N_("write multi-pack index containing only given indexes")),
133 OPT_FILENAME(0, "refs-snapshot", &opts
.refs_snapshot
,
134 N_("refs snapshot for selecting bitmap commits")),
138 opts
.flags
|= MIDX_WRITE_BITMAP_HASH_CACHE
;
140 git_config(git_multi_pack_index_write_config
, NULL
);
142 options
= add_common_options(builtin_multi_pack_index_write_options
);
144 trace2_cmd_mode(argv
[0]);
147 opts
.flags
|= MIDX_PROGRESS
;
148 argc
= parse_options(argc
, argv
, prefix
,
149 options
, builtin_multi_pack_index_write_usage
,
152 usage_with_options(builtin_multi_pack_index_write_usage
,
155 FREE_AND_NULL(options
);
157 if (opts
.stdin_packs
) {
158 struct string_list packs
= STRING_LIST_INIT_DUP
;
161 read_packs_from_stdin(&packs
);
163 ret
= write_midx_file_only(opts
.object_dir
, &packs
,
165 opts
.refs_snapshot
, opts
.flags
);
167 string_list_clear(&packs
, 0);
172 return write_midx_file(opts
.object_dir
, opts
.preferred_pack
,
173 opts
.refs_snapshot
, opts
.flags
);
176 static int cmd_multi_pack_index_verify(int argc
, const char **argv
,
179 struct option
*options
;
180 static struct option builtin_multi_pack_index_verify_options
[] = {
181 OPT_BIT(0, "progress", &opts
.flags
,
182 N_("force progress reporting"), MIDX_PROGRESS
),
185 options
= add_common_options(builtin_multi_pack_index_verify_options
);
187 trace2_cmd_mode(argv
[0]);
190 opts
.flags
|= MIDX_PROGRESS
;
191 argc
= parse_options(argc
, argv
, prefix
,
192 options
, builtin_multi_pack_index_verify_usage
,
195 usage_with_options(builtin_multi_pack_index_verify_usage
,
198 FREE_AND_NULL(options
);
200 return verify_midx_file(the_repository
, opts
.object_dir
, opts
.flags
);
203 static int cmd_multi_pack_index_expire(int argc
, const char **argv
,
206 struct option
*options
;
207 static struct option builtin_multi_pack_index_expire_options
[] = {
208 OPT_BIT(0, "progress", &opts
.flags
,
209 N_("force progress reporting"), MIDX_PROGRESS
),
212 options
= add_common_options(builtin_multi_pack_index_expire_options
);
214 trace2_cmd_mode(argv
[0]);
217 opts
.flags
|= MIDX_PROGRESS
;
218 argc
= parse_options(argc
, argv
, prefix
,
219 options
, builtin_multi_pack_index_expire_usage
,
222 usage_with_options(builtin_multi_pack_index_expire_usage
,
225 FREE_AND_NULL(options
);
227 return expire_midx_packs(the_repository
, opts
.object_dir
, opts
.flags
);
230 static int cmd_multi_pack_index_repack(int argc
, const char **argv
,
233 struct option
*options
;
234 static struct option builtin_multi_pack_index_repack_options
[] = {
235 OPT_MAGNITUDE(0, "batch-size", &opts
.batch_size
,
236 N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
237 OPT_BIT(0, "progress", &opts
.flags
,
238 N_("force progress reporting"), MIDX_PROGRESS
),
242 options
= add_common_options(builtin_multi_pack_index_repack_options
);
244 trace2_cmd_mode(argv
[0]);
247 opts
.flags
|= MIDX_PROGRESS
;
248 argc
= parse_options(argc
, argv
, prefix
,
250 builtin_multi_pack_index_repack_usage
,
253 usage_with_options(builtin_multi_pack_index_repack_usage
,
256 FREE_AND_NULL(options
);
258 return midx_repack(the_repository
, opts
.object_dir
,
259 (size_t)opts
.batch_size
, opts
.flags
);
262 int cmd_multi_pack_index(int argc
, const char **argv
,
266 parse_opt_subcommand_fn
*fn
= NULL
;
267 struct option builtin_multi_pack_index_options
[] = {
268 OPT_SUBCOMMAND("repack", &fn
, cmd_multi_pack_index_repack
),
269 OPT_SUBCOMMAND("write", &fn
, cmd_multi_pack_index_write
),
270 OPT_SUBCOMMAND("verify", &fn
, cmd_multi_pack_index_verify
),
271 OPT_SUBCOMMAND("expire", &fn
, cmd_multi_pack_index_expire
),
274 struct option
*options
= parse_options_concat(builtin_multi_pack_index_options
, common_opts
);
276 git_config(git_default_config
, NULL
);
278 if (the_repository
&&
279 the_repository
->objects
&&
280 the_repository
->objects
->odb
)
281 opts
.object_dir
= xstrdup(the_repository
->objects
->odb
->path
);
283 argc
= parse_options(argc
, argv
, prefix
, options
,
284 builtin_multi_pack_index_usage
, 0);
285 FREE_AND_NULL(options
);
287 res
= fn(argc
, argv
, prefix
);
289 free(opts
.object_dir
);