Skip to content

Commit 8d41dbb

Browse files
ttaylorrgitster
authored andcommitted
builtin/repack.c: allow configuring cruft pack generation
In servers which set the pack.window configuration to a large value, we can wind up spending quite a lot of time finding new bases when breaking delta chains between reachable and unreachable objects while generating a cruft pack. Introduce a handful of `repack.cruft*` configuration variables to control the parameters used by pack-objects when generating a cruft pack. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f979bcd commit 8d41dbb

File tree

3 files changed

+128
-14
lines changed

3 files changed

+128
-14
lines changed

Documentation/config/repack.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,12 @@ repack.writeBitmaps::
2525
space and extra time spent on the initial repack. This has
2626
no effect if multiple packfiles are created.
2727
Defaults to true on bare repos, false otherwise.
28+
29+
repack.cruftWindow::
30+
repack.cruftWindowMemory::
31+
repack.cruftDepth::
32+
repack.cruftThreads::
33+
Parameters used by linkgit:git-pack-objects[1] when generating
34+
a cruft pack and the respective parameters are not given over
35+
the command line. See similarly named `pack.*` configuration
36+
variables for defaults and meaning.

builtin/repack.c

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,21 @@ static const char incremental_bitmap_conflict_error[] = N_(
4040
"--no-write-bitmap-index or disable the pack.writebitmaps configuration."
4141
);
4242

43+
struct pack_objects_args {
44+
const char *window;
45+
const char *window_memory;
46+
const char *depth;
47+
const char *threads;
48+
const char *max_pack_size;
49+
int no_reuse_delta;
50+
int no_reuse_object;
51+
int quiet;
52+
int local;
53+
};
4354

4455
static int repack_config(const char *var, const char *value, void *cb)
4556
{
57+
struct pack_objects_args *cruft_po_args = cb;
4658
if (!strcmp(var, "repack.usedeltabaseoffset")) {
4759
delta_base_offset = git_config_bool(var, value);
4860
return 0;
@@ -61,6 +73,15 @@ static int repack_config(const char *var, const char *value, void *cb)
6173
return 0;
6274
}
6375

76+
if (!strcmp(var, "repack.cruftwindow"))
77+
return git_config_string(&cruft_po_args->window, var, value);
78+
if (!strcmp(var, "repack.cruftwindowmemory"))
79+
return git_config_string(&cruft_po_args->window_memory, var, value);
80+
if (!strcmp(var, "repack.cruftdepth"))
81+
return git_config_string(&cruft_po_args->depth, var, value);
82+
if (!strcmp(var, "repack.cruftthreads"))
83+
return git_config_string(&cruft_po_args->threads, var, value);
84+
6485
return git_default_config(var, value, cb);
6586
}
6687

@@ -153,18 +174,6 @@ static void remove_redundant_pack(const char *dir_name, const char *base_name)
153174
strbuf_release(&buf);
154175
}
155176

156-
struct pack_objects_args {
157-
const char *window;
158-
const char *window_memory;
159-
const char *depth;
160-
const char *threads;
161-
const char *max_pack_size;
162-
int no_reuse_delta;
163-
int no_reuse_object;
164-
int quiet;
165-
int local;
166-
};
167-
168177
static void prepare_pack_objects(struct child_process *cmd,
169178
const struct pack_objects_args *args)
170179
{
@@ -689,6 +698,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
689698
struct string_list keep_pack_list = STRING_LIST_INIT_NODUP;
690699
int no_update_server_info = 0;
691700
struct pack_objects_args po_args = {NULL};
701+
struct pack_objects_args cruft_po_args = {NULL};
692702
int geometric_factor = 0;
693703
int write_midx = 0;
694704

@@ -743,7 +753,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
743753
OPT_END()
744754
};
745755

746-
git_config(repack_config, NULL);
756+
git_config(repack_config, &cruft_po_args);
747757

748758
argc = parse_options(argc, argv, prefix, builtin_repack_options,
749759
git_repack_usage, 0);
@@ -918,7 +928,19 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
918928
if (*pack_prefix == '/')
919929
pack_prefix++;
920930

