]>
Commit | Line | Data |
---|---|---|
03eae9af | 1 | #define USE_THE_REPOSITORY_VARIABLE |
6a257f03 | 2 | #include "builtin.h" |
0b027f6c | 3 | #include "abspath.h" |
6a257f03 | 4 | #include "config.h" |
f394e093 | 5 | #include "gettext.h" |
6a257f03 | 6 | #include "parse-options.h" |
a3407730 | 7 | #include "midx.h" |
a034e910 | 8 | #include "strbuf.h" |
d829223a | 9 | #include "trace2.h" |
68cd492a | 10 | #include "object-store.h" |
93e2ae1c | 11 | #include "replace-object.h" |
a3673f48 | 12 | #include "repository.h" |
6a257f03 | 13 | |
b25b7274 | 14 | #define BUILTIN_MIDX_WRITE_USAGE \ |
08944d1c TB |
15 | N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]" \ |
16 | "[--refs-snapshot=<path>]") | |
b25b7274 TB |
17 | |
18 | #define BUILTIN_MIDX_VERIFY_USAGE \ | |
19 | N_("git multi-pack-index [<options>] verify") | |
20 | ||
21 | #define BUILTIN_MIDX_EXPIRE_USAGE \ | |
22 | N_("git multi-pack-index [<options>] expire") | |
23 | ||
24 | #define BUILTIN_MIDX_REPACK_USAGE \ | |
25 | N_("git multi-pack-index [<options>] repack [--batch-size=<size>]") | |
26 | ||
60ca9476 TB |
27 | static char const * const builtin_multi_pack_index_write_usage[] = { |
28 | BUILTIN_MIDX_WRITE_USAGE, | |
29 | NULL | |
30 | }; | |
31 | static char const * const builtin_multi_pack_index_verify_usage[] = { | |
32 | BUILTIN_MIDX_VERIFY_USAGE, | |
33 | NULL | |
34 | }; | |
35 | static char const * const builtin_multi_pack_index_expire_usage[] = { | |
36 | BUILTIN_MIDX_EXPIRE_USAGE, | |
37 | NULL | |
38 | }; | |
39 | static char const * const builtin_multi_pack_index_repack_usage[] = { | |
40 | BUILTIN_MIDX_REPACK_USAGE, | |
41 | NULL | |
42 | }; | |
6a257f03 | 43 | static char const * const builtin_multi_pack_index_usage[] = { |
b25b7274 TB |
44 | BUILTIN_MIDX_WRITE_USAGE, |
45 | BUILTIN_MIDX_VERIFY_USAGE, | |
46 | BUILTIN_MIDX_EXPIRE_USAGE, | |
47 | BUILTIN_MIDX_REPACK_USAGE, | |
6a257f03 DS |
48 | NULL |
49 | }; | |
50 | ||
51 | static struct opts_multi_pack_index { | |
b56166ca | 52 | char *object_dir; |
9218c6a4 | 53 | const char *preferred_pack; |
14da2623 | 54 | char *refs_snapshot; |
2af890bb | 55 | unsigned long batch_size; |
f7c4d63e | 56 | unsigned flags; |
6fb22ca4 | 57 | int stdin_packs; |
6a257f03 DS |
58 | } opts; |
59 | ||
b56166ca DS |
60 | |
61 | static int parse_object_dir(const struct option *opt, const char *arg, | |
62 | int unset) | |
63 | { | |
7faba18a JK |
64 | char **value = opt->value; |
65 | free(*value); | |
b56166ca | 66 | if (unset) |
a3673f48 | 67 | *value = xstrdup(repo_get_object_directory(the_repository)); |
b56166ca | 68 | else |
7faba18a | 69 | *value = real_pathdup(arg, 1); |
b56166ca DS |
70 | return 0; |
71 | } | |
72 | ||
60ca9476 | 73 | static struct option common_opts[] = { |
b56166ca DS |
74 | OPT_CALLBACK(0, "object-dir", &opts.object_dir, |
75 | N_("directory"), | |
76 | N_("object directory containing set of packfile and pack-index pairs"), | |
77 | parse_object_dir), | |
60ca9476 TB |
78 | OPT_END(), |
79 | }; | |
80 | ||
81 | static struct option *add_common_options(struct option *prev) | |
82 | { | |
83 | return parse_options_concat(common_opts, prev); | |
84 | } | |
85 | ||
caca3c9f | 86 | static int git_multi_pack_index_write_config(const char *var, const char *value, |
a4e7e317 | 87 | const struct config_context *ctx UNUSED, |
5cf88fd8 | 88 | void *cb UNUSED) |
caca3c9f TB |
89 | { |
90 | if (!strcmp(var, "pack.writebitmaphashcache")) { | |
91 | if (git_config_bool(var, value)) | |
92 | opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE; | |
93 | else | |
94 | opts.flags &= ~MIDX_WRITE_BITMAP_HASH_CACHE; | |
95 | } | |
96 | ||
76f14b77 AC |
97 | if (!strcmp(var, "pack.writebitmaplookuptable")) { |
98 | if (git_config_bool(var, value)) | |
99 | opts.flags |= MIDX_WRITE_BITMAP_LOOKUP_TABLE; | |
100 | else | |
101 | opts.flags &= ~MIDX_WRITE_BITMAP_LOOKUP_TABLE; | |
102 | } | |
103 | ||
caca3c9f TB |
104 | /* |
105 | * We should never make a fall-back call to 'git_default_config', since | |
106 | * this was already called in 'cmd_multi_pack_index()'. | |
107 | */ | |
108 | return 0; | |
109 | } | |
110 | ||
6fb22ca4 TB |
111 | static void read_packs_from_stdin(struct string_list *to) |
112 | { | |
113 | struct strbuf buf = STRBUF_INIT; | |
114 | while (strbuf_getline(&buf, stdin) != EOF) | |
115 | string_list_append(to, buf.buf); | |
116 | string_list_sort(to); | |
117 | ||
118 | strbuf_release(&buf); | |
119 | } | |
120 | ||
bf0a6b65 | 121 | static int cmd_multi_pack_index_write(int argc, const char **argv, |
6f33d8e2 | 122 | const char *prefix, |
2fed09aa | 123 | struct repository *repo) |
60ca9476 | 124 | { |
9218c6a4 TB |
125 | struct option *options; |
126 | static struct option builtin_multi_pack_index_write_options[] = { | |
127 | OPT_STRING(0, "preferred-pack", &opts.preferred_pack, | |
128 | N_("preferred-pack"), | |
129 | N_("pack for reuse when computing a multi-pack bitmap")), | |
c528e179 TB |
130 | OPT_BIT(0, "bitmap", &opts.flags, N_("write multi-pack bitmap"), |
131 | MIDX_WRITE_BITMAP | MIDX_WRITE_REV_INDEX), | |
0394f8d0 TB |
132 | OPT_BIT(0, "progress", &opts.flags, |
133 | N_("force progress reporting"), MIDX_PROGRESS), | |
fcb2205b TB |
134 | OPT_BIT(0, "incremental", &opts.flags, |
135 | N_("write a new incremental MIDX"), MIDX_WRITE_INCREMENTAL), | |
6fb22ca4 TB |
136 | OPT_BOOL(0, "stdin-packs", &opts.stdin_packs, |
137 | N_("write multi-pack index containing only given indexes")), | |
08944d1c TB |
138 | OPT_FILENAME(0, "refs-snapshot", &opts.refs_snapshot, |
139 | N_("refs snapshot for selecting bitmap commits")), | |
9218c6a4 TB |
140 | OPT_END(), |
141 | }; | |
14da2623 | 142 | int ret; |
9218c6a4 | 143 | |
caca3c9f TB |
144 | opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE; |
145 | ||
146 | git_config(git_multi_pack_index_write_config, NULL); | |
147 | ||
9218c6a4 | 148 | options = add_common_options(builtin_multi_pack_index_write_options); |
60ca9476 | 149 | |
690eb057 TB |
150 | trace2_cmd_mode(argv[0]); |
151 | ||
0394f8d0 TB |
152 | if (isatty(2)) |
153 | opts.flags |= MIDX_PROGRESS; | |
ecd2d3ef | 154 | argc = parse_options(argc, argv, prefix, |
60ca9476 | 155 | options, builtin_multi_pack_index_write_usage, |
cc74afb8 | 156 | 0); |
60ca9476 TB |
157 | if (argc) |
158 | usage_with_options(builtin_multi_pack_index_write_usage, | |
159 | options); | |
160 | ||
9218c6a4 TB |
161 | FREE_AND_NULL(options); |
162 | ||
6fb22ca4 TB |
163 | if (opts.stdin_packs) { |
164 | struct string_list packs = STRING_LIST_INIT_DUP; | |
6fb22ca4 TB |
165 | |
166 | read_packs_from_stdin(&packs); | |
167 | ||
2fed09aa | 168 | ret = write_midx_file_only(repo, opts.object_dir, &packs, |
08944d1c TB |
169 | opts.preferred_pack, |
170 | opts.refs_snapshot, opts.flags); | |
6fb22ca4 TB |
171 | |
172 | string_list_clear(&packs, 0); | |
14da2623 | 173 | free(opts.refs_snapshot); |
6fb22ca4 TB |
174 | |
175 | return ret; | |
176 | ||
177 | } | |
14da2623 | 178 | |
2fed09aa | 179 | ret = write_midx_file(repo, opts.object_dir, opts.preferred_pack, |
14da2623 PS |
180 | opts.refs_snapshot, opts.flags); |
181 | ||
182 | free(opts.refs_snapshot); | |
183 | return ret; | |
60ca9476 TB |
184 | } |
185 | ||
bf0a6b65 | 186 | static int cmd_multi_pack_index_verify(int argc, const char **argv, |
6f33d8e2 KN |
187 | const char *prefix, |
188 | struct repository *repo UNUSED) | |
60ca9476 | 189 | { |
0394f8d0 TB |
190 | struct option *options; |
191 | static struct option builtin_multi_pack_index_verify_options[] = { | |
192 | OPT_BIT(0, "progress", &opts.flags, | |
193 | N_("force progress reporting"), MIDX_PROGRESS), | |
194 | OPT_END(), | |
195 | }; | |
196 | options = add_common_options(builtin_multi_pack_index_verify_options); | |
60ca9476 | 197 | |
690eb057 TB |
198 | trace2_cmd_mode(argv[0]); |
199 | ||
0394f8d0 TB |
200 | if (isatty(2)) |
201 | opts.flags |= MIDX_PROGRESS; | |
ecd2d3ef | 202 | argc = parse_options(argc, argv, prefix, |
60ca9476 | 203 | options, builtin_multi_pack_index_verify_usage, |
cc74afb8 | 204 | 0); |
60ca9476 TB |
205 | if (argc) |
206 | usage_with_options(builtin_multi_pack_index_verify_usage, | |
207 | options); | |
208 | ||
ee4a1d63 TB |
209 | FREE_AND_NULL(options); |
210 | ||
60ca9476 TB |
211 | return verify_midx_file(the_repository, opts.object_dir, opts.flags); |
212 | } | |
213 | ||
bf0a6b65 | 214 | static int cmd_multi_pack_index_expire(int argc, const char **argv, |
6f33d8e2 KN |
215 | const char *prefix, |
216 | struct repository *repo UNUSED) | |
60ca9476 | 217 | { |
0394f8d0 TB |
218 | struct option *options; |
219 | static struct option builtin_multi_pack_index_expire_options[] = { | |
220 | OPT_BIT(0, "progress", &opts.flags, | |
221 | N_("force progress reporting"), MIDX_PROGRESS), | |
222 | OPT_END(), | |
223 | }; | |
224 | options = add_common_options(builtin_multi_pack_index_expire_options); | |
60ca9476 | 225 | |
690eb057 TB |
226 | trace2_cmd_mode(argv[0]); |
227 | ||
0394f8d0 TB |
228 | if (isatty(2)) |
229 | opts.flags |= MIDX_PROGRESS; | |
ecd2d3ef | 230 | argc = parse_options(argc, argv, prefix, |
60ca9476 | 231 | options, builtin_multi_pack_index_expire_usage, |
cc74afb8 | 232 | 0); |
60ca9476 TB |
233 | if (argc) |
234 | usage_with_options(builtin_multi_pack_index_expire_usage, | |
235 | options); | |
236 | ||
ee4a1d63 TB |
237 | FREE_AND_NULL(options); |
238 | ||
60ca9476 TB |
239 | return expire_midx_packs(the_repository, opts.object_dir, opts.flags); |
240 | } | |
241 | ||
bf0a6b65 | 242 | static int cmd_multi_pack_index_repack(int argc, const char **argv, |
6f33d8e2 KN |
243 | const char *prefix, |
244 | struct repository *repo UNUSED) | |
6a257f03 | 245 | { |
60ca9476 TB |
246 | struct option *options; |
247 | static struct option builtin_multi_pack_index_repack_options[] = { | |
785c17df | 248 | OPT_UNSIGNED(0, "batch-size", &opts.batch_size, |
2af890bb | 249 | N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")), |
0394f8d0 TB |
250 | OPT_BIT(0, "progress", &opts.flags, |
251 | N_("force progress reporting"), MIDX_PROGRESS), | |
6a257f03 DS |
252 | OPT_END(), |
253 | }; | |
254 | ||
60ca9476 TB |
255 | options = add_common_options(builtin_multi_pack_index_repack_options); |
256 | ||
690eb057 TB |
257 | trace2_cmd_mode(argv[0]); |
258 | ||
0394f8d0 TB |
259 | if (isatty(2)) |
260 | opts.flags |= MIDX_PROGRESS; | |
ecd2d3ef | 261 | argc = parse_options(argc, argv, prefix, |
60ca9476 TB |
262 | options, |
263 | builtin_multi_pack_index_repack_usage, | |
cc74afb8 | 264 | 0); |
60ca9476 TB |
265 | if (argc) |
266 | usage_with_options(builtin_multi_pack_index_repack_usage, | |
267 | options); | |
268 | ||
269 | FREE_AND_NULL(options); | |
270 | ||
271 | return midx_repack(the_repository, opts.object_dir, | |
272 | (size_t)opts.batch_size, opts.flags); | |
273 | } | |
274 | ||
9b1cb507 JC |
275 | int cmd_multi_pack_index(int argc, |
276 | const char **argv, | |
277 | const char *prefix, | |
6f33d8e2 | 278 | struct repository *repo) |
60ca9476 | 279 | { |
b56166ca | 280 | int res; |
bf0a6b65 SG |
281 | parse_opt_subcommand_fn *fn = NULL; |
282 | struct option builtin_multi_pack_index_options[] = { | |
283 | OPT_SUBCOMMAND("repack", &fn, cmd_multi_pack_index_repack), | |
284 | OPT_SUBCOMMAND("write", &fn, cmd_multi_pack_index_write), | |
285 | OPT_SUBCOMMAND("verify", &fn, cmd_multi_pack_index_verify), | |
286 | OPT_SUBCOMMAND("expire", &fn, cmd_multi_pack_index_expire), | |
287 | OPT_END(), | |
288 | }; | |
289 | struct option *options = parse_options_concat(builtin_multi_pack_index_options, common_opts); | |
60ca9476 | 290 | |
93e2ae1c XX |
291 | disable_replace_refs(); |
292 | ||
6a257f03 DS |
293 | git_config(git_default_config, NULL); |
294 | ||
b56166ca DS |
295 | if (the_repository && |
296 | the_repository->objects && | |
297 | the_repository->objects->odb) | |
298 | opts.object_dir = xstrdup(the_repository->objects->odb->path); | |
299 | ||
bf0a6b65 SG |
300 | argc = parse_options(argc, argv, prefix, options, |
301 | builtin_multi_pack_index_usage, 0); | |
302 | FREE_AND_NULL(options); | |
303 | ||
6f33d8e2 | 304 | res = fn(argc, argv, prefix, repo); |
b56166ca DS |
305 | |
306 | free(opts.object_dir); | |
307 | return res; | |
6a257f03 | 308 | } |