1 #define USE_THE_REPOSITORY_VARIABLE
2 #define DISABLE_SIGN_COMPARE_WARNINGS
7 #include "environment.h"
10 #include "parse-options.h"
12 #include "run-command.h"
13 #include "server-info.h"
15 #include "string-list.h"
19 #include "prune-packed.h"
20 #include "object-store.h"
21 #include "promisor-remote.h"
24 #include "pack-bitmap.h"
26 #include "list-objects-filter-options.h"
28 #define ALL_INTO_ONE 1
29 #define LOOSEN_UNREACHABLE 2
35 static int pack_everything
;
36 static int delta_base_offset
= 1;
37 static int pack_kept_objects
= -1;
38 static int write_bitmaps
= -1;
39 static int use_delta_islands
;
40 static int run_update_server_info
= 1;
41 static char *packdir
, *packtmp_name
, *packtmp
;
43 static const char *const git_repack_usage
[] = {
44 N_("git repack [-a] [-A] [-d] [-f] [-F] [-l] [-n] [-q] [-b] [-m]\n"
45 "[--window=<n>] [--depth=<n>] [--threads=<n>] [--keep-pack=<pack-name>]\n"
46 "[--write-midx] [--name-hash-version=<n>] [--path-walk]"),
50 static const char incremental_bitmap_conflict_error
[] = N_(
51 "Incremental repacks are incompatible with bitmap indexes. Use\n"
52 "--no-write-bitmap-index or disable the pack.writeBitmaps configuration."
55 struct pack_objects_args
{
60 unsigned long max_pack_size
;
65 int name_hash_version
;
67 struct list_objects_filter_options filter_options
;
70 static int repack_config(const char *var
, const char *value
,
71 const struct config_context
*ctx
, void *cb
)
73 struct pack_objects_args
*cruft_po_args
= cb
;
74 if (!strcmp(var
, "repack.usedeltabaseoffset")) {
75 delta_base_offset
= git_config_bool(var
, value
);
78 if (!strcmp(var
, "repack.packkeptobjects")) {
79 pack_kept_objects
= git_config_bool(var
, value
);
82 if (!strcmp(var
, "repack.writebitmaps") ||
83 !strcmp(var
, "pack.writebitmaps")) {
84 write_bitmaps
= git_config_bool(var
, value
);
87 if (!strcmp(var
, "repack.usedeltaislands")) {
88 use_delta_islands
= git_config_bool(var
, value
);
91 if (strcmp(var
, "repack.updateserverinfo") == 0) {
92 run_update_server_info
= git_config_bool(var
, value
);
95 if (!strcmp(var
, "repack.cruftwindow")) {
96 free(cruft_po_args
->window
);
97 return git_config_string(&cruft_po_args
->window
, var
, value
);
99 if (!strcmp(var
, "repack.cruftwindowmemory")) {
100 free(cruft_po_args
->window_memory
);
101 return git_config_string(&cruft_po_args
->window_memory
, var
, value
);
103 if (!strcmp(var
, "repack.cruftdepth")) {
104 free(cruft_po_args
->depth
);
105 return git_config_string(&cruft_po_args
->depth
, var
, value
);
107 if (!strcmp(var
, "repack.cruftthreads")) {
108 free(cruft_po_args
->threads
);
109 return git_config_string(&cruft_po_args
->threads
, var
, value
);
111 return git_default_config(var
, value
, ctx
, cb
);
114 static void pack_objects_args_release(struct pack_objects_args
*args
)
117 free(args
->window_memory
);
120 list_objects_filter_release(&args
->filter_options
);
123 struct existing_packs
{
124 struct string_list kept_packs
;
125 struct string_list non_kept_packs
;
126 struct string_list cruft_packs
;
129 #define EXISTING_PACKS_INIT { \
130 .kept_packs = STRING_LIST_INIT_DUP, \
131 .non_kept_packs = STRING_LIST_INIT_DUP, \
132 .cruft_packs = STRING_LIST_INIT_DUP, \
135 static int has_existing_non_kept_packs(const struct existing_packs
*existing
)
137 return existing
->non_kept_packs
.nr
|| existing
->cruft_packs
.nr
;
140 static void pack_mark_for_deletion(struct string_list_item
*item
)
142 item
->util
= (void*)((uintptr_t)item
->util
| DELETE_PACK
);
145 static void pack_unmark_for_deletion(struct string_list_item
*item
)
147 item
->util
= (void*)((uintptr_t)item
->util
& ~DELETE_PACK
);
150 static int pack_is_marked_for_deletion(struct string_list_item
*item
)
152 return (uintptr_t)item
->util
& DELETE_PACK
;
155 static void pack_mark_retained(struct string_list_item
*item
)
157 item
->util
= (void*)((uintptr_t)item
->util
| RETAIN_PACK
);
160 static int pack_is_retained(struct string_list_item
*item
)
162 return (uintptr_t)item
->util
& RETAIN_PACK
;
165 static void mark_packs_for_deletion_1(struct string_list
*names
,
166 struct string_list
*list
)
168 struct string_list_item
*item
;
169 const int hexsz
= the_hash_algo
->hexsz
;
171 for_each_string_list_item(item
, list
) {
173 size_t len
= strlen(item
->string
);
176 sha1
= item
->string
+ len
- hexsz
;
178 if (pack_is_retained(item
)) {
179 pack_unmark_for_deletion(item
);
180 } else if (!string_list_has_string(names
, sha1
)) {
182 * Mark this pack for deletion, which ensures
183 * that this pack won't be included in a MIDX
184 * (if `--write-midx` was given) and that we
185 * will actually delete this pack (if `-d` was
188 pack_mark_for_deletion(item
);
193 static void retain_cruft_pack(struct existing_packs
*existing
,
194 struct packed_git
*cruft
)
196 struct strbuf buf
= STRBUF_INIT
;
197 struct string_list_item
*item
;
199 strbuf_addstr(&buf
, pack_basename(cruft
));
200 strbuf_strip_suffix(&buf
, ".pack");
202 item
= string_list_lookup(&existing
->cruft_packs
, buf
.buf
);
204 BUG("could not find cruft pack '%s'", pack_basename(cruft
));
206 pack_mark_retained(item
);
207 strbuf_release(&buf
);
210 static void mark_packs_for_deletion(struct existing_packs
*existing
,
211 struct string_list
*names
)
214 mark_packs_for_deletion_1(names
, &existing
->non_kept_packs
);
215 mark_packs_for_deletion_1(names
, &existing
->cruft_packs
);
218 static void remove_redundant_pack(const char *dir_name
, const char *base_name
)
220 struct strbuf buf
= STRBUF_INIT
;
221 struct multi_pack_index
*m
= get_local_multi_pack_index(the_repository
);
222 strbuf_addf(&buf
, "%s.pack", base_name
);
223 if (m
&& midx_contains_pack(m
, buf
.buf
))
224 clear_midx_file(the_repository
);
225 strbuf_insertf(&buf
, 0, "%s/", dir_name
);
226 unlink_pack_path(buf
.buf
, 1);
227 strbuf_release(&buf
);
230 static void remove_redundant_packs_1(struct string_list
*packs
)
232 struct string_list_item
*item
;
233 for_each_string_list_item(item
, packs
) {
234 if (!pack_is_marked_for_deletion(item
))
236 remove_redundant_pack(packdir
, item
->string
);
240 static void remove_redundant_existing_packs(struct existing_packs
*existing
)
242 remove_redundant_packs_1(&existing
->non_kept_packs
);
243 remove_redundant_packs_1(&existing
->cruft_packs
);
246 static void existing_packs_release(struct existing_packs
*existing
)
248 string_list_clear(&existing
->kept_packs
, 0);
249 string_list_clear(&existing
->non_kept_packs
, 0);
250 string_list_clear(&existing
->cruft_packs
, 0);
254 * Adds all packs hex strings (pack-$HASH) to either packs->non_kept
255 * or packs->kept based on whether each pack has a corresponding
256 * .keep file or not. Packs without a .keep file are not to be kept
257 * if we are going to pack everything into one file.
259 static void collect_pack_filenames(struct existing_packs
*existing
,
260 const struct string_list
*extra_keep
)
262 struct packed_git
*p
;
263 struct strbuf buf
= STRBUF_INIT
;
265 for (p
= get_all_packs(the_repository
); p
; p
= p
->next
) {
272 base
= pack_basename(p
);
274 for (i
= 0; i
< extra_keep
->nr
; i
++)
275 if (!fspathcmp(base
, extra_keep
->items
[i
].string
))
279 strbuf_addstr(&buf
, base
);
280 strbuf_strip_suffix(&buf
, ".pack");
282 if ((extra_keep
->nr
> 0 && i
< extra_keep
->nr
) || p
->pack_keep
)
283 string_list_append(&existing
->kept_packs
, buf
.buf
);
284 else if (p
->is_cruft
)
285 string_list_append(&existing
->cruft_packs
, buf
.buf
);
287 string_list_append(&existing
->non_kept_packs
, buf
.buf
);
290 string_list_sort(&existing
->kept_packs
);
291 string_list_sort(&existing
->non_kept_packs
);
292 string_list_sort(&existing
->cruft_packs
);
293 strbuf_release(&buf
);
296 static void prepare_pack_objects(struct child_process
*cmd
,
297 const struct pack_objects_args
*args
,
300 strvec_push(&cmd
->args
, "pack-objects");
302 strvec_pushf(&cmd
->args
, "--window=%s", args
->window
);
303 if (args
->window_memory
)
304 strvec_pushf(&cmd
->args
, "--window-memory=%s", args
->window_memory
);
306 strvec_pushf(&cmd
->args
, "--depth=%s", args
->depth
);
308 strvec_pushf(&cmd
->args
, "--threads=%s", args
->threads
);
309 if (args
->max_pack_size
)
310 strvec_pushf(&cmd
->args
, "--max-pack-size=%lu", args
->max_pack_size
);
311 if (args
->no_reuse_delta
)
312 strvec_pushf(&cmd
->args
, "--no-reuse-delta");
313 if (args
->no_reuse_object
)
314 strvec_pushf(&cmd
->args
, "--no-reuse-object");
315 if (args
->name_hash_version
)
316 strvec_pushf(&cmd
->args
, "--name-hash-version=%d", args
->name_hash_version
);
318 strvec_pushf(&cmd
->args
, "--path-walk");
320 strvec_push(&cmd
->args
, "--local");
322 strvec_push(&cmd
->args
, "--quiet");
323 if (delta_base_offset
)
324 strvec_push(&cmd
->args
, "--delta-base-offset");
325 strvec_push(&cmd
->args
, out
);
331 * Write oid to the given struct child_process's stdin, starting it first if
334 static int write_oid(const struct object_id
*oid
,
335 struct packed_git
*pack UNUSED
,
336 uint32_t pos UNUSED
, void *data
)
338 struct child_process
*cmd
= data
;
341 if (start_command(cmd
))
342 die(_("could not start pack-objects to repack promisor objects"));
345 if (write_in_full(cmd
->in
, oid_to_hex(oid
), the_hash_algo
->hexsz
) < 0 ||
346 write_in_full(cmd
->in
, "\n", 1) < 0)
347 die(_("failed to feed promisor objects to pack-objects"));
363 struct generated_pack_data
{
364 struct tempfile
*tempfiles
[ARRAY_SIZE(exts
)];
367 static struct generated_pack_data
*populate_pack_exts(const char *name
)
370 struct strbuf path
= STRBUF_INIT
;
371 struct generated_pack_data
*data
= xcalloc(1, sizeof(*data
));
374 for (i
= 0; i
< ARRAY_SIZE(exts
); i
++) {
376 strbuf_addf(&path
, "%s-%s%s", packtmp
, name
, exts
[i
].name
);
378 if (stat(path
.buf
, &statbuf
))
381 data
->tempfiles
[i
] = register_tempfile(path
.buf
);
384 strbuf_release(&path
);
388 static int has_pack_ext(const struct generated_pack_data
*data
,
392 for (i
= 0; i
< ARRAY_SIZE(exts
); i
++) {
393 if (strcmp(exts
[i
].name
, ext
))
395 return !!data
->tempfiles
[i
];
397 BUG("unknown pack extension: '%s'", ext
);
400 static void repack_promisor_objects(const struct pack_objects_args
*args
,
401 struct string_list
*names
)
403 struct child_process cmd
= CHILD_PROCESS_INIT
;
405 struct strbuf line
= STRBUF_INIT
;
407 prepare_pack_objects(&cmd
, args
, packtmp
);
411 * NEEDSWORK: Giving pack-objects only the OIDs without any ordering
412 * hints may result in suboptimal deltas in the resulting pack. See if
413 * the OIDs can be sent with fake paths such that pack-objects can use a
414 * {type -> existing pack order} ordering when computing deltas instead
415 * of a {type -> size} ordering, which may produce better deltas.
417 for_each_packed_object(the_repository
, write_oid
, &cmd
,
418 FOR_EACH_OBJECT_PROMISOR_ONLY
);
421 /* No packed objects; cmd was never started */
422 child_process_clear(&cmd
);
428 out
= xfdopen(cmd
.out
, "r");
429 while (strbuf_getline_lf(&line
, out
) != EOF
) {
430 struct string_list_item
*item
;
433 if (line
.len
!= the_hash_algo
->hexsz
)
434 die(_("repack: Expecting full hex object ID lines only from pack-objects."));
435 item
= string_list_append(names
, line
.buf
);
438 * pack-objects creates the .pack and .idx files, but not the
439 * .promisor file. Create the .promisor file, which is empty.
441 * NEEDSWORK: fetch-pack sometimes generates non-empty
442 * .promisor files containing the ref names and associated
443 * hashes at the point of generation of the corresponding
444 * packfile, but this would not preserve their contents. Maybe
445 * concatenate the contents of all .promisor files instead of
446 * just creating a new empty file.
448 promisor_name
= mkpathdup("%s-%s.promisor", packtmp
,
450 write_promisor_file(promisor_name
, NULL
, 0);
452 item
->util
= populate_pack_exts(item
->string
);
458 if (finish_command(&cmd
))
459 die(_("could not finish pack-objects to repack promisor objects"));
460 strbuf_release(&line
);
463 struct pack_geometry
{
464 struct packed_git
**pack
;
465 uint32_t pack_nr
, pack_alloc
;
471 static uint32_t geometry_pack_weight(struct packed_git
*p
)
473 if (open_pack_index(p
))
474 die(_("cannot open index for %s"), p
->pack_name
);
475 return p
->num_objects
;
478 static int geometry_cmp(const void *va
, const void *vb
)
480 uint32_t aw
= geometry_pack_weight(*(struct packed_git
**)va
),
481 bw
= geometry_pack_weight(*(struct packed_git
**)vb
);
490 static void init_pack_geometry(struct pack_geometry
*geometry
,
491 struct existing_packs
*existing
,
492 const struct pack_objects_args
*args
)
494 struct packed_git
*p
;
495 struct strbuf buf
= STRBUF_INIT
;
497 for (p
= get_all_packs(the_repository
); p
; p
= p
->next
) {
498 if (args
->local
&& !p
->pack_local
)
500 * When asked to only repack local packfiles we skip
501 * over any packfiles that are borrowed from alternate
502 * object directories.
506 if (!pack_kept_objects
) {
508 * Any pack that has its pack_keep bit set will
509 * appear in existing->kept_packs below, but
510 * this saves us from doing a more expensive
517 * The pack may be kept via the --keep-pack
518 * option; check 'existing->kept_packs' to
519 * determine whether to ignore it.
522 strbuf_addstr(&buf
, pack_basename(p
));
523 strbuf_strip_suffix(&buf
, ".pack");
525 if (string_list_has_string(&existing
->kept_packs
, buf
.buf
))
531 ALLOC_GROW(geometry
->pack
,
532 geometry
->pack_nr
+ 1,
533 geometry
->pack_alloc
);
535 geometry
->pack
[geometry
->pack_nr
] = p
;
539 QSORT(geometry
->pack
, geometry
->pack_nr
, geometry_cmp
);
540 strbuf_release(&buf
);
543 static void split_pack_geometry(struct pack_geometry
*geometry
)
547 off_t total_size
= 0;
549 if (!geometry
->pack_nr
) {
550 geometry
->split
= geometry
->pack_nr
;
555 * First, count the number of packs (in descending order of size) which
556 * already form a geometric progression.
558 for (i
= geometry
->pack_nr
- 1; i
> 0; i
--) {
559 struct packed_git
*ours
= geometry
->pack
[i
];
560 struct packed_git
*prev
= geometry
->pack
[i
- 1];
562 if (unsigned_mult_overflows(geometry
->split_factor
,
563 geometry_pack_weight(prev
)))
564 die(_("pack %s too large to consider in geometric "
568 if (geometry_pack_weight(ours
) <
569 geometry
->split_factor
* geometry_pack_weight(prev
))
577 * Move the split one to the right, since the top element in the
578 * last-compared pair can't be in the progression. Only do this
579 * when we split in the middle of the array (otherwise if we got
580 * to the end, then the split is in the right place).
586 * Then, anything to the left of 'split' must be in a new pack. But,
587 * creating that new pack may cause packs in the heavy half to no longer
588 * form a geometric progression.
590 * Compute an expected size of the new pack, and then determine how many
591 * packs in the heavy half need to be joined into it (if any) to restore
592 * the geometric progression.
594 for (i
= 0; i
< split
; i
++) {
595 struct packed_git
*p
= geometry
->pack
[i
];
597 if (unsigned_add_overflows(total_size
, geometry_pack_weight(p
)))
598 die(_("pack %s too large to roll up"), p
->pack_name
);
599 total_size
+= geometry_pack_weight(p
);
601 for (i
= split
; i
< geometry
->pack_nr
; i
++) {
602 struct packed_git
*ours
= geometry
->pack
[i
];
604 if (unsigned_mult_overflows(geometry
->split_factor
,
606 die(_("pack %s too large to roll up"), ours
->pack_name
);
608 if (geometry_pack_weight(ours
) <
609 geometry
->split_factor
* total_size
) {
610 if (unsigned_add_overflows(total_size
,
611 geometry_pack_weight(ours
)))
612 die(_("pack %s too large to roll up"),
616 total_size
+= geometry_pack_weight(ours
);
621 geometry
->split
= split
;
624 static struct packed_git
*get_preferred_pack(struct pack_geometry
*geometry
)
630 * No geometry means either an all-into-one repack (in which
631 * case there is only one pack left and it is the largest) or an
634 * If repacking incrementally, then we could check the size of
635 * all packs to determine which should be preferred, but leave
640 if (geometry
->split
== geometry
->pack_nr
)
644 * The preferred pack is the largest pack above the split line. In
645 * other words, it is the largest pack that does not get rolled up in
646 * the geometric repack.
648 for (i
= geometry
->pack_nr
; i
> geometry
->split
; i
--)
650 * A pack that is not local would never be included in a
651 * multi-pack index. We thus skip over any non-local packs.
653 if (geometry
->pack
[i
- 1]->pack_local
)
654 return geometry
->pack
[i
- 1];
659 static void geometry_remove_redundant_packs(struct pack_geometry
*geometry
,
660 struct string_list
*names
,
661 struct existing_packs
*existing
)
663 struct strbuf buf
= STRBUF_INIT
;
666 for (i
= 0; i
< geometry
->split
; i
++) {
667 struct packed_git
*p
= geometry
->pack
[i
];
668 if (string_list_has_string(names
, hash_to_hex(p
->hash
)))
672 strbuf_addstr(&buf
, pack_basename(p
));
673 strbuf_strip_suffix(&buf
, ".pack");
675 if ((p
->pack_keep
) ||
676 (string_list_has_string(&existing
->kept_packs
, buf
.buf
)))
679 remove_redundant_pack(packdir
, buf
.buf
);
682 strbuf_release(&buf
);
685 static void free_pack_geometry(struct pack_geometry
*geometry
)
690 free(geometry
->pack
);
693 struct midx_snapshot_ref_data
{
699 static int midx_snapshot_ref_one(const char *refname UNUSED
,
700 const char *referent UNUSED
,
701 const struct object_id
*oid
,
702 int flag UNUSED
, void *_data
)
704 struct midx_snapshot_ref_data
*data
= _data
;
705 struct object_id peeled
;
707 if (!peel_iterated_oid(the_repository
, oid
, &peeled
))
710 if (oidset_insert(&data
->seen
, oid
))
711 return 0; /* already seen */
713 if (oid_object_info(the_repository
, oid
, NULL
) != OBJ_COMMIT
)
716 fprintf(data
->f
->fp
, "%s%s\n", data
->preferred
? "+" : "",
722 static void midx_snapshot_refs(struct tempfile
*f
)
724 struct midx_snapshot_ref_data data
;
725 const struct string_list
*preferred
= bitmap_preferred_tips(the_repository
);
729 oidset_init(&data
.seen
, 0);
731 if (!fdopen_tempfile(f
, "w"))
732 die(_("could not open tempfile %s for writing"),
733 get_tempfile_path(f
));
736 struct string_list_item
*item
;
739 for_each_string_list_item(item
, preferred
)
740 refs_for_each_ref_in(get_main_ref_store(the_repository
),
742 midx_snapshot_ref_one
, &data
);
746 refs_for_each_ref(get_main_ref_store(the_repository
),
747 midx_snapshot_ref_one
, &data
);
749 if (close_tempfile_gently(f
)) {
750 int save_errno
= errno
;
753 die_errno(_("could not close refs snapshot tempfile"));
756 oidset_clear(&data
.seen
);
759 static void midx_included_packs(struct string_list
*include
,
760 struct existing_packs
*existing
,
761 struct string_list
*names
,
762 struct pack_geometry
*geometry
)
764 struct string_list_item
*item
;
765 struct strbuf buf
= STRBUF_INIT
;
767 for_each_string_list_item(item
, &existing
->kept_packs
) {
769 strbuf_addf(&buf
, "%s.idx", item
->string
);
770 string_list_insert(include
, buf
.buf
);
773 for_each_string_list_item(item
, names
) {
775 strbuf_addf(&buf
, "pack-%s.idx", item
->string
);
776 string_list_insert(include
, buf
.buf
);
779 if (geometry
->split_factor
) {
782 for (i
= geometry
->split
; i
< geometry
->pack_nr
; i
++) {
783 struct packed_git
*p
= geometry
->pack
[i
];
786 * The multi-pack index never refers to packfiles part
787 * of an alternate object database, so we skip these.
788 * While git-multi-pack-index(1) would silently ignore
789 * them anyway, this allows us to skip executing the
790 * command completely when we have only non-local
797 strbuf_addstr(&buf
, pack_basename(p
));
798 strbuf_strip_suffix(&buf
, ".pack");
799 strbuf_addstr(&buf
, ".idx");
801 string_list_insert(include
, buf
.buf
);
804 for_each_string_list_item(item
, &existing
->non_kept_packs
) {
805 if (pack_is_marked_for_deletion(item
))
809 strbuf_addf(&buf
, "%s.idx", item
->string
);
810 string_list_insert(include
, buf
.buf
);
814 for_each_string_list_item(item
, &existing
->cruft_packs
) {
816 * When doing a --geometric repack, there is no need to check
817 * for deleted packs, since we're by definition not doing an
818 * ALL_INTO_ONE repack (hence no packs will be deleted).
819 * Otherwise we must check for and exclude any packs which are
820 * enqueued for deletion.
822 * So we could omit the conditional below in the --geometric
823 * case, but doing so is unnecessary since no packs are marked
824 * as pending deletion (since we only call
825 * `mark_packs_for_deletion()` when doing an all-into-one
828 if (pack_is_marked_for_deletion(item
))
832 strbuf_addf(&buf
, "%s.idx", item
->string
);
833 string_list_insert(include
, buf
.buf
);
836 strbuf_release(&buf
);
839 static int write_midx_included_packs(struct string_list
*include
,
840 struct pack_geometry
*geometry
,
841 struct string_list
*names
,
842 const char *refs_snapshot
,
843 int show_progress
, int write_bitmaps
)
845 struct child_process cmd
= CHILD_PROCESS_INIT
;
846 struct string_list_item
*item
;
847 struct packed_git
*preferred
= get_preferred_pack(geometry
);
857 strvec_push(&cmd
.args
, "multi-pack-index");
858 strvec_pushl(&cmd
.args
, "write", "--stdin-packs", NULL
);
861 strvec_push(&cmd
.args
, "--progress");
863 strvec_push(&cmd
.args
, "--no-progress");
866 strvec_push(&cmd
.args
, "--bitmap");
869 strvec_pushf(&cmd
.args
, "--preferred-pack=%s",
870 pack_basename(preferred
));
871 else if (names
->nr
) {
872 /* The largest pack was repacked, meaning that either
873 * one or two packs exist depending on whether the
874 * repository has a cruft pack or not.
876 * Select the non-cruft one as preferred to encourage
877 * pack-reuse among packs containing reachable objects
878 * over unreachable ones.
880 * (Note we could write multiple packs here if
881 * `--max-pack-size` was given, but any one of them
882 * will suffice, so pick the first one.)
884 for_each_string_list_item(item
, names
) {
885 struct generated_pack_data
*data
= item
->util
;
886 if (has_pack_ext(data
, ".mtimes"))
889 strvec_pushf(&cmd
.args
, "--preferred-pack=pack-%s.pack",
895 * No packs were kept, and no packs were written. The
896 * only thing remaining are .keep packs (unless
897 * --pack-kept-objects was given).
899 * Set the `--preferred-pack` arbitrarily here.
905 strvec_pushf(&cmd
.args
, "--refs-snapshot=%s", refs_snapshot
);
907 ret
= start_command(&cmd
);
911 in
= xfdopen(cmd
.in
, "w");
912 for_each_string_list_item(item
, include
)
913 fprintf(in
, "%s\n", item
->string
);
916 return finish_command(&cmd
);
919 static void remove_redundant_bitmaps(struct string_list
*include
,
922 struct strbuf path
= STRBUF_INIT
;
923 struct string_list_item
*item
;
926 strbuf_addstr(&path
, packdir
);
927 strbuf_addch(&path
, '/');
928 packdir_len
= path
.len
;
931 * Remove any pack bitmaps corresponding to packs which are now
932 * included in the MIDX.
934 for_each_string_list_item(item
, include
) {
935 strbuf_addstr(&path
, item
->string
);
936 strbuf_strip_suffix(&path
, ".idx");
937 strbuf_addstr(&path
, ".bitmap");
939 if (unlink(path
.buf
) && errno
!= ENOENT
)
940 warning_errno(_("could not remove stale bitmap: %s"),
943 strbuf_setlen(&path
, packdir_len
);
945 strbuf_release(&path
);
948 static int finish_pack_objects_cmd(struct child_process
*cmd
,
949 struct string_list
*names
,
953 struct strbuf line
= STRBUF_INIT
;
955 out
= xfdopen(cmd
->out
, "r");
956 while (strbuf_getline_lf(&line
, out
) != EOF
) {
957 struct string_list_item
*item
;
959 if (line
.len
!= the_hash_algo
->hexsz
)
960 die(_("repack: Expecting full hex object ID lines only "
961 "from pack-objects."));
963 * Avoid putting packs written outside of the repository in the
967 item
= string_list_append(names
, line
.buf
);
968 item
->util
= populate_pack_exts(line
.buf
);
973 strbuf_release(&line
);
975 return finish_command(cmd
);
978 static int write_filtered_pack(const struct pack_objects_args
*args
,
979 const char *destination
,
980 const char *pack_prefix
,
981 struct existing_packs
*existing
,
982 struct string_list
*names
)
984 struct child_process cmd
= CHILD_PROCESS_INIT
;
985 struct string_list_item
*item
;
990 int local
= skip_prefix(destination
, packdir
, &scratch
);
992 prepare_pack_objects(&cmd
, args
, destination
);
994 strvec_push(&cmd
.args
, "--stdin-packs");
996 if (!pack_kept_objects
)
997 strvec_push(&cmd
.args
, "--honor-pack-keep");
998 for_each_string_list_item(item
, &existing
->kept_packs
)
999 strvec_pushf(&cmd
.args
, "--keep-pack=%s", item
->string
);
1003 ret
= start_command(&cmd
);
1008 * Here 'names' contains only the pack(s) that were just
1009 * written, which is exactly the packs we want to keep. Also
1010 * 'existing_kept_packs' already contains the packs in
1013 in
= xfdopen(cmd
.in
, "w");
1014 for_each_string_list_item(item
, names
)
1015 fprintf(in
, "^%s-%s.pack\n", pack_prefix
, item
->string
);
1016 for_each_string_list_item(item
, &existing
->non_kept_packs
)
1017 fprintf(in
, "%s.pack\n", item
->string
);
1018 for_each_string_list_item(item
, &existing
->cruft_packs
)
1019 fprintf(in
, "%s.pack\n", item
->string
);
1020 caret
= pack_kept_objects
? "" : "^";
1021 for_each_string_list_item(item
, &existing
->kept_packs
)
1022 fprintf(in
, "%s%s.pack\n", caret
, item
->string
);
1025 return finish_pack_objects_cmd(&cmd
, names
, local
);
1028 static void combine_small_cruft_packs(FILE *in
, size_t combine_cruft_below_size
,
1029 struct existing_packs
*existing
)
1031 struct packed_git
*p
;
1032 struct strbuf buf
= STRBUF_INIT
;
1035 for (p
= get_all_packs(the_repository
); p
; p
= p
->next
) {
1036 if (!(p
->is_cruft
&& p
->pack_local
))
1040 strbuf_addstr(&buf
, pack_basename(p
));
1041 strbuf_strip_suffix(&buf
, ".pack");
1043 if (!string_list_has_string(&existing
->cruft_packs
, buf
.buf
))
1046 if (p
->pack_size
< combine_cruft_below_size
) {
1047 fprintf(in
, "-%s\n", pack_basename(p
));
1049 retain_cruft_pack(existing
, p
);
1050 fprintf(in
, "%s\n", pack_basename(p
));
1054 for (i
= 0; i
< existing
->non_kept_packs
.nr
; i
++)
1055 fprintf(in
, "-%s.pack\n",
1056 existing
->non_kept_packs
.items
[i
].string
);
1058 strbuf_release(&buf
);
1061 static int write_cruft_pack(const struct pack_objects_args
*args
,
1062 const char *destination
,
1063 const char *pack_prefix
,
1064 const char *cruft_expiration
,
1065 unsigned long combine_cruft_below_size
,
1066 struct string_list
*names
,
1067 struct existing_packs
*existing
)
1069 struct child_process cmd
= CHILD_PROCESS_INIT
;
1070 struct string_list_item
*item
;
1073 const char *scratch
;
1074 int local
= skip_prefix(destination
, packdir
, &scratch
);
1076 prepare_pack_objects(&cmd
, args
, destination
);
1078 strvec_push(&cmd
.args
, "--cruft");
1079 if (cruft_expiration
)
1080 strvec_pushf(&cmd
.args
, "--cruft-expiration=%s",
1083 strvec_push(&cmd
.args
, "--honor-pack-keep");
1084 strvec_push(&cmd
.args
, "--non-empty");
1088 ret
= start_command(&cmd
);
1093 * names has a confusing double use: it both provides the list
1094 * of just-written new packs, and accepts the name of the cruft
1095 * pack we are writing.
1097 * By the time it is read here, it contains only the pack(s)
1098 * that were just written, which is exactly the set of packs we
1099 * want to consider kept.
1101 * If `--expire-to` is given, the double-use served by `names`
1102 * ensures that the pack written to `--expire-to` excludes any
1103 * objects contained in the cruft pack.
1105 in
= xfdopen(cmd
.in
, "w");
1106 for_each_string_list_item(item
, names
)
1107 fprintf(in
, "%s-%s.pack\n", pack_prefix
, item
->string
);
1108 if (combine_cruft_below_size
&& !cruft_expiration
) {
1109 combine_small_cruft_packs(in
, combine_cruft_below_size
,
1112 for_each_string_list_item(item
, &existing
->non_kept_packs
)
1113 fprintf(in
, "-%s.pack\n", item
->string
);
1114 for_each_string_list_item(item
, &existing
->cruft_packs
)
1115 fprintf(in
, "-%s.pack\n", item
->string
);
1117 for_each_string_list_item(item
, &existing
->kept_packs
)
1118 fprintf(in
, "%s.pack\n", item
->string
);
1121 return finish_pack_objects_cmd(&cmd
, names
, local
);
1124 static const char *find_pack_prefix(const char *packdir
, const char *packtmp
)
1126 const char *pack_prefix
;
1127 if (!skip_prefix(packtmp
, packdir
, &pack_prefix
))
1128 die(_("pack prefix %s does not begin with objdir %s"),
1130 if (*pack_prefix
== '/')
1135 int cmd_repack(int argc
,
1138 struct repository
*repo UNUSED
)
1140 struct child_process cmd
= CHILD_PROCESS_INIT
;
1141 struct string_list_item
*item
;
1142 struct string_list names
= STRING_LIST_INIT_DUP
;
1143 struct existing_packs existing
= EXISTING_PACKS_INIT
;
1144 struct pack_geometry geometry
= { 0 };
1145 struct tempfile
*refs_snapshot
= NULL
;
1149 /* variables to be filled by option parsing */
1150 int delete_redundant
= 0;
1151 const char *unpack_unreachable
= NULL
;
1152 int keep_unreachable
= 0;
1153 struct string_list keep_pack_list
= STRING_LIST_INIT_NODUP
;
1154 struct pack_objects_args po_args
= { 0 };
1155 struct pack_objects_args cruft_po_args
= { 0 };
1157 const char *cruft_expiration
= NULL
;
1158 const char *expire_to
= NULL
;
1159 const char *filter_to
= NULL
;
1160 const char *opt_window
= NULL
;
1161 const char *opt_window_memory
= NULL
;
1162 const char *opt_depth
= NULL
;
1163 const char *opt_threads
= NULL
;
1164 unsigned long combine_cruft_below_size
= 0ul;
1166 struct option builtin_repack_options
[] = {
1167 OPT_BIT('a', NULL
, &pack_everything
,
1168 N_("pack everything in a single pack"), ALL_INTO_ONE
),
1169 OPT_BIT('A', NULL
, &pack_everything
,
1170 N_("same as -a, and turn unreachable objects loose"),
1171 LOOSEN_UNREACHABLE
| ALL_INTO_ONE
),
1172 OPT_BIT(0, "cruft", &pack_everything
,
1173 N_("same as -a, pack unreachable cruft objects separately"),
1175 OPT_STRING(0, "cruft-expiration", &cruft_expiration
, N_("approxidate"),
1176 N_("with --cruft, expire objects older than this")),
1177 OPT_UNSIGNED(0, "combine-cruft-below-size",
1178 &combine_cruft_below_size
,
1179 N_("with --cruft, only repack cruft packs smaller than this")),
1180 OPT_UNSIGNED(0, "max-cruft-size", &cruft_po_args
.max_pack_size
,
1181 N_("with --cruft, limit the size of new cruft packs")),
1182 OPT_BOOL('d', NULL
, &delete_redundant
,
1183 N_("remove redundant packs, and run git-prune-packed")),
1184 OPT_BOOL('f', NULL
, &po_args
.no_reuse_delta
,
1185 N_("pass --no-reuse-delta to git-pack-objects")),
1186 OPT_BOOL('F', NULL
, &po_args
.no_reuse_object
,
1187 N_("pass --no-reuse-object to git-pack-objects")),
1188 OPT_INTEGER(0, "name-hash-version", &po_args
.name_hash_version
,
1189 N_("specify the name hash version to use for grouping similar objects by path")),
1190 OPT_BOOL(0, "path-walk", &po_args
.path_walk
,
1191 N_("pass --path-walk to git-pack-objects")),
1192 OPT_NEGBIT('n', NULL
, &run_update_server_info
,
1193 N_("do not run git-update-server-info"), 1),
1194 OPT__QUIET(&po_args
.quiet
, N_("be quiet")),
1195 OPT_BOOL('l', "local", &po_args
.local
,
1196 N_("pass --local to git-pack-objects")),
1197 OPT_BOOL('b', "write-bitmap-index", &write_bitmaps
,
1198 N_("write bitmap index")),
1199 OPT_BOOL('i', "delta-islands", &use_delta_islands
,
1200 N_("pass --delta-islands to git-pack-objects")),
1201 OPT_STRING(0, "unpack-unreachable", &unpack_unreachable
, N_("approxidate"),
1202 N_("with -A, do not loosen objects older than this")),
1203 OPT_BOOL('k', "keep-unreachable", &keep_unreachable
,
1204 N_("with -a, repack unreachable objects")),
1205 OPT_STRING(0, "window", &opt_window
, N_("n"),
1206 N_("size of the window used for delta compression")),
1207 OPT_STRING(0, "window-memory", &opt_window_memory
, N_("bytes"),
1208 N_("same as the above, but limit memory size instead of entries count")),
1209 OPT_STRING(0, "depth", &opt_depth
, N_("n"),
1210 N_("limits the maximum delta depth")),
1211 OPT_STRING(0, "threads", &opt_threads
, N_("n"),
1212 N_("limits the maximum number of threads")),
1213 OPT_UNSIGNED(0, "max-pack-size", &po_args
.max_pack_size
,
1214 N_("maximum size of each packfile")),
1215 OPT_PARSE_LIST_OBJECTS_FILTER(&po_args
.filter_options
),
1216 OPT_BOOL(0, "pack-kept-objects", &pack_kept_objects
,
1217 N_("repack objects in packs marked with .keep")),
1218 OPT_STRING_LIST(0, "keep-pack", &keep_pack_list
, N_("name"),
1219 N_("do not repack this pack")),
1220 OPT_INTEGER('g', "geometric", &geometry
.split_factor
,
1221 N_("find a geometric progression with factor <N>")),
1222 OPT_BOOL('m', "write-midx", &write_midx
,
1223 N_("write a multi-pack index of the resulting packs")),
1224 OPT_STRING(0, "expire-to", &expire_to
, N_("dir"),
1225 N_("pack prefix to store a pack containing pruned objects")),
1226 OPT_STRING(0, "filter-to", &filter_to
, N_("dir"),
1227 N_("pack prefix to store a pack containing filtered out objects")),
1231 list_objects_filter_init(&po_args
.filter_options
);
1233 git_config(repack_config
, &cruft_po_args
);
1235 argc
= parse_options(argc
, argv
, prefix
, builtin_repack_options
,
1236 git_repack_usage
, 0);
1238 po_args
.window
= xstrdup_or_null(opt_window
);
1239 po_args
.window_memory
= xstrdup_or_null(opt_window_memory
);
1240 po_args
.depth
= xstrdup_or_null(opt_depth
);
1241 po_args
.threads
= xstrdup_or_null(opt_threads
);
1243 if (delete_redundant
&& repository_format_precious_objects
)
1244 die(_("cannot delete packs in a precious-objects repo"));
1246 die_for_incompatible_opt3(unpack_unreachable
|| (pack_everything
& LOOSEN_UNREACHABLE
), "-A",
1247 keep_unreachable
, "-k/--keep-unreachable",
1248 pack_everything
& PACK_CRUFT
, "--cruft");
1250 if (pack_everything
& PACK_CRUFT
)
1251 pack_everything
|= ALL_INTO_ONE
;
1253 if (write_bitmaps
< 0) {
1255 (!(pack_everything
& ALL_INTO_ONE
) || !is_bare_repository()))
1258 if (pack_kept_objects
< 0)
1259 pack_kept_objects
= write_bitmaps
> 0 && !write_midx
;
1261 if (write_bitmaps
&& !(pack_everything
& ALL_INTO_ONE
) && !write_midx
)
1262 die(_(incremental_bitmap_conflict_error
));
1264 if (write_bitmaps
&& po_args
.local
&& has_alt_odb(the_repository
)) {
1266 * When asked to do a local repack, but we have
1267 * packfiles that are inherited from an alternate, then
1268 * we cannot guarantee that the multi-pack-index would
1269 * have full coverage of all objects. We thus disable
1270 * writing bitmaps in that case.
1272 warning(_("disabling bitmap writing, as some objects are not being packed"));
1276 if (write_midx
&& write_bitmaps
) {
1277 struct strbuf path
= STRBUF_INIT
;
1279 strbuf_addf(&path
, "%s/%s_XXXXXX", repo_get_object_directory(the_repository
),
1282 refs_snapshot
= xmks_tempfile(path
.buf
);
1283 midx_snapshot_refs(refs_snapshot
);
1285 strbuf_release(&path
);
1288 packdir
= mkpathdup("%s/pack", repo_get_object_directory(the_repository
));
1289 packtmp_name
= xstrfmt(".tmp-%d-pack", (int)getpid());
1290 packtmp
= mkpathdup("%s/%s", packdir
, packtmp_name
);
1292 collect_pack_filenames(&existing
, &keep_pack_list
);
1294 if (geometry
.split_factor
) {
1295 if (pack_everything
)
1296 die(_("options '%s' and '%s' cannot be used together"), "--geometric", "-A/-a");
1297 init_pack_geometry(&geometry
, &existing
, &po_args
);
1298 split_pack_geometry(&geometry
);
1301 prepare_pack_objects(&cmd
, &po_args
, packtmp
);
1303 show_progress
= !po_args
.quiet
&& isatty(2);
1305 strvec_push(&cmd
.args
, "--keep-true-parents");
1306 if (!pack_kept_objects
)
1307 strvec_push(&cmd
.args
, "--honor-pack-keep");
1308 for (i
= 0; i
< keep_pack_list
.nr
; i
++)
1309 strvec_pushf(&cmd
.args
, "--keep-pack=%s",
1310 keep_pack_list
.items
[i
].string
);
1311 strvec_push(&cmd
.args
, "--non-empty");
1312 if (!geometry
.split_factor
) {
1314 * We need to grab all reachable objects, including those that
1315 * are reachable from reflogs and the index.
1317 * When repacking into a geometric progression of packs,
1318 * however, we ask 'git pack-objects --stdin-packs', and it is
1319 * not about packing objects based on reachability but about
1320 * repacking all the objects in specified packs and loose ones
1321 * (indeed, --stdin-packs is incompatible with these options).
1323 strvec_push(&cmd
.args
, "--all");
1324 strvec_push(&cmd
.args
, "--reflog");
1325 strvec_push(&cmd
.args
, "--indexed-objects");
1327 if (repo_has_promisor_remote(the_repository
))
1328 strvec_push(&cmd
.args
, "--exclude-promisor-objects");
1330 if (write_bitmaps
> 0)
1331 strvec_push(&cmd
.args
, "--write-bitmap-index");
1332 else if (write_bitmaps
< 0)
1333 strvec_push(&cmd
.args
, "--write-bitmap-index-quiet");
1335 if (use_delta_islands
)
1336 strvec_push(&cmd
.args
, "--delta-islands");
1338 if (pack_everything
& ALL_INTO_ONE
) {
1339 repack_promisor_objects(&po_args
, &names
);
1341 if (has_existing_non_kept_packs(&existing
) &&
1343 !(pack_everything
& PACK_CRUFT
)) {
1344 for_each_string_list_item(item
, &names
) {
1345 strvec_pushf(&cmd
.args
, "--keep-pack=%s-%s.pack",
1346 packtmp_name
, item
->string
);
1348 if (unpack_unreachable
) {
1349 strvec_pushf(&cmd
.args
,
1350 "--unpack-unreachable=%s",
1351 unpack_unreachable
);
1352 } else if (pack_everything
& LOOSEN_UNREACHABLE
) {
1353 strvec_push(&cmd
.args
,
1354 "--unpack-unreachable");
1355 } else if (keep_unreachable
) {
1356 strvec_push(&cmd
.args
, "--keep-unreachable");
1360 if (keep_unreachable
&& delete_redundant
&&
1361 !(pack_everything
& PACK_CRUFT
))
1362 strvec_push(&cmd
.args
, "--pack-loose-unreachable");
1363 } else if (geometry
.split_factor
) {
1364 strvec_push(&cmd
.args
, "--stdin-packs");
1365 strvec_push(&cmd
.args
, "--unpacked");
1367 strvec_push(&cmd
.args
, "--unpacked");
1368 strvec_push(&cmd
.args
, "--incremental");
1371 if (po_args
.filter_options
.choice
)
1372 strvec_pushf(&cmd
.args
, "--filter=%s",
1373 expand_list_objects_filter_spec(&po_args
.filter_options
));
1375 die(_("option '%s' can only be used along with '%s'"), "--filter-to", "--filter");
1377 if (geometry
.split_factor
)
1382 ret
= start_command(&cmd
);
1386 if (geometry
.split_factor
) {
1387 FILE *in
= xfdopen(cmd
.in
, "w");
1389 * The resulting pack should contain all objects in packs that
1390 * are going to be rolled up, but exclude objects in packs which
1391 * are being left alone.
1393 for (i
= 0; i
< geometry
.split
; i
++)
1394 fprintf(in
, "%s\n", pack_basename(geometry
.pack
[i
]));
1395 for (i
= geometry
.split
; i
< geometry
.pack_nr
; i
++)
1396 fprintf(in
, "^%s\n", pack_basename(geometry
.pack
[i
]));
1400 ret
= finish_pack_objects_cmd(&cmd
, &names
, 1);
1404 if (!names
.nr
&& !po_args
.quiet
)
1405 printf_ln(_("Nothing new to pack."));
1407 if (pack_everything
& PACK_CRUFT
) {
1408 const char *pack_prefix
= find_pack_prefix(packdir
, packtmp
);
1410 if (!cruft_po_args
.window
)
1411 cruft_po_args
.window
= xstrdup_or_null(po_args
.window
);
1412 if (!cruft_po_args
.window_memory
)
1413 cruft_po_args
.window_memory
= xstrdup_or_null(po_args
.window_memory
);
1414 if (!cruft_po_args
.depth
)
1415 cruft_po_args
.depth
= xstrdup_or_null(po_args
.depth
);
1416 if (!cruft_po_args
.threads
)
1417 cruft_po_args
.threads
= xstrdup_or_null(po_args
.threads
);
1418 if (!cruft_po_args
.max_pack_size
)
1419 cruft_po_args
.max_pack_size
= po_args
.max_pack_size
;
1421 cruft_po_args
.local
= po_args
.local
;
1422 cruft_po_args
.quiet
= po_args
.quiet
;
1424 ret
= write_cruft_pack(&cruft_po_args
, packtmp
, pack_prefix
,
1426 combine_cruft_below_size
, &names
,
1431 if (delete_redundant
&& expire_to
) {
1433 * If `--expire-to` is given with `-d`, it's possible
1434 * that we're about to prune some objects. With cruft
1435 * packs, pruning is implicit: any objects from existing
1436 * packs that weren't picked up by new packs are removed
1437 * when their packs are deleted.
1439 * Generate an additional cruft pack, with one twist:
1440 * `names` now includes the name of the cruft pack
1441 * written in the previous step. So the contents of
1442 * _this_ cruft pack exclude everything contained in the
1443 * existing cruft pack (that is, all of the unreachable
1444 * objects which are no older than
1445 * `--cruft-expiration`).
1447 * To make this work, cruft_expiration must become NULL
1448 * so that this cruft pack doesn't actually prune any
1449 * objects. If it were non-NULL, this call would always
1450 * generate an empty pack (since every object not in the
1451 * cruft pack generated above will have an mtime older
1452 * than the expiration).
1454 * Pretend we don't have a `--combine-cruft-below-size`
1455 * argument, since we're not selectively combining
1456 * anything based on size to generate the limbo cruft
1457 * pack, but rather removing all cruft packs from the
1458 * main repository regardless of size.
1460 ret
= write_cruft_pack(&cruft_po_args
, expire_to
,
1471 if (po_args
.filter_options
.choice
) {
1473 filter_to
= packtmp
;
1475 ret
= write_filtered_pack(&po_args
,
1477 find_pack_prefix(packdir
, packtmp
),
1484 string_list_sort(&names
);
1486 close_object_store(the_repository
->objects
);
1489 * Ok we have prepared all new packfiles.
1491 for_each_string_list_item(item
, &names
) {
1492 struct generated_pack_data
*data
= item
->util
;
1494 for (ext
= 0; ext
< ARRAY_SIZE(exts
); ext
++) {
1497 fname
= mkpathdup("%s/pack-%s%s",
1498 packdir
, item
->string
, exts
[ext
].name
);
1500 if (data
->tempfiles
[ext
]) {
1501 const char *fname_old
= get_tempfile_path(data
->tempfiles
[ext
]);
1502 struct stat statbuffer
;
1504 if (!stat(fname_old
, &statbuffer
)) {
1505 statbuffer
.st_mode
&= ~(S_IWUSR
| S_IWGRP
| S_IWOTH
);
1506 chmod(fname_old
, statbuffer
.st_mode
);
1509 if (rename_tempfile(&data
->tempfiles
[ext
], fname
))
1510 die_errno(_("renaming pack to '%s' failed"), fname
);
1511 } else if (!exts
[ext
].optional
)
1512 die(_("pack-objects did not write a '%s' file for pack %s-%s"),
1513 exts
[ext
].name
, packtmp
, item
->string
);
1514 else if (unlink(fname
) < 0 && errno
!= ENOENT
)
1515 die_errno(_("could not unlink: %s"), fname
);
1520 /* End of pack replacement. */
1522 if (delete_redundant
&& pack_everything
& ALL_INTO_ONE
)
1523 mark_packs_for_deletion(&existing
, &names
);
1526 struct string_list include
= STRING_LIST_INIT_DUP
;
1527 midx_included_packs(&include
, &existing
, &names
, &geometry
);
1529 ret
= write_midx_included_packs(&include
, &geometry
, &names
,
1530 refs_snapshot
? get_tempfile_path(refs_snapshot
) : NULL
,
1531 show_progress
, write_bitmaps
> 0);
1533 if (!ret
&& write_bitmaps
)
1534 remove_redundant_bitmaps(&include
, packdir
);
1536 string_list_clear(&include
, 0);
1542 reprepare_packed_git(the_repository
);
1544 if (delete_redundant
) {
1546 remove_redundant_existing_packs(&existing
);
1548 if (geometry
.split_factor
)
1549 geometry_remove_redundant_packs(&geometry
, &names
,
1552 opts
|= PRUNE_PACKED_VERBOSE
;
1553 prune_packed_objects(opts
);
1555 if (!keep_unreachable
&&
1556 (!(pack_everything
& LOOSEN_UNREACHABLE
) ||
1557 unpack_unreachable
) &&
1558 is_repository_shallow(the_repository
))
1559 prune_shallow(PRUNE_QUICK
);
1562 if (run_update_server_info
)
1563 update_server_info(the_repository
, 0);
1565 if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX
, 0)) {
1567 if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL
, 0))
1568 flags
|= MIDX_WRITE_INCREMENTAL
;
1569 write_midx_file(the_repository
, repo_get_object_directory(the_repository
),
1574 string_list_clear(&keep_pack_list
, 0);
1575 string_list_clear(&names
, 1);
1576 existing_packs_release(&existing
);
1577 free_pack_geometry(&geometry
);
1578 pack_objects_args_release(&po_args
);
1579 pack_objects_args_release(&cruft_po_args
);