2018-07-13 03:39:20 +08:00
|
|
|
#include "builtin.h"
|
|
|
|
#include "cache.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "parse-options.h"
|
2018-07-13 03:39:21 +08:00
|
|
|
#include "midx.h"
|
2019-03-22 03:36:13 +08:00
|
|
|
#include "trace2.h"
|
2018-07-13 03:39:20 +08:00
|
|
|
|
2021-03-30 23:03:54 +08:00
|
|
|
#define BUILTIN_MIDX_WRITE_USAGE \
|
|
|
|
N_("git multi-pack-index [<options>] write")
|
|
|
|
|
|
|
|
#define BUILTIN_MIDX_VERIFY_USAGE \
|
|
|
|
N_("git multi-pack-index [<options>] verify")
|
|
|
|
|
|
|
|
#define BUILTIN_MIDX_EXPIRE_USAGE \
|
|
|
|
N_("git multi-pack-index [<options>] expire")
|
|
|
|
|
|
|
|
#define BUILTIN_MIDX_REPACK_USAGE \
|
|
|
|
N_("git multi-pack-index [<options>] repack [--batch-size=<size>]")
|
|
|
|
|
2018-07-13 03:39:20 +08:00
|
|
|
static char const * const builtin_multi_pack_index_usage[] = {
|
2021-03-30 23:03:54 +08:00
|
|
|
BUILTIN_MIDX_WRITE_USAGE,
|
|
|
|
BUILTIN_MIDX_VERIFY_USAGE,
|
|
|
|
BUILTIN_MIDX_EXPIRE_USAGE,
|
|
|
|
BUILTIN_MIDX_REPACK_USAGE,
|
2018-07-13 03:39:20 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct opts_multi_pack_index {
|
|
|
|
const char *object_dir;
|
2019-06-11 07:35:26 +08:00
|
|
|
unsigned long batch_size;
|
2021-03-30 23:03:47 +08:00
|
|
|
unsigned flags;
|
2018-07-13 03:39:20 +08:00
|
|
|
} opts;
|
|
|
|
|
|
|
|
int cmd_multi_pack_index(int argc, const char **argv,
|
|
|
|
const char *prefix)
|
|
|
|
{
|
|
|
|
static struct option builtin_multi_pack_index_options[] = {
|
|
|
|
OPT_FILENAME(0, "object-dir", &opts.object_dir,
|
|
|
|
N_("object directory containing set of packfile and pack-index pairs")),
|
2021-03-30 23:03:51 +08:00
|
|
|
OPT_BIT(0, "progress", &opts.flags, N_("force progress reporting"), MIDX_PROGRESS),
|
2019-06-11 07:35:26 +08:00
|
|
|
OPT_MAGNITUDE(0, "batch-size", &opts.batch_size,
|
|
|
|
N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
|
2018-07-13 03:39:20 +08:00
|
|
|
OPT_END(),
|
|
|
|
};
|
|
|
|
|
|
|
|
git_config(git_default_config, NULL);
|
|
|
|
|
2021-03-30 23:03:51 +08:00
|
|
|
if (isatty(2))
|
|
|
|
opts.flags |= MIDX_PROGRESS;
|
2018-07-13 03:39:20 +08:00
|
|
|
argc = parse_options(argc, argv, prefix,
|
|
|
|
builtin_multi_pack_index_options,
|
|
|
|
builtin_multi_pack_index_usage, 0);
|
|
|
|
|
|
|
|
if (!opts.object_dir)
|
|
|
|
opts.object_dir = get_object_directory();
|
|
|
|
|
2018-07-13 03:39:21 +08:00
|
|
|
if (argc == 0)
|
2018-08-21 00:51:53 +08:00
|
|
|
usage_with_options(builtin_multi_pack_index_usage,
|
|
|
|
builtin_multi_pack_index_options);
|
2018-07-13 03:39:21 +08:00
|
|
|
|
2018-08-21 00:51:53 +08:00
|
|
|
if (argc > 1) {
|
|
|
|
die(_("too many arguments"));
|
|
|
|
return 1;
|
|
|
|
}
|
2018-07-13 03:39:21 +08:00
|
|
|
|
2019-03-22 03:36:13 +08:00
|
|
|
trace2_cmd_mode(argv[0]);
|
|
|
|
|
2019-06-11 07:35:26 +08:00
|
|
|
if (!strcmp(argv[0], "repack"))
|
2019-10-22 02:40:03 +08:00
|
|
|
return midx_repack(the_repository, opts.object_dir,
|
2021-03-30 23:03:47 +08:00
|
|
|
(size_t)opts.batch_size, opts.flags);
|
2019-06-11 07:35:26 +08:00
|
|
|
if (opts.batch_size)
|
|
|
|
die(_("--batch-size option is only for 'repack' subcommand"));
|
|
|
|
|
2018-08-21 00:51:53 +08:00
|
|
|
if (!strcmp(argv[0], "write"))
|
2021-03-30 23:03:47 +08:00
|
|
|
return write_midx_file(opts.object_dir, opts.flags);
|
2018-09-14 02:02:13 +08:00
|
|
|
if (!strcmp(argv[0], "verify"))
|
2021-03-30 23:03:47 +08:00
|
|
|
return verify_midx_file(the_repository, opts.object_dir, opts.flags);
|
2019-06-11 07:35:23 +08:00
|
|
|
if (!strcmp(argv[0], "expire"))
|
2021-03-30 23:03:47 +08:00
|
|
|
return expire_midx_packs(the_repository, opts.object_dir, opts.flags);
|
2018-07-13 03:39:21 +08:00
|
|
|
|
2019-06-11 07:35:26 +08:00
|
|
|
die(_("unrecognized subcommand: %s"), argv[0]);
|
2018-07-13 03:39:20 +08:00
|
|
|
}
|