2018-07-12 22:39:20 +03:00
|
|
|
#include "builtin.h"
|
|
|
|
#include "cache.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "parse-options.h"
|
2018-07-12 22:39:21 +03:00
|
|
|
#include "midx.h"
|
2019-03-21 22:36:13 +03:00
|
|
|
#include "trace2.h"
|
2021-03-30 18:04:11 +03:00
|
|
|
#include "object-store.h"
|
2018-07-12 22:39:20 +03:00
|
|
|
|
2021-03-30 18:03:54 +03:00
|
|
|
#define BUILTIN_MIDX_WRITE_USAGE \
|
2021-03-30 18:04:11 +03:00
|
|
|
N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]")
|
2021-03-30 18:03:54 +03:00
|
|
|
|
|
|
|
#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>]")
|
|
|
|
|
builtin/multi-pack-index.c: split sub-commands
Handle sub-commands of the 'git multi-pack-index' builtin (e.g.,
"write", "repack", etc.) separately from one another. This allows
sub-commands with unique options, without forcing cmd_multi_pack_index()
to reject invalid combinations itself.
This comes at the cost of some duplication and boilerplate. Luckily, the
duplication is reduced to a minimum, since common options are shared
among sub-commands due to a suggestion by Ævar. (Sub-commands do have to
retain the common options, too, since this builtin accepts common
options on either side of the sub-command).
Roughly speaking, cmd_multi_pack_index() parses options (including
common ones), and stops at the first non-option, which is the
sub-command. It then dispatches to the appropriate sub-command, which
parses the remaining options (also including common options).
Unknown options are kept by the sub-commands in order to detect their
presence (and complain that too many arguments were given).
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-03-30 18:03:57 +03:00
|
|
|
static char const * const builtin_multi_pack_index_write_usage[] = {
|
|
|
|
BUILTIN_MIDX_WRITE_USAGE,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
static char const * const builtin_multi_pack_index_verify_usage[] = {
|
|
|
|
BUILTIN_MIDX_VERIFY_USAGE,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
static char const * const builtin_multi_pack_index_expire_usage[] = {
|
|
|
|
BUILTIN_MIDX_EXPIRE_USAGE,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
static char const * const builtin_multi_pack_index_repack_usage[] = {
|
|
|
|
BUILTIN_MIDX_REPACK_USAGE,
|
|
|
|
NULL
|
|
|
|
};
|
2018-07-12 22:39:20 +03:00
|
|
|
static char const * const builtin_multi_pack_index_usage[] = {
|
2021-03-30 18:03:54 +03:00
|
|
|
BUILTIN_MIDX_WRITE_USAGE,
|
|
|
|
BUILTIN_MIDX_VERIFY_USAGE,
|
|
|
|
BUILTIN_MIDX_EXPIRE_USAGE,
|
|
|
|
BUILTIN_MIDX_REPACK_USAGE,
|
2018-07-12 22:39:20 +03:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct opts_multi_pack_index {
|
|
|
|
const char *object_dir;
|
2021-03-30 18:04:11 +03:00
|
|
|
const char *preferred_pack;
|
2019-06-11 02:35:26 +03:00
|
|
|
unsigned long batch_size;
|
2021-03-30 18:03:47 +03:00
|
|
|
unsigned flags;
|
2018-07-12 22:39:20 +03:00
|
|
|
} opts;
|
|
|
|
|
builtin/multi-pack-index.c: split sub-commands
Handle sub-commands of the 'git multi-pack-index' builtin (e.g.,
"write", "repack", etc.) separately from one another. This allows
sub-commands with unique options, without forcing cmd_multi_pack_index()
to reject invalid combinations itself.
This comes at the cost of some duplication and boilerplate. Luckily, the
duplication is reduced to a minimum, since common options are shared
among sub-commands due to a suggestion by Ævar. (Sub-commands do have to
retain the common options, too, since this builtin accepts common
options on either side of the sub-command).
Roughly speaking, cmd_multi_pack_index() parses options (including
common ones), and stops at the first non-option, which is the
sub-command. It then dispatches to the appropriate sub-command, which
parses the remaining options (also including common options).
Unknown options are kept by the sub-commands in order to detect their
presence (and complain that too many arguments were given).
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-03-30 18:03:57 +03:00
|
|
|
static struct option common_opts[] = {
|
|
|
|
OPT_FILENAME(0, "object-dir", &opts.object_dir,
|
|
|
|
N_("object directory containing set of packfile and pack-index pairs")),
|
|
|
|
OPT_BIT(0, "progress", &opts.flags, N_("force progress reporting"), MIDX_PROGRESS),
|
|
|
|
OPT_END(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct option *add_common_options(struct option *prev)
|
|
|
|
{
|
|
|
|
return parse_options_concat(common_opts, prev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cmd_multi_pack_index_write(int argc, const char **argv)
|
|
|
|
{
|
2021-03-30 18:04:11 +03:00
|
|
|
struct option *options;
|
|
|
|
static struct option builtin_multi_pack_index_write_options[] = {
|
|
|
|
OPT_STRING(0, "preferred-pack", &opts.preferred_pack,
|
|
|
|
N_("preferred-pack"),
|
|
|
|
N_("pack for reuse when computing a multi-pack bitmap")),
|
2021-08-31 23:52:24 +03:00
|
|
|
OPT_BIT(0, "bitmap", &opts.flags, N_("write multi-pack bitmap"),
|
|
|
|
MIDX_WRITE_BITMAP | MIDX_WRITE_REV_INDEX),
|
2021-03-30 18:04:11 +03:00
|
|
|
OPT_END(),
|
|
|
|
};
|
|
|
|
|
|
|
|
options = add_common_options(builtin_multi_pack_index_write_options);
|
builtin/multi-pack-index.c: split sub-commands
Handle sub-commands of the 'git multi-pack-index' builtin (e.g.,
"write", "repack", etc.) separately from one another. This allows
sub-commands with unique options, without forcing cmd_multi_pack_index()
to reject invalid combinations itself.
This comes at the cost of some duplication and boilerplate. Luckily, the
duplication is reduced to a minimum, since common options are shared
among sub-commands due to a suggestion by Ævar. (Sub-commands do have to
retain the common options, too, since this builtin accepts common
options on either side of the sub-command).
Roughly speaking, cmd_multi_pack_index() parses options (including
common ones), and stops at the first non-option, which is the
sub-command. It then dispatches to the appropriate sub-command, which
parses the remaining options (also including common options).
Unknown options are kept by the sub-commands in order to detect their
presence (and complain that too many arguments were given).
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-03-30 18:03:57 +03:00
|
|
|
|
2021-03-30 18:04:01 +03:00
|
|
|
trace2_cmd_mode(argv[0]);
|
|
|
|
|
builtin/multi-pack-index.c: split sub-commands
Handle sub-commands of the 'git multi-pack-index' builtin (e.g.,
"write", "repack", etc.) separately from one another. This allows
sub-commands with unique options, without forcing cmd_multi_pack_index()
to reject invalid combinations itself.
This comes at the cost of some duplication and boilerplate. Luckily, the
duplication is reduced to a minimum, since common options are shared
among sub-commands due to a suggestion by Ævar. (Sub-commands do have to
retain the common options, too, since this builtin accepts common
options on either side of the sub-command).
Roughly speaking, cmd_multi_pack_index() parses options (including
common ones), and stops at the first non-option, which is the
sub-command. It then dispatches to the appropriate sub-command, which
parses the remaining options (also including common options).
Unknown options are kept by the sub-commands in order to detect their
presence (and complain that too many arguments were given).
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-03-30 18:03:57 +03:00
|
|
|
argc = parse_options(argc, argv, NULL,
|
|
|
|
options, builtin_multi_pack_index_write_usage,
|
|
|
|
PARSE_OPT_KEEP_UNKNOWN);
|
|
|
|
if (argc)
|
|
|
|
usage_with_options(builtin_multi_pack_index_write_usage,
|
|
|
|
options);
|
|
|
|
|
2021-03-30 18:04:11 +03:00
|
|
|
FREE_AND_NULL(options);
|
|
|
|
|
|
|
|
return write_midx_file(opts.object_dir, opts.preferred_pack,
|
|
|
|
opts.flags);
|
builtin/multi-pack-index.c: split sub-commands
Handle sub-commands of the 'git multi-pack-index' builtin (e.g.,
"write", "repack", etc.) separately from one another. This allows
sub-commands with unique options, without forcing cmd_multi_pack_index()
to reject invalid combinations itself.
This comes at the cost of some duplication and boilerplate. Luckily, the
duplication is reduced to a minimum, since common options are shared
among sub-commands due to a suggestion by Ævar. (Sub-commands do have to
retain the common options, too, since this builtin accepts common
options on either side of the sub-command).
Roughly speaking, cmd_multi_pack_index() parses options (including
common ones), and stops at the first non-option, which is the
sub-command. It then dispatches to the appropriate sub-command, which
parses the remaining options (also including common options).
Unknown options are kept by the sub-commands in order to detect their
presence (and complain that too many arguments were given).
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-03-30 18:03:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int cmd_multi_pack_index_verify(int argc, const char **argv)
|
|
|
|
{
|
|
|
|
struct option *options = common_opts;
|
|
|
|
|
2021-03-30 18:04:01 +03:00
|
|
|
trace2_cmd_mode(argv[0]);
|
|
|
|
|
builtin/multi-pack-index.c: split sub-commands
Handle sub-commands of the 'git multi-pack-index' builtin (e.g.,
"write", "repack", etc.) separately from one another. This allows
sub-commands with unique options, without forcing cmd_multi_pack_index()
to reject invalid combinations itself.
This comes at the cost of some duplication and boilerplate. Luckily, the
duplication is reduced to a minimum, since common options are shared
among sub-commands due to a suggestion by Ævar. (Sub-commands do have to
retain the common options, too, since this builtin accepts common
options on either side of the sub-command).
Roughly speaking, cmd_multi_pack_index() parses options (including
common ones), and stops at the first non-option, which is the
sub-command. It then dispatches to the appropriate sub-command, which
parses the remaining options (also including common options).
Unknown options are kept by the sub-commands in order to detect their
presence (and complain that too many arguments were given).
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-03-30 18:03:57 +03:00
|
|
|
argc = parse_options(argc, argv, NULL,
|
|
|
|
options, builtin_multi_pack_index_verify_usage,
|
|
|
|
PARSE_OPT_KEEP_UNKNOWN);
|
|
|
|
if (argc)
|
|
|
|
usage_with_options(builtin_multi_pack_index_verify_usage,
|
|
|
|
options);
|
|
|
|
|
|
|
|
return verify_midx_file(the_repository, opts.object_dir, opts.flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cmd_multi_pack_index_expire(int argc, const char **argv)
|
|
|
|
{
|
|
|
|
struct option *options = common_opts;
|
|
|
|
|
2021-03-30 18:04:01 +03:00
|
|
|
trace2_cmd_mode(argv[0]);
|
|
|
|
|
builtin/multi-pack-index.c: split sub-commands
Handle sub-commands of the 'git multi-pack-index' builtin (e.g.,
"write", "repack", etc.) separately from one another. This allows
sub-commands with unique options, without forcing cmd_multi_pack_index()
to reject invalid combinations itself.
This comes at the cost of some duplication and boilerplate. Luckily, the
duplication is reduced to a minimum, since common options are shared
among sub-commands due to a suggestion by Ævar. (Sub-commands do have to
retain the common options, too, since this builtin accepts common
options on either side of the sub-command).
Roughly speaking, cmd_multi_pack_index() parses options (including
common ones), and stops at the first non-option, which is the
sub-command. It then dispatches to the appropriate sub-command, which
parses the remaining options (also including common options).
Unknown options are kept by the sub-commands in order to detect their
presence (and complain that too many arguments were given).
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-03-30 18:03:57 +03:00
|
|
|
argc = parse_options(argc, argv, NULL,
|
|
|
|
options, builtin_multi_pack_index_expire_usage,
|
|
|
|
PARSE_OPT_KEEP_UNKNOWN);
|
|
|
|
if (argc)
|
|
|
|
usage_with_options(builtin_multi_pack_index_expire_usage,
|
|
|
|
options);
|
|
|
|
|
|
|
|
return expire_midx_packs(the_repository, opts.object_dir, opts.flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cmd_multi_pack_index_repack(int argc, const char **argv)
|
2018-07-12 22:39:20 +03:00
|
|
|
{
|
builtin/multi-pack-index.c: split sub-commands
Handle sub-commands of the 'git multi-pack-index' builtin (e.g.,
"write", "repack", etc.) separately from one another. This allows
sub-commands with unique options, without forcing cmd_multi_pack_index()
to reject invalid combinations itself.
This comes at the cost of some duplication and boilerplate. Luckily, the
duplication is reduced to a minimum, since common options are shared
among sub-commands due to a suggestion by Ævar. (Sub-commands do have to
retain the common options, too, since this builtin accepts common
options on either side of the sub-command).
Roughly speaking, cmd_multi_pack_index() parses options (including
common ones), and stops at the first non-option, which is the
sub-command. It then dispatches to the appropriate sub-command, which
parses the remaining options (also including common options).
Unknown options are kept by the sub-commands in order to detect their
presence (and complain that too many arguments were given).
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-03-30 18:03:57 +03:00
|
|
|
struct option *options;
|
|
|
|
static struct option builtin_multi_pack_index_repack_options[] = {
|
2019-06-11 02:35:26 +03: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-12 22:39:20 +03:00
|
|
|
OPT_END(),
|
|
|
|
};
|
|
|
|
|
builtin/multi-pack-index.c: split sub-commands
Handle sub-commands of the 'git multi-pack-index' builtin (e.g.,
"write", "repack", etc.) separately from one another. This allows
sub-commands with unique options, without forcing cmd_multi_pack_index()
to reject invalid combinations itself.
This comes at the cost of some duplication and boilerplate. Luckily, the
duplication is reduced to a minimum, since common options are shared
among sub-commands due to a suggestion by Ævar. (Sub-commands do have to
retain the common options, too, since this builtin accepts common
options on either side of the sub-command).
Roughly speaking, cmd_multi_pack_index() parses options (including
common ones), and stops at the first non-option, which is the
sub-command. It then dispatches to the appropriate sub-command, which
parses the remaining options (also including common options).
Unknown options are kept by the sub-commands in order to detect their
presence (and complain that too many arguments were given).
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-03-30 18:03:57 +03:00
|
|
|
options = add_common_options(builtin_multi_pack_index_repack_options);
|
|
|
|
|
2021-03-30 18:04:01 +03:00
|
|
|
trace2_cmd_mode(argv[0]);
|
|
|
|
|
builtin/multi-pack-index.c: split sub-commands
Handle sub-commands of the 'git multi-pack-index' builtin (e.g.,
"write", "repack", etc.) separately from one another. This allows
sub-commands with unique options, without forcing cmd_multi_pack_index()
to reject invalid combinations itself.
This comes at the cost of some duplication and boilerplate. Luckily, the
duplication is reduced to a minimum, since common options are shared
among sub-commands due to a suggestion by Ævar. (Sub-commands do have to
retain the common options, too, since this builtin accepts common
options on either side of the sub-command).
Roughly speaking, cmd_multi_pack_index() parses options (including
common ones), and stops at the first non-option, which is the
sub-command. It then dispatches to the appropriate sub-command, which
parses the remaining options (also including common options).
Unknown options are kept by the sub-commands in order to detect their
presence (and complain that too many arguments were given).
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-03-30 18:03:57 +03:00
|
|
|
argc = parse_options(argc, argv, NULL,
|
|
|
|
options,
|
|
|
|
builtin_multi_pack_index_repack_usage,
|
|
|
|
PARSE_OPT_KEEP_UNKNOWN);
|
|
|
|
if (argc)
|
|
|
|
usage_with_options(builtin_multi_pack_index_repack_usage,
|
|
|
|
options);
|
|
|
|
|
|
|
|
FREE_AND_NULL(options);
|
|
|
|
|
|
|
|
return midx_repack(the_repository, opts.object_dir,
|
|
|
|
(size_t)opts.batch_size, opts.flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmd_multi_pack_index(int argc, const char **argv,
|
|
|
|
const char *prefix)
|
|
|
|
{
|
|
|
|
struct option *builtin_multi_pack_index_options = common_opts;
|
|
|
|
|
2018-07-12 22:39:20 +03:00
|
|
|
git_config(git_default_config, NULL);
|
|
|
|
|
2021-03-30 18:03:51 +03:00
|
|
|
if (isatty(2))
|
|
|
|
opts.flags |= MIDX_PROGRESS;
|
2018-07-12 22:39:20 +03:00
|
|
|
argc = parse_options(argc, argv, prefix,
|
|
|
|
builtin_multi_pack_index_options,
|
builtin/multi-pack-index.c: split sub-commands
Handle sub-commands of the 'git multi-pack-index' builtin (e.g.,
"write", "repack", etc.) separately from one another. This allows
sub-commands with unique options, without forcing cmd_multi_pack_index()
to reject invalid combinations itself.
This comes at the cost of some duplication and boilerplate. Luckily, the
duplication is reduced to a minimum, since common options are shared
among sub-commands due to a suggestion by Ævar. (Sub-commands do have to
retain the common options, too, since this builtin accepts common
options on either side of the sub-command).
Roughly speaking, cmd_multi_pack_index() parses options (including
common ones), and stops at the first non-option, which is the
sub-command. It then dispatches to the appropriate sub-command, which
parses the remaining options (also including common options).
Unknown options are kept by the sub-commands in order to detect their
presence (and complain that too many arguments were given).
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-03-30 18:03:57 +03:00
|
|
|
builtin_multi_pack_index_usage,
|
|
|
|
PARSE_OPT_STOP_AT_NON_OPTION);
|
2018-07-12 22:39:20 +03:00
|
|
|
|
|
|
|
if (!opts.object_dir)
|
|
|
|
opts.object_dir = get_object_directory();
|
|
|
|
|
2018-07-12 22:39:21 +03:00
|
|
|
if (argc == 0)
|
2021-03-30 18:04:04 +03:00
|
|
|
goto usage;
|
2018-07-12 22:39:21 +03:00
|
|
|
|
2019-06-11 02:35:26 +03:00
|
|
|
if (!strcmp(argv[0], "repack"))
|
builtin/multi-pack-index.c: split sub-commands
Handle sub-commands of the 'git multi-pack-index' builtin (e.g.,
"write", "repack", etc.) separately from one another. This allows
sub-commands with unique options, without forcing cmd_multi_pack_index()
to reject invalid combinations itself.
This comes at the cost of some duplication and boilerplate. Luckily, the
duplication is reduced to a minimum, since common options are shared
among sub-commands due to a suggestion by Ævar. (Sub-commands do have to
retain the common options, too, since this builtin accepts common
options on either side of the sub-command).
Roughly speaking, cmd_multi_pack_index() parses options (including
common ones), and stops at the first non-option, which is the
sub-command. It then dispatches to the appropriate sub-command, which
parses the remaining options (also including common options).
Unknown options are kept by the sub-commands in order to detect their
presence (and complain that too many arguments were given).
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-03-30 18:03:57 +03:00
|
|
|
return cmd_multi_pack_index_repack(argc, argv);
|
|
|
|
else if (!strcmp(argv[0], "write"))
|
|
|
|
return cmd_multi_pack_index_write(argc, argv);
|
|
|
|
else if (!strcmp(argv[0], "verify"))
|
|
|
|
return cmd_multi_pack_index_verify(argc, argv);
|
|
|
|
else if (!strcmp(argv[0], "expire"))
|
|
|
|
return cmd_multi_pack_index_expire(argc, argv);
|
2021-03-30 18:04:04 +03:00
|
|
|
else {
|
|
|
|
error(_("unrecognized subcommand: %s"), argv[0]);
|
2021-07-19 20:18:49 +03:00
|
|
|
usage:
|
2021-03-30 18:04:04 +03:00
|
|
|
usage_with_options(builtin_multi_pack_index_usage,
|
|
|
|
builtin_multi_pack_index_options);
|
|
|
|
}
|
2018-07-12 22:39:20 +03:00
|
|
|
}
|