Merge branch 'cb/t5004-empty-tar-archive-fix'
[git] / builtin / multi-pack-index.c
1 #include "builtin.h"
2 #include "cache.h"
3 #include "config.h"
4 #include "parse-options.h"
5 #include "midx.h"
6
7 static char const * const builtin_multi_pack_index_usage[] = {
8         N_("git multi-pack-index [--object-dir=<dir>] (write|verify)"),
9         NULL
10 };
11
12 static struct opts_multi_pack_index {
13         const char *object_dir;
14 } opts;
15
16 int cmd_multi_pack_index(int argc, const char **argv,
17                          const char *prefix)
18 {
19         static struct option builtin_multi_pack_index_options[] = {
20                 OPT_FILENAME(0, "object-dir", &opts.object_dir,
21                   N_("object directory containing set of packfile and pack-index pairs")),
22                 OPT_END(),
23         };
24
25         git_config(git_default_config, NULL);
26
27         argc = parse_options(argc, argv, prefix,
28                              builtin_multi_pack_index_options,
29                              builtin_multi_pack_index_usage, 0);
30
31         if (!opts.object_dir)
32                 opts.object_dir = get_object_directory();
33
34         if (argc == 0)
35                 usage_with_options(builtin_multi_pack_index_usage,
36                                    builtin_multi_pack_index_options);
37
38         if (argc > 1) {
39                 die(_("too many arguments"));
40                 return 1;
41         }
42
43         if (!strcmp(argv[0], "write"))
44                 return write_midx_file(opts.object_dir);
45         if (!strcmp(argv[0], "verify"))
46                 return verify_midx_file(opts.object_dir);
47
48         die(_("unrecognized verb: %s"), argv[0]);
49 }