diff --git a/Documentation/config/maintenance.adoc b/Documentation/config/maintenance.adoc index 26dc5de423..45fdafc2c6 100644 --- a/Documentation/config/maintenance.adoc +++ b/Documentation/config/maintenance.adoc @@ -86,6 +86,11 @@ maintenance.geometric-repack.auto:: objects that would be written into a new packfile. The default value is 100. +maintenance.geometric-repack.splitFactor:: + This integer config option controls the factor used for the geometric + sequence. See the `--geometric=` option in linkgit:git-repack[1] for + more details. Defaults to `2`. + maintenance.reflog-expire.auto:: This integer config option controls how often the `reflog-expire` task should be run as part of `git maintenance run --auto`. If zero, then diff --git a/builtin/gc.c b/builtin/gc.c index 2c9ecd464d..fb1a82e030 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1582,6 +1582,9 @@ static int maintenance_task_geometric_repack(struct maintenance_run_opts *opts, struct child_process child = CHILD_PROCESS_INIT; int ret; + repo_config_get_int(the_repository, "maintenance.geometric-repack.splitFactor", + &geometry.split_factor); + existing_packs.repo = the_repository; existing_packs_collect(&existing_packs, &kept_packs); pack_geometry_init(&geometry, &existing_packs, &po_args); @@ -1591,7 +1594,8 @@ static int maintenance_task_geometric_repack(struct maintenance_run_opts *opts, strvec_pushl(&child.args, "repack", "-d", "-l", NULL); if (geometry.split < geometry.pack_nr) - strvec_push(&child.args, "--geometric=2"); + strvec_pushf(&child.args, "--geometric=%d", + geometry.split_factor); else add_repack_all_option(cfg, NULL, &child.args); if (opts->quiet) @@ -1632,6 +1636,9 @@ static int geometric_repack_auto_condition(struct gc_config *cfg UNUSED) if (auto_value < 0) return 1; + repo_config_get_int(the_repository, "maintenance.geometric-repack.splitFactor", + &geometry.split_factor); + existing_packs.repo = the_repository; existing_packs_collect(&existing_packs, &kept_packs); pack_geometry_init(&geometry, &existing_packs, &po_args); diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index ace0ba8300..e0352fd196 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -603,6 +603,38 @@ test_expect_success 'geometric repacking with --auto' ' ) ' +test_expect_success 'geometric repacking honors configured split factor' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + git config set maintenance.auto false && + + # Create three different packs with 9, 2 and 1 object, respectively. + # This is done so that only a subset of packs would be merged + # together so that we can verify that `git repack` receives the + # correct geometric factor. + for i in $(test_seq 9) + do + echo first-$i | git hash-object -w --stdin -t blob || return 1 + done && + git repack --geometric=2 -d && + + for i in $(test_seq 2) + do + echo second-$i | git hash-object -w --stdin -t blob || return 1 + done && + git repack --geometric=2 -d && + + echo third | git hash-object -w --stdin -t blob && + git repack --geometric=2 -d && + + test_geometric_repack_needed false splitFactor=2 && + test_geometric_repack_needed true splitFactor=3 && + test_subcommand git repack -d -l --geometric=3 --quiet --write-midx