921-
ret = write_cruft_pack(&po_args, pack_prefix, &names,
931+
if (!cruft_po_args.window)
932+
cruft_po_args.window = po_args.window;
933+
if (!cruft_po_args.window_memory)
934+
cruft_po_args.window_memory = po_args.window_memory;
935+
if (!cruft_po_args.depth)
936+
cruft_po_args.depth = po_args.depth;
937+
if (!cruft_po_args.threads)
938+
cruft_po_args.threads = po_args.threads;
939+
940+
cruft_po_args.local = po_args.local;
941+
cruft_po_args.quiet = po_args.quiet;
942+
943+
ret = write_cruft_pack(&cruft_po_args, pack_prefix, &names,
922944
&existing_nonkept_packs,
923945
&existing_kept_packs);
924946
if (ret)

t/t5329-pack-objects-cruft.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,4 +565,87 @@ test_expect_success 'cruft repack ignores pack.packSizeLimit' '
565565
)
566566
'
567567

568+
test_expect_success 'cruft repack respects repack.cruftWindow' '
569+
git init repo &&
570+
test_when_finished "rm -fr repo" &&
571+
(
572+
cd repo &&
573+
574+
test_commit base &&
575+
576+
GIT_TRACE2_EVENT=$(pwd)/event.trace \
577+
git -c pack.window=1 -c repack.cruftWindow=2 repack \
578+
--cruft --window=3 &&
579+
580+
grep "pack-objects.*--window=2.*--cruft" event.trace
581+
)
582+
'
583+
584+
test_expect_success 'cruft repack respects --window by default' '
585+
git init repo &&
586+
test_when_finished "rm -fr repo" &&
587+
(
588+
cd repo &&
589+
590+
test_commit base &&
591+
592+
GIT_TRACE2_EVENT=$(pwd)/event.trace \
593+
git -c pack.window=2 repack --cruft --window=3 &&
594+
595+
grep "pack-objects.*--window=3.*--cruft" event.trace
596+
)
597+
'
598+
599+
test_expect_success 'cruft repack respects --quiet' '
600+
git init repo &&
601+
test_when_finished "rm -fr repo" &&
602+
(
603+
cd repo &&
604+
605+
test_commit base &&
606+
GIT_PROGRESS_DELAY=0 git repack --cruft --quiet 2>err &&
607+
test_must_be_empty err
608+
)
609+
'
610+
611+
test_expect_success 'cruft --local drops unreachable objects' '
612+
git init alternate &&
613+
git init repo &&
614+
test_when_finished "rm -fr alternate repo" &&
615+
616+
test_commit -C alternate base &&
617+
# Pack all objects in alterate so that the cruft repack in "repo" sees
618+
# the object it dropped due to `--local` as packed. Otherwise this
619+
# object would not appear packed anywhere (since it is not packed in
620+
# alternate and likewise not part of the cruft pack in the other repo
621+
# because of `--local`).
622+
git -C alternate repack -ad &&
623+
624+
(
625+
cd repo &&
626+
627+
object="$(git -C ../alternate rev-parse HEAD:base.t)" &&
628+
git -C ../alternate cat-file -p $object >contents &&
629+
630+
# Write some reachable objects and two unreachable ones: one
631+
# that the alternate has and another that is unique.
632+
test_commit other &&
633+
git hash-object -w -t blob contents &&
634+
cruft="$(echo cruft | git hash-object -w -t blob --stdin)" &&
635+
636+
( cd ../alternate/.git/objects && pwd ) \
637+
>.git/objects/info/alternates &&
638+
639+
test_path_is_file $objdir/$(test_oid_to_path $cruft) &&
640+
test_path_is_file $objdir/$(test_oid_to_path $object) &&
641+
642+
git repack -d --cruft --local &&
643+
644+
test-tool pack-mtimes "$(basename $(ls $packdir/pack-*.mtimes))" \
645+
>objects &&
646+
! grep $object objects &&
647+
grep $cruft objects
648+
)
649+
'
650+
568651
test_done

0 commit comments

Comments
 (0)