|
4 | 4 | #include "parse-options.h" |
5 | 5 | #include "midx.h" |
6 | 6 | #include "trace2.h" |
| 7 | +#include "object-store.h" |
7 | 8 |
|
| 9 | +#define BUILTIN_MIDX_WRITE_USAGE \ |
| 10 | + N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]") |
| 11 | + |
| 12 | +#define BUILTIN_MIDX_VERIFY_USAGE \ |
| 13 | + N_("git multi-pack-index [<options>] verify") |
| 14 | + |
| 15 | +#define BUILTIN_MIDX_EXPIRE_USAGE \ |
| 16 | + N_("git multi-pack-index [<options>] expire") |
| 17 | + |
| 18 | +#define BUILTIN_MIDX_REPACK_USAGE \ |
| 19 | + N_("git multi-pack-index [<options>] repack [--batch-size=<size>]") |
| 20 | + |
| 21 | +static char const * const builtin_multi_pack_index_write_usage[] = { |
| 22 | + BUILTIN_MIDX_WRITE_USAGE, |
| 23 | + NULL |
| 24 | +}; |
| 25 | +static char const * const builtin_multi_pack_index_verify_usage[] = { |
| 26 | + BUILTIN_MIDX_VERIFY_USAGE, |
| 27 | + NULL |
| 28 | +}; |
| 29 | +static char const * const builtin_multi_pack_index_expire_usage[] = { |
| 30 | + BUILTIN_MIDX_EXPIRE_USAGE, |
| 31 | + NULL |
| 32 | +}; |
| 33 | +static char const * const builtin_multi_pack_index_repack_usage[] = { |
| 34 | + BUILTIN_MIDX_REPACK_USAGE, |
| 35 | + NULL |
| 36 | +}; |
8 | 37 | static char const * const builtin_multi_pack_index_usage[] = { |
9 | | - N_("git multi-pack-index [<options>] (write|verify|expire|repack --batch-size=<size>)"), |
| 38 | + BUILTIN_MIDX_WRITE_USAGE, |
| 39 | + BUILTIN_MIDX_VERIFY_USAGE, |
| 40 | + BUILTIN_MIDX_EXPIRE_USAGE, |
| 41 | + BUILTIN_MIDX_REPACK_USAGE, |
10 | 42 | NULL |
11 | 43 | }; |
12 | 44 |
|
13 | 45 | static struct opts_multi_pack_index { |
14 | 46 | const char *object_dir; |
| 47 | + const char *preferred_pack; |
15 | 48 | unsigned long batch_size; |
16 | | - int progress; |
| 49 | + unsigned flags; |
17 | 50 | } opts; |
18 | 51 |
|
19 | | -int cmd_multi_pack_index(int argc, const char **argv, |
20 | | - const char *prefix) |
| 52 | +static struct option common_opts[] = { |
| 53 | + OPT_FILENAME(0, "object-dir", &opts.object_dir, |
| 54 | + N_("object directory containing set of packfile and pack-index pairs")), |
| 55 | + OPT_BIT(0, "progress", &opts.flags, N_("force progress reporting"), MIDX_PROGRESS), |
| 56 | + OPT_END(), |
| 57 | +}; |
| 58 | + |
| 59 | +static struct option *add_common_options(struct option *prev) |
21 | 60 | { |
22 | | - unsigned flags = 0; |
| 61 | + return parse_options_concat(common_opts, prev); |
| 62 | +} |
| 63 | + |
| 64 | +static int cmd_multi_pack_index_write(int argc, const char **argv) |
| 65 | +{ |
| 66 | + struct option *options; |
| 67 | + static struct option builtin_multi_pack_index_write_options[] = { |
| 68 | + OPT_STRING(0, "preferred-pack", &opts.preferred_pack, |
| 69 | + N_("preferred-pack"), |
| 70 | + N_("pack for reuse when computing a multi-pack bitmap")), |
| 71 | + OPT_END(), |
| 72 | + }; |
| 73 | + |
| 74 | + options = add_common_options(builtin_multi_pack_index_write_options); |
| 75 | + |
| 76 | + trace2_cmd_mode(argv[0]); |
23 | 77 |
|
24 | | - static struct option builtin_multi_pack_index_options[] = { |
25 | | - OPT_FILENAME(0, "object-dir", &opts.object_dir, |
26 | | - N_("object directory containing set of packfile and pack-index pairs")), |
27 | | - OPT_BOOL(0, "progress", &opts.progress, N_("force progress reporting")), |
| 78 | + argc = parse_options(argc, argv, NULL, |
| 79 | + options, builtin_multi_pack_index_write_usage, |
| 80 | + PARSE_OPT_KEEP_UNKNOWN); |
| 81 | + if (argc) |
| 82 | + usage_with_options(builtin_multi_pack_index_write_usage, |
| 83 | + options); |
| 84 | + |
| 85 | + FREE_AND_NULL(options); |
| 86 | + |
| 87 | + return write_midx_file(opts.object_dir, opts.preferred_pack, |
| 88 | + opts.flags); |
| 89 | +} |
| 90 | + |
| 91 | +static int cmd_multi_pack_index_verify(int argc, const char **argv) |
| 92 | +{ |
| 93 | + struct option *options = common_opts; |
| 94 | + |
| 95 | + trace2_cmd_mode(argv[0]); |
| 96 | + |
| 97 | + argc = parse_options(argc, argv, NULL, |
| 98 | + options, builtin_multi_pack_index_verify_usage, |
| 99 | + PARSE_OPT_KEEP_UNKNOWN); |
| 100 | + if (argc) |
| 101 | + usage_with_options(builtin_multi_pack_index_verify_usage, |
| 102 | + options); |
| 103 | + |
| 104 | + return verify_midx_file(the_repository, opts.object_dir, opts.flags); |
| 105 | +} |
| 106 | + |
| 107 | +static int cmd_multi_pack_index_expire(int argc, const char **argv) |
| 108 | +{ |
| 109 | + struct option *options = common_opts; |
| 110 | + |
| 111 | + trace2_cmd_mode(argv[0]); |
| 112 | + |
| 113 | + argc = parse_options(argc, argv, NULL, |
| 114 | + options, builtin_multi_pack_index_expire_usage, |
| 115 | + PARSE_OPT_KEEP_UNKNOWN); |
| 116 | + if (argc) |
| 117 | + usage_with_options(builtin_multi_pack_index_expire_usage, |
| 118 | + options); |
| 119 | + |
| 120 | + return expire_midx_packs(the_repository, opts.object_dir, opts.flags); |
| 121 | +} |
| 122 | + |
| 123 | +static int cmd_multi_pack_index_repack(int argc, const char **argv) |
| 124 | +{ |
| 125 | + struct option *options; |
| 126 | + static struct option builtin_multi_pack_index_repack_options[] = { |
28 | 127 | OPT_MAGNITUDE(0, "batch-size", &opts.batch_size, |
29 | 128 | N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")), |
30 | 129 | OPT_END(), |
31 | 130 | }; |
32 | 131 |
|
| 132 | + options = add_common_options(builtin_multi_pack_index_repack_options); |
| 133 | + |
| 134 | + trace2_cmd_mode(argv[0]); |
| 135 | + |
| 136 | + argc = parse_options(argc, argv, NULL, |
| 137 | + options, |
| 138 | + builtin_multi_pack_index_repack_usage, |
| 139 | + PARSE_OPT_KEEP_UNKNOWN); |
| 140 | + if (argc) |
| 141 | + usage_with_options(builtin_multi_pack_index_repack_usage, |
| 142 | + options); |
| 143 | + |
| 144 | + FREE_AND_NULL(options); |
| 145 | + |
| 146 | + return midx_repack(the_repository, opts.object_dir, |
| 147 | + (size_t)opts.batch_size, opts.flags); |
| 148 | +} |
| 149 | + |
| 150 | +int cmd_multi_pack_index(int argc, const char **argv, |
| 151 | + const char *prefix) |
| 152 | +{ |
| 153 | + struct option *builtin_multi_pack_index_options = common_opts; |
| 154 | + |
33 | 155 | git_config(git_default_config, NULL); |
34 | 156 |
|
35 | | - opts.progress = isatty(2); |
| 157 | + if (isatty(2)) |
| 158 | + opts.flags |= MIDX_PROGRESS; |
36 | 159 | argc = parse_options(argc, argv, prefix, |
37 | 160 | builtin_multi_pack_index_options, |
38 | | - builtin_multi_pack_index_usage, 0); |
| 161 | + builtin_multi_pack_index_usage, |
| 162 | + PARSE_OPT_STOP_AT_NON_OPTION); |
39 | 163 |
|
40 | 164 | if (!opts.object_dir) |
41 | 165 | opts.object_dir = get_object_directory(); |
42 | | - if (opts.progress) |
43 | | - flags |= MIDX_PROGRESS; |
44 | 166 |
|
45 | 167 | if (argc == 0) |
| 168 | + goto usage; |
| 169 | + |
| 170 | + if (!strcmp(argv[0], "repack")) |
| 171 | + return cmd_multi_pack_index_repack(argc, argv); |
| 172 | + else if (!strcmp(argv[0], "write")) |
| 173 | + return cmd_multi_pack_index_write(argc, argv); |
| 174 | + else if (!strcmp(argv[0], "verify")) |
| 175 | + return cmd_multi_pack_index_verify(argc, argv); |
| 176 | + else if (!strcmp(argv[0], "expire")) |
| 177 | + return cmd_multi_pack_index_expire(argc, argv); |
| 178 | + else { |
| 179 | +usage: |
| 180 | + error(_("unrecognized subcommand: %s"), argv[0]); |
46 | 181 | usage_with_options(builtin_multi_pack_index_usage, |
47 | 182 | builtin_multi_pack_index_options); |
48 | | - |
49 | | - if (argc > 1) { |
50 | | - die(_("too many arguments")); |
51 | | - return 1; |
52 | 183 | } |
53 | | - |
54 | | - trace2_cmd_mode(argv[0]); |
55 | | - |
56 | | - if (!strcmp(argv[0], "repack")) |
57 | | - return midx_repack(the_repository, opts.object_dir, |
58 | | - (size_t)opts.batch_size, flags); |
59 | | - if (opts.batch_size) |
60 | | - die(_("--batch-size option is only for 'repack' subcommand")); |
61 | | - |
62 | | - if (!strcmp(argv[0], "write")) |
63 | | - return write_midx_file(opts.object_dir, flags); |
64 | | - if (!strcmp(argv[0], "verify")) |
65 | | - return verify_midx_file(the_repository, opts.object_dir, flags); |
66 | | - if (!strcmp(argv[0], "expire")) |
67 | | - return expire_midx_packs(the_repository, opts.object_dir, flags); |
68 | | - |
69 | | - die(_("unrecognized subcommand: %s"), argv[0]); |
70 | 184 | } |
0 commit comments