Raw
1 #define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "builtin.h"
4 #include "config.h"
5 #include "environment.h"
6 #include "parse-options.h"
7 #include "path.h"
8 #include "run-command.h"
9 #include "server-info.h"
10 #include "string-list.h"
11 #include "midx.h"
12 #include "packfile.h"
13 #include "prune-packed.h"
14 #include "promisor-remote.h"
15 #include "repack.h"
16 #include "shallow.h"
17
18 #define ALL_INTO_ONE 1
19 #define LOOSEN_UNREACHABLE 2
20 #define PACK_CRUFT 4
21
22 #define DELETE_PACK 1
23 #define RETAIN_PACK 2
24
25 static int pack_everything;
26 static int write_bitmaps = -1;
27 static int use_delta_islands;
28 static int run_update_server_info = 1;
29 static char *packdir, *packtmp_name, *packtmp;
30 static int midx_must_contain_cruft = 1;
31
32 static const char *const git_repack_usage[] = {
33 N_("git repack [-a] [-A] [-d] [-f] [-F] [-l] [-n] [-q] [-b] [-m]\n"
34 "[--window=<n>] [--depth=<n>] [--threads=<n>] [--keep-pack=<pack-name>]\n"
35 "[--write-midx[=<mode>]] [--name-hash-version=<n>] [--path-walk]"),
36 NULL
37 };
38
39 static const char incremental_bitmap_conflict_error[] = N_(
40 "Incremental repacks are incompatible with bitmap indexes. Use\n"
41 "--no-write-bitmap-index or disable the pack.writeBitmaps configuration."
42 );
43
44 #define DEFAULT_MIDX_SPLIT_FACTOR 2
45 #define DEFAULT_MIDX_NEW_LAYER_THRESHOLD 8
46
47 struct repack_config_ctx {
48 struct pack_objects_args *po_args;
49 struct pack_objects_args *cruft_po_args;
50 int midx_split_factor;
51 int midx_new_layer_threshold;
52 };
53
54 static int repack_config(const char *var, const char *value,
55 const struct config_context *ctx, void *cb)
56 {
57 struct repack_config_ctx *repack_ctx = cb;
58 struct pack_objects_args *po_args = repack_ctx->po_args;
59 struct pack_objects_args *cruft_po_args = repack_ctx->cruft_po_args;
60 if (!strcmp(var, "repack.usedeltabaseoffset")) {
61 po_args->delta_base_offset = git_config_bool(var, value);
62 return 0;
63 }
64 if (!strcmp(var, "repack.packkeptobjects")) {
65 po_args->pack_kept_objects = git_config_bool(var, value);
66 return 0;
67 }
68 if (!strcmp(var, "repack.writebitmaps") ||
69 !strcmp(var, "pack.writebitmaps")) {
70 write_bitmaps = git_config_bool(var, value);
71 return 0;
72 }
73 if (!strcmp(var, "repack.usedeltaislands")) {
74 use_delta_islands = git_config_bool(var, value);
75 return 0;
76 }
77 if (strcmp(var, "repack.updateserverinfo") == 0) {
78 run_update_server_info = git_config_bool(var, value);
79 return 0;
80 }
81 if (!strcmp(var, "repack.cruftwindow")) {
82 free(cruft_po_args->window);
83 return git_config_string(&cruft_po_args->window, var, value);
84 }
85 if (!strcmp(var, "repack.cruftwindowmemory")) {
86 free(cruft_po_args->window_memory);
87 return git_config_string(&cruft_po_args->window_memory, var, value);
88 }
89 if (!strcmp(var, "repack.cruftdepth")) {
90 free(cruft_po_args->depth);
91 return git_config_string(&cruft_po_args->depth, var, value);
92 }
93 if (!strcmp(var, "repack.cruftthreads")) {
94 free(cruft_po_args->threads);
95 return git_config_string(&cruft_po_args->threads, var, value);
96 }
97 if (!strcmp(var, "repack.midxmustcontaincruft")) {
98 midx_must_contain_cruft = git_config_bool(var, value);
99 return 0;
100 }
101 if (!strcmp(var, "repack.midxsplitfactor")) {
102 repack_ctx->midx_split_factor = git_config_int(var, value,
103 ctx->kvi);
104 return 0;
105 }
106 if (!strcmp(var, "repack.midxnewlayerthreshold")) {
107 repack_ctx->midx_new_layer_threshold = git_config_int(var, value,
108 ctx->kvi);
109 return 0;
110 }
111 return git_default_config(var, value, ctx, cb);
112 }
113
114 static int option_parse_write_midx(const struct option *opt, const char *arg,
115 int unset)
116 {
117 enum repack_write_midx_mode *cfg = opt->value;
118
119 if (unset) {
120 *cfg = REPACK_WRITE_MIDX_NONE;
121 return 0;
122 }
123
124 if (!arg || !*arg)
125 *cfg = REPACK_WRITE_MIDX_DEFAULT;
126 else if (!strcmp(arg, "incremental"))
127 *cfg = REPACK_WRITE_MIDX_INCREMENTAL;
128 else
129 return error(_("unknown value for %s: %s"), opt->long_name, arg);
130
131 return 0;
132 }
133
134 int cmd_repack(int argc,
135 const char **argv,
136 const char *prefix,
137 struct repository *repo)
138 {
139 struct child_process cmd = CHILD_PROCESS_INIT;
140 struct string_list_item *item;
141 struct string_list names = STRING_LIST_INIT_DUP;
142 struct existing_packs existing = EXISTING_PACKS_INIT;
143 struct pack_geometry geometry = { 0 };
144 struct tempfile *refs_snapshot = NULL;
145 int i, ret;
146 int show_progress;
147
148 /* variables to be filled by option parsing */
149 struct repack_config_ctx config_ctx;
150 int delete_redundant = 0;
151 const char *unpack_unreachable = NULL;
152 int keep_unreachable = 0;
153 struct string_list keep_pack_list = STRING_LIST_INIT_NODUP;
154 struct pack_objects_args po_args = PACK_OBJECTS_ARGS_INIT;
155 struct pack_objects_args cruft_po_args = PACK_OBJECTS_ARGS_INIT;
156 enum repack_write_midx_mode write_midx = REPACK_WRITE_MIDX_NONE;
157 const char *cruft_expiration = NULL;
158 const char *expire_to = NULL;
159 const char *filter_to = NULL;
160 const char *opt_window = NULL;
161 const char *opt_window_memory = NULL;
162 const char *opt_depth = NULL;
163 const char *opt_threads = NULL;
164 unsigned long combine_cruft_below_size = 0ul;
165
166 struct option builtin_repack_options[] = {
167 OPT_BIT('a', NULL, &pack_everything,
168 N_("pack everything in a single pack"), ALL_INTO_ONE),
169 OPT_BIT('A', NULL, &pack_everything,
170 N_("same as -a, and turn unreachable objects loose"),
171 LOOSEN_UNREACHABLE | ALL_INTO_ONE),
172 OPT_BIT(0, "cruft", &pack_everything,
173 N_("same as -a, pack unreachable cruft objects separately"),
174 PACK_CRUFT),
175 OPT_STRING(0, "cruft-expiration", &cruft_expiration, N_("approxidate"),
176 N_("with --cruft, expire objects older than this")),
177 OPT_UNSIGNED(0, "combine-cruft-below-size",
178 &combine_cruft_below_size,
179 N_("with --cruft, only repack cruft packs smaller than this")),
180 OPT_UNSIGNED(0, "max-cruft-size", &cruft_po_args.max_pack_size,
181 N_("with --cruft, limit the size of new cruft packs")),
182 OPT_BOOL('d', NULL, &delete_redundant,
183 N_("remove redundant packs, and run git-prune-packed")),
184 OPT_BOOL('f', NULL, &po_args.no_reuse_delta,
185 N_("pass --no-reuse-delta to git-pack-objects")),
186 OPT_BOOL('F', NULL, &po_args.no_reuse_object,
187 N_("pass --no-reuse-object to git-pack-objects")),
188 OPT_INTEGER(0, "name-hash-version", &po_args.name_hash_version,
189 N_("specify the name hash version to use for grouping similar objects by path")),
190 OPT_BOOL(0, "path-walk", &po_args.path_walk,
191 N_("pass --path-walk to git-pack-objects")),
192 OPT_NEGBIT('n', NULL, &run_update_server_info,
193 N_("do not run git-update-server-info"), 1),
194 OPT__QUIET(&po_args.quiet, N_("be quiet")),
195 OPT_BOOL('l', "local", &po_args.local,
196 N_("pass --local to git-pack-objects")),
197 OPT_BOOL('b', "write-bitmap-index", &write_bitmaps,
198 N_("write bitmap index")),
199 OPT_BOOL('i', "delta-islands", &use_delta_islands,
200 N_("pass --delta-islands to git-pack-objects")),
201 OPT_STRING(0, "unpack-unreachable", &unpack_unreachable, N_("approxidate"),
202 N_("with -A, do not loosen objects older than this")),
203 OPT_BOOL('k', "keep-unreachable", &keep_unreachable,
204 N_("with -a, repack unreachable objects")),
205 OPT_STRING(0, "window", &opt_window, N_("n"),
206 N_("size of the window used for delta compression")),
207 OPT_STRING(0, "window-memory", &opt_window_memory, N_("bytes"),
208 N_("same as the above, but limit memory size instead of entries count")),
209 OPT_STRING(0, "depth", &opt_depth, N_("n"),
210 N_("limits the maximum delta depth")),
211 OPT_STRING(0, "threads", &opt_threads, N_("n"),
212 N_("limits the maximum number of threads")),
213 OPT_UNSIGNED(0, "max-pack-size", &po_args.max_pack_size,
214 N_("maximum size of each packfile")),
215 OPT_PARSE_LIST_OBJECTS_FILTER(&po_args.filter_options),
216 OPT_BOOL(0, "pack-kept-objects", &po_args.pack_kept_objects,
217 N_("repack objects in packs marked with .keep")),
218 OPT_STRING_LIST(0, "keep-pack", &keep_pack_list, N_("name"),
219 N_("do not repack this pack")),
220 OPT_INTEGER('g', "geometric", &geometry.split_factor,
221 N_("find a geometric progression with factor <N>")),
222 OPT_CALLBACK_F(0, "write-midx", &write_midx,
223 N_("mode"),
224 N_("write a multi-pack index of the resulting packs"),
225 PARSE_OPT_OPTARG, option_parse_write_midx),
226 OPT_SET_INT_F('m', NULL, &write_midx,
227 N_("write a multi-pack index of the resulting packs"),
228 REPACK_WRITE_MIDX_DEFAULT,
229 PARSE_OPT_HIDDEN),
230 OPT_STRING(0, "expire-to", &expire_to, N_("dir"),
231 N_("pack prefix to store a pack containing pruned objects")),
232 OPT_STRING(0, "filter-to", &filter_to, N_("dir"),
233 N_("pack prefix to store a pack containing filtered out objects")),
234 OPT_END()
235 };
236
237 list_objects_filter_init(&po_args.filter_options);
238
239 memset(&config_ctx, 0, sizeof(config_ctx));
240 config_ctx.po_args = &po_args;
241 config_ctx.cruft_po_args = &cruft_po_args;
242 config_ctx.midx_split_factor = DEFAULT_MIDX_SPLIT_FACTOR;
243 config_ctx.midx_new_layer_threshold = DEFAULT_MIDX_NEW_LAYER_THRESHOLD;
244
245 repo_config(repo, repack_config, &config_ctx);
246
247 argc = parse_options(argc, argv, prefix, builtin_repack_options,
248 git_repack_usage, 0);
249
250 po_args.window = xstrdup_or_null(opt_window);
251 po_args.window_memory = xstrdup_or_null(opt_window_memory);
252 po_args.depth = xstrdup_or_null(opt_depth);
253 po_args.threads = xstrdup_or_null(opt_threads);
254
255 if (delete_redundant && repo->repository_format_precious_objects)
256 die(_("cannot delete packs in a precious-objects repo"));
257
258 die_for_incompatible_opt3(unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE), "-A",
259 keep_unreachable, "-k/--keep-unreachable",
260 pack_everything & PACK_CRUFT, "--cruft");
261
262 if (pack_everything & PACK_CRUFT)
263 pack_everything |= ALL_INTO_ONE;
264
265 if (write_bitmaps < 0) {
266 if (write_midx == REPACK_WRITE_MIDX_NONE &&
267 (!(pack_everything & ALL_INTO_ONE) || !is_bare_repository(repo)))
268 write_bitmaps = 0;
269 }
270 if (po_args.pack_kept_objects < 0)
271 po_args.pack_kept_objects = write_bitmaps > 0 &&
272 write_midx == REPACK_WRITE_MIDX_NONE;
273
274 if (write_bitmaps && !(pack_everything & ALL_INTO_ONE) &&
275 write_midx == REPACK_WRITE_MIDX_NONE)
276 die(_(incremental_bitmap_conflict_error));
277
278 if (write_bitmaps && po_args.local &&
279 odb_has_alternates(repo->objects)) {
280 /*
281 * When asked to do a local repack, but we have
282 * packfiles that are inherited from an alternate, then
283 * we cannot guarantee that the multi-pack-index would
284 * have full coverage of all objects. We thus disable
285 * writing bitmaps in that case.
286 */
287 warning(_("disabling bitmap writing, as some objects are not being packed"));
288 write_bitmaps = 0;
289 }
290
291 if (config_ctx.midx_split_factor < 2)
292 die(_("invalid value for %s: %d"), "--midx-split-factor",
293 config_ctx.midx_split_factor);
294 if (config_ctx.midx_new_layer_threshold < 1)
295 die(_("invalid value for %s: %d"), "--midx-new-layer-threshold",
296 config_ctx.midx_new_layer_threshold);
297
298 if (write_midx != REPACK_WRITE_MIDX_NONE && write_bitmaps) {
299 struct strbuf path = STRBUF_INIT;
300
301 strbuf_addf(&path, "%s/%s_XXXXXX",
302 repo_get_object_directory(repo),
303 "bitmap-ref-tips");
304
305 refs_snapshot = xmks_tempfile(path.buf);
306 midx_snapshot_refs(repo, refs_snapshot);
307
308 strbuf_release(&path);
309 }
310
311 packdir = mkpathdup("%s/pack", repo_get_object_directory(repo));
312 packtmp_name = xstrfmt(".tmp-%d-pack", (int)getpid());
313 packtmp = mkpathdup("%s/%s", packdir, packtmp_name);
314
315 existing.repo = repo;
316 existing_packs_collect(&existing, &keep_pack_list);
317
318 if (geometry.split_factor) {
319 if (pack_everything)
320 die(_("options '%s' and '%s' cannot be used together"), "--geometric", "-A/-a");
321 if (write_midx == REPACK_WRITE_MIDX_INCREMENTAL) {
322 geometry.midx_layer_threshold = config_ctx.midx_new_layer_threshold;
323 geometry.midx_layer_threshold_set = true;
324 }
325 pack_geometry_init(&geometry, &existing, &po_args);
326 pack_geometry_split(&geometry);
327 }
328
329 prepare_pack_objects(&cmd, &po_args, packtmp);
330
331 show_progress = !po_args.quiet && isatty(2);
332
333 strvec_push(&cmd.args, "--keep-true-parents");
334 for (i = 0; i < keep_pack_list.nr; i++)
335 strvec_pushf(&cmd.args, "--keep-pack=%s",
336 keep_pack_list.items[i].string);
337 strvec_push(&cmd.args, "--non-empty");
338 if (!geometry.split_factor) {
339 /*
340 * We need to grab all reachable objects, including those that
341 * are reachable from reflogs and the index.
342 *
343 * When repacking into a geometric progression of packs,
344 * however, we ask 'git pack-objects --stdin-packs', and it is
345 * not about packing objects based on reachability but about
346 * repacking all the objects in specified packs and loose ones
347 * (indeed, --stdin-packs is incompatible with these options).
348 */
349 strvec_push(&cmd.args, "--all");
350 strvec_push(&cmd.args, "--reflog");
351 strvec_push(&cmd.args, "--indexed-objects");
352 }
353 if (repo_has_promisor_remote(repo))
354 strvec_push(&cmd.args, "--exclude-promisor-objects");
355 if (write_midx == REPACK_WRITE_MIDX_NONE) {
356 if (write_bitmaps > 0)
357 strvec_push(&cmd.args, "--write-bitmap-index");
358 else if (write_bitmaps < 0)
359 strvec_push(&cmd.args, "--write-bitmap-index-quiet");
360 }
361 if (use_delta_islands)
362 strvec_push(&cmd.args, "--delta-islands");
363
364 if (pack_everything & ALL_INTO_ONE) {
365 repack_promisor_objects(repo, &po_args, &names, packtmp);
366
367 if (existing_packs_has_non_kept(&existing) &&
368 delete_redundant &&
369 !(pack_everything & PACK_CRUFT)) {
370 for_each_string_list_item(item, &names) {
371 strvec_pushf(&cmd.args, "--keep-pack=%s-%s.pack",
372 packtmp_name, item->string);
373 }
374 if (unpack_unreachable) {
375 strvec_pushf(&cmd.args,
376 "--unpack-unreachable=%s",
377 unpack_unreachable);
378 } else if (pack_everything & LOOSEN_UNREACHABLE) {
379 strvec_push(&cmd.args,
380 "--unpack-unreachable");
381 } else if (keep_unreachable) {
382 strvec_push(&cmd.args, "--keep-unreachable");
383 }
384 }
385
386 if (keep_unreachable && delete_redundant &&
387 !(pack_everything & PACK_CRUFT))
388 strvec_push(&cmd.args, "--pack-loose-unreachable");
389 } else if (geometry.split_factor) {
390 pack_geometry_repack_promisors(repo, &po_args, &geometry,
391 &names, packtmp);
392
393 if (midx_must_contain_cruft)
394 strvec_push(&cmd.args, "--stdin-packs");
395 else
396 strvec_push(&cmd.args, "--stdin-packs=follow");
397 strvec_push(&cmd.args, "--unpacked");
398 } else {
399 strvec_push(&cmd.args, "--unpacked");
400 strvec_push(&cmd.args, "--incremental");
401 }
402
403 if (po_args.filter_options.choice)
404 strvec_pushf(&cmd.args, "--filter=%s",
405 expand_list_objects_filter_spec(&po_args.filter_options));
406 else if (filter_to)
407 die(_("option '%s' can only be used along with '%s'"), "--filter-to", "--filter");
408
409 if (geometry.split_factor)
410 cmd.in = -1;
411 else
412 cmd.no_stdin = 1;
413
414 ret = start_command(&cmd);
415 if (ret)
416 goto cleanup;
417
418 if (geometry.split_factor) {
419 FILE *in = xfdopen(cmd.in, "w");
420 /*
421 * The resulting pack should contain all objects in packs that
422 * are going to be rolled up, but exclude objects in packs which
423 * are being left alone.
424 */
425 for (i = 0; i < geometry.split; i++)
426 fprintf(in, "%s\n", pack_basename(geometry.pack[i]));
427 for (i = geometry.split; i < geometry.pack_nr; i++) {
428 const char *basename = pack_basename(geometry.pack[i]);
429 char marker = '^';
430
431 if (!midx_must_contain_cruft &&
432 !string_list_has_string(&existing.midx_packs,
433 basename)) {
434 /*
435 * Assume non-MIDX'd packs are not
436 * necessarily closed under
437 * reachability.
438 */
439 marker = '!';
440 }
441
442 fprintf(in, "%c%s\n", marker, basename);
443 }
444 fclose(in);
445 }
446
447 {
448 struct write_pack_opts opts = {
449 .packdir = packdir,
450 .destination = packdir,
451 .packtmp = packtmp,
452 };
453 ret = finish_pack_objects_cmd(repo->hash_algo, &opts, &cmd,
454 &names);
455 if (ret)
456 goto cleanup;
457 }
458
459 if (!names.nr) {
460 struct odb_source_files *files = odb_source_files_downcast(existing.source);
461
462 if (!po_args.quiet)
463 printf_ln(_("Nothing new to pack."));
464 /*
465 * If we didn't write any new packs, the non-cruft packs
466 * may refer to once-unreachable objects in the cruft
467 * pack(s).
468 *
469 * If there isn't already a MIDX, the one we write
470 * must include the cruft pack(s), in case the
471 * non-cruft pack(s) refer to once-cruft objects.
472 *
473 * If there is already a MIDX, we can punt here, since
474 * midx_has_unknown_packs() will make the decision for
475 * us.
476 */
477 if (!get_multi_pack_index(files->packed))
478 midx_must_contain_cruft = 1;
479 }
480
481 if (pack_everything & PACK_CRUFT) {
482 struct write_pack_opts opts = {
483 .po_args = &cruft_po_args,
484 .destination = packtmp,
485 .packtmp = packtmp,
486 .packdir = packdir,
487 };
488
489 if (!cruft_po_args.window)
490 cruft_po_args.window = xstrdup_or_null(po_args.window);
491 if (!cruft_po_args.window_memory)
492 cruft_po_args.window_memory = xstrdup_or_null(po_args.window_memory);
493 if (!cruft_po_args.depth)
494 cruft_po_args.depth = xstrdup_or_null(po_args.depth);
495 if (!cruft_po_args.threads)
496 cruft_po_args.threads = xstrdup_or_null(po_args.threads);
497 if (!cruft_po_args.max_pack_size)
498 cruft_po_args.max_pack_size = po_args.max_pack_size;
499
500 cruft_po_args.local = po_args.local;
501 cruft_po_args.quiet = po_args.quiet;
502 cruft_po_args.delta_base_offset = po_args.delta_base_offset;
503 cruft_po_args.pack_kept_objects = 0;
504
505 ret = write_cruft_pack(&opts, cruft_expiration,
506 combine_cruft_below_size, &names,
507 &existing);
508 if (ret)
509 goto cleanup;
510
511 if (delete_redundant && expire_to) {
512 /*
513 * If `--expire-to` is given with `-d`, it's possible
514 * that we're about to prune some objects. With cruft
515 * packs, pruning is implicit: any objects from existing
516 * packs that weren't picked up by new packs are removed
517 * when their packs are deleted.
518 *
519 * Generate an additional cruft pack, with one twist:
520 * `names` now includes the name of the cruft pack
521 * written in the previous step. So the contents of
522 * _this_ cruft pack exclude everything contained in the
523 * existing cruft pack (that is, all of the unreachable
524 * objects which are no older than
525 * `--cruft-expiration`).
526 *
527 * To make this work, cruft_expiration must become NULL
528 * so that this cruft pack doesn't actually prune any
529 * objects. If it were non-NULL, this call would always
530 * generate an empty pack (since every object not in the
531 * cruft pack generated above will have an mtime older
532 * than the expiration).
533 *
534 * Pretend we don't have a `--combine-cruft-below-size`
535 * argument, since we're not selectively combining
536 * anything based on size to generate the limbo cruft
537 * pack, but rather removing all cruft packs from the
538 * main repository regardless of size.
539 */
540 opts.destination = expire_to;
541 ret = write_cruft_pack(&opts, NULL, 0ul, &names,
542 &existing);
543 if (ret)
544 goto cleanup;
545 }
546 }
547
548 if (po_args.filter_options.choice) {
549 struct write_pack_opts opts = {
550 .po_args = &po_args,
551 .destination = filter_to,
552 .packdir = packdir,
553 .packtmp = packtmp,
554 };
555
556 if (!opts.destination)
557 opts.destination = packtmp;
558
559 ret = write_filtered_pack(&opts, &existing, &names);
560 if (ret)
561 goto cleanup;
562 }
563
564 string_list_sort(&names);
565
566 odb_close(repo->objects);
567
568 /*
569 * Ok we have prepared all new packfiles.
570 */
571 for_each_string_list_item(item, &names)
572 generated_pack_install(item->util, item->string, packdir,
573 packtmp);
574 /* End of pack replacement. */
575
576 if (delete_redundant && pack_everything & ALL_INTO_ONE) {
577 if (write_midx == REPACK_WRITE_MIDX_INCREMENTAL)
578 existing_packs_retain_midx_packs(&existing);
579 existing_packs_mark_for_deletion(&existing, &names);
580 }
581
582 if (write_midx != REPACK_WRITE_MIDX_NONE) {
583 struct repack_write_midx_opts opts = {
584 .existing = &existing,
585 .geometry = &geometry,
586 .names = &names,
587 .refs_snapshot = refs_snapshot ? get_tempfile_path(refs_snapshot) : NULL,
588 .packdir = packdir,
589 .show_progress = show_progress,
590 .write_bitmaps = write_bitmaps > 0,
591 .midx_must_contain_cruft = midx_must_contain_cruft,
592 .midx_split_factor = config_ctx.midx_split_factor,
593 .midx_new_layer_threshold = config_ctx.midx_new_layer_threshold,
594 .mode = write_midx,
595 };
596
597 ret = repack_write_midx(&opts);
598 if (ret)
599 goto cleanup;
600 }
601
602 odb_reprepare(repo->objects);
603
604 if (delete_redundant) {
605 int opts = 0;
606 bool wrote_incremental_midx = write_midx == REPACK_WRITE_MIDX_INCREMENTAL;
607
608 existing_packs_remove_redundant(&existing, packdir,
609 wrote_incremental_midx);
610
611 if (geometry.split_factor)
612 pack_geometry_remove_redundant(&geometry, &names,
613 &existing, packdir,
614 wrote_incremental_midx);
615 if (show_progress)
616 opts |= PRUNE_PACKED_VERBOSE;
617 prune_packed_objects(opts);
618
619 if (!keep_unreachable &&
620 (!(pack_everything & LOOSEN_UNREACHABLE) ||
621 unpack_unreachable) &&
622 is_repository_shallow(repo))
623 prune_shallow(PRUNE_QUICK);
624 }
625
626 if (run_update_server_info)
627 update_server_info(repo, 0);
628
629 if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0)) {
630 struct odb_source_files *files = odb_source_files_downcast(existing.source);
631 unsigned flags = 0;
632
633 if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL, 0))
634 flags |= MIDX_WRITE_INCREMENTAL;
635 write_midx_file(files->packed, NULL, NULL, flags);
636 }
637
638 cleanup:
639 string_list_clear(&keep_pack_list, 0);
640 string_list_clear(&names, 1);
641 existing_packs_release(&existing);
642 pack_geometry_release(&geometry);
643 pack_objects_args_release(&po_args);
644 pack_objects_args_release(&cruft_po_args);
645
646 return ret;
647 }