summaryrefslogtreecommitdiff
path: root/builtin/multi-pack-index.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/multi-pack-index.c')
-rw-r--r--builtin/multi-pack-index.c91
1 files changed, 48 insertions, 43 deletions
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 5edbb7f..a72aebe 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -1,10 +1,13 @@
#include "builtin.h"
-#include "cache.h"
+#include "abspath.h"
#include "config.h"
+#include "environment.h"
+#include "gettext.h"
#include "parse-options.h"
#include "midx.h"
+#include "strbuf.h"
#include "trace2.h"
-#include "object-store.h"
+#include "object-store-ll.h"
#define BUILTIN_MIDX_WRITE_USAGE \
N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]" \
@@ -56,11 +59,12 @@ static struct opts_multi_pack_index {
static int parse_object_dir(const struct option *opt, const char *arg,
int unset)
{
- free(opts.object_dir);
+ char **value = opt->value;
+ free(*value);
if (unset)
- opts.object_dir = xstrdup(get_object_directory());
+ *value = xstrdup(get_object_directory());
else
- opts.object_dir = real_pathdup(arg, 1);
+ *value = real_pathdup(arg, 1);
return 0;
}
@@ -78,7 +82,8 @@ static struct option *add_common_options(struct option *prev)
}
static int git_multi_pack_index_write_config(const char *var, const char *value,
- void *cb)
+ const struct config_context *ctx UNUSED,
+ void *cb UNUSED)
{
if (!strcmp(var, "pack.writebitmaphashcache")) {
if (git_config_bool(var, value))
@@ -87,6 +92,13 @@ static int git_multi_pack_index_write_config(const char *var, const char *value,
opts.flags &= ~MIDX_WRITE_BITMAP_HASH_CACHE;
}
+ if (!strcmp(var, "pack.writebitmaplookuptable")) {
+ if (git_config_bool(var, value))
+ opts.flags |= MIDX_WRITE_BITMAP_LOOKUP_TABLE;
+ else
+ opts.flags &= ~MIDX_WRITE_BITMAP_LOOKUP_TABLE;
+ }
+
/*
* We should never make a fall-back call to 'git_default_config', since
* this was already called in 'cmd_multi_pack_index()'.
@@ -104,7 +116,8 @@ static void read_packs_from_stdin(struct string_list *to)
strbuf_release(&buf);
}
-static int cmd_multi_pack_index_write(int argc, const char **argv)
+static int cmd_multi_pack_index_write(int argc, const char **argv,
+ const char *prefix)
{
struct option *options;
static struct option builtin_multi_pack_index_write_options[] = {
@@ -132,9 +145,9 @@ static int cmd_multi_pack_index_write(int argc, const char **argv)
if (isatty(2))
opts.flags |= MIDX_PROGRESS;
- argc = parse_options(argc, argv, NULL,
+ argc = parse_options(argc, argv, prefix,
options, builtin_multi_pack_index_write_usage,
- PARSE_OPT_KEEP_UNKNOWN);
+ 0);
if (argc)
usage_with_options(builtin_multi_pack_index_write_usage,
options);
@@ -160,7 +173,8 @@ static int cmd_multi_pack_index_write(int argc, const char **argv)
opts.refs_snapshot, opts.flags);
}
-static int cmd_multi_pack_index_verify(int argc, const char **argv)
+static int cmd_multi_pack_index_verify(int argc, const char **argv,
+ const char *prefix)
{
struct option *options;
static struct option builtin_multi_pack_index_verify_options[] = {
@@ -174,9 +188,9 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv)
if (isatty(2))
opts.flags |= MIDX_PROGRESS;
- argc = parse_options(argc, argv, NULL,
+ argc = parse_options(argc, argv, prefix,
options, builtin_multi_pack_index_verify_usage,
- PARSE_OPT_KEEP_UNKNOWN);
+ 0);
if (argc)
usage_with_options(builtin_multi_pack_index_verify_usage,
options);
@@ -186,7 +200,8 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv)
return verify_midx_file(the_repository, opts.object_dir, opts.flags);
}
-static int cmd_multi_pack_index_expire(int argc, const char **argv)
+static int cmd_multi_pack_index_expire(int argc, const char **argv,
+ const char *prefix)
{
struct option *options;
static struct option builtin_multi_pack_index_expire_options[] = {
@@ -200,9 +215,9 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv)
if (isatty(2))
opts.flags |= MIDX_PROGRESS;
- argc = parse_options(argc, argv, NULL,
+ argc = parse_options(argc, argv, prefix,
options, builtin_multi_pack_index_expire_usage,
- PARSE_OPT_KEEP_UNKNOWN);
+ 0);
if (argc)
usage_with_options(builtin_multi_pack_index_expire_usage,
options);
@@ -212,7 +227,8 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv)
return expire_midx_packs(the_repository, opts.object_dir, opts.flags);
}
-static int cmd_multi_pack_index_repack(int argc, const char **argv)
+static int cmd_multi_pack_index_repack(int argc, const char **argv,
+ const char *prefix)
{
struct option *options;
static struct option builtin_multi_pack_index_repack_options[] = {
@@ -229,10 +245,10 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv)
if (isatty(2))
opts.flags |= MIDX_PROGRESS;
- argc = parse_options(argc, argv, NULL,
+ argc = parse_options(argc, argv, prefix,
options,
builtin_multi_pack_index_repack_usage,
- PARSE_OPT_KEEP_UNKNOWN);
+ 0);
if (argc)
usage_with_options(builtin_multi_pack_index_repack_usage,
options);
@@ -247,7 +263,15 @@ int cmd_multi_pack_index(int argc, const char **argv,
const char *prefix)
{
int res;
- struct option *builtin_multi_pack_index_options = common_opts;
+ parse_opt_subcommand_fn *fn = NULL;
+ struct option builtin_multi_pack_index_options[] = {
+ OPT_SUBCOMMAND("repack", &fn, cmd_multi_pack_index_repack),
+ OPT_SUBCOMMAND("write", &fn, cmd_multi_pack_index_write),
+ OPT_SUBCOMMAND("verify", &fn, cmd_multi_pack_index_verify),
+ OPT_SUBCOMMAND("expire", &fn, cmd_multi_pack_index_expire),
+ OPT_END(),
+ };
+ struct option *options = parse_options_concat(builtin_multi_pack_index_options, common_opts);
git_config(git_default_config, NULL);
@@ -256,31 +280,12 @@ int cmd_multi_pack_index(int argc, const char **argv,
the_repository->objects->odb)
opts.object_dir = xstrdup(the_repository->objects->odb->path);
- argc = parse_options(argc, argv, prefix,
- builtin_multi_pack_index_options,
- builtin_multi_pack_index_usage,
- PARSE_OPT_STOP_AT_NON_OPTION);
-
- if (!argc)
- goto usage;
-
- if (!strcmp(argv[0], "repack"))
- res = cmd_multi_pack_index_repack(argc, argv);
- else if (!strcmp(argv[0], "write"))
- res = cmd_multi_pack_index_write(argc, argv);
- else if (!strcmp(argv[0], "verify"))
- res = cmd_multi_pack_index_verify(argc, argv);
- else if (!strcmp(argv[0], "expire"))
- res = cmd_multi_pack_index_expire(argc, argv);
- else {
- error(_("unrecognized subcommand: %s"), argv[0]);
- goto usage;
- }
+ argc = parse_options(argc, argv, prefix, options,
+ builtin_multi_pack_index_usage, 0);
+ FREE_AND_NULL(options);
+
+ res = fn(argc, argv, prefix);
free(opts.object_dir);
return res;
-
-usage:
- usage_with_options(builtin_multi_pack_index_usage,
- builtin_multi_pack_index_options);
}