builtin/gc.c: make `gc.cruftPacks` enabled by default

Back in 5b92477f89 (builtin/gc.c: conditionally avoid pruning objects via loose, 2022-05-20), `git gc` learned the `--cruft` option and `gc.cruftPacks` configuration to opt-in to writing cruft packs when collecting or pruning unreachable objects. Cruft packs were introduced with the merge in a50036da1a (Merge branch 'tb/cruft-packs', 2022-06-03). They address the problem of "loose object explosions", where Git will write out many individual loose objects when there is a large number of unreachable objects that have not yet aged past `--prune=<date>`. Instead of keeping track of those unreachable yet recent objects via their loose object file's mtime, cruft packs collect all unreachable objects into a single pack with a corresponding `*.mtimes` file that acts as a table to store the mtimes of all unreachable objects. This prevents the need to store unreachable objects as loose as they age out of the repository, and avoids the problem of loose object explosions. Beyond avoiding loose object explosions, cruft packs also act as a more efficient mechanism to store unreachable objects as they age out of a repository. This is because pairs of similar unreachable objects serve as delta bases for one another. In 5b92477f89, the feature was introduced as experimental. Since then, GitHub has been running these patches in every repository generating hundreds of millions of cruft packs along the way. The feature is battle-tested, and avoids many pathological cases such as above. Users who either run `git gc` manually, or via `git maintenance` can benefit from having cruft packs. As such, enable cruft pack generation to take place by default (by making `gc.cruftPacks` have the default of "true" rather than "false). Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Apr 18, 2023 at 16:40 UTC e3e24de1bf1fd443978015fe06bb523dc85a3086
6 files changed +11 -21
Documentation/config/feature.txt
-3
@@ -14,9 +14,6 @@ feature.experimental::
14 +
15 * `fetch.negotiationAlgorithm=skipping` may improve fetch negotiation times by
16 skipping more commits at a time, reducing the number of round trips.
17 -+
18 -* `gc.cruftPacks=true` reduces disk space used by unreachable objects during
19 -garbage collection, preventing loose object explosions.
17
18 feature.manyFiles::
19 Enable config options that optimize for repos with many files in the
Documentation/config/gc.txt
+1 -1
@@ -84,7 +84,7 @@ gc.packRefs::
84 gc.cruftPacks::
85 Store unreachable objects in a cruft pack (see
86 linkgit:git-repack[1]) instead of as loose objects. The default
87 - is `false`.
87 + is `true`.
88
89 gc.pruneExpire::
90 When 'git gc' is run, it will call 'prune --expire 2.weeks.ago'
Documentation/git-gc.txt
+3 -2
@@ -54,9 +54,10 @@ other housekeeping tasks (e.g. rerere, working trees, reflog...) will
54 be performed as well.
55
56
57 ---cruft::
57 +--[no-]cruft::
58 When expiring unreachable objects, pack them separately into a
59 - cruft pack instead of storing them as loose objects.
59 + cruft pack instead of storing them as loose objects. `--cruft`
60 + is on by default.
61
62 --prune=<date>::
63 Prune loose objects older than date (default is 2 weeks ago,
Documentation/gitformat-pack.txt
+2 -2
@@ -611,8 +611,8 @@ result of repeatedly resetting the objects' mtimes to the present time.
611
612 If you are GC-ing repositories in a mixed version environment, consider omitting
613 the `--cruft` option when using linkgit:git-repack[1] and linkgit:git-gc[1], and
614 -leaving the `gc.cruftPacks` configuration unset until all writers understand
615 -cruft packs.
614 +setting the `gc.cruftPacks` configuration to "false" until all writers
615 +understand cruft packs.
616
617 === Alternatives
618
builtin/gc.c
+1 -5
@@ -48,7 +48,7 @@ static const char * const builtin_gc_usage[] = {
48
49 static int pack_refs = 1;
50 static int prune_reflogs = 1;
51 -static int cruft_packs = -1;
51 +static int cruft_packs = 1;
52 static int aggressive_depth = 50;
53 static int aggressive_window = 250;
54 static int gc_auto_threshold = 6700;
@@ -608,10 +608,6 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
608 if (prune_expire && parse_expiry_date(prune_expire, &dummy))
609 die(_("failed to parse prune expiry value %s"), prune_expire);
610
611 - prepare_repo_settings(the_repository);
612 - if (cruft_packs < 0)
613 - cruft_packs = the_repository->settings.gc_cruft_packs;
614 -
611 if (aggressive) {
612 strvec_push(&repack, "-f");
613 if (aggressive_depth > 0)
t/t6500-gc.sh
+4 -8
@@ -216,11 +216,9 @@ assert_no_cruft_packs () {
216 }
217
218 for argv in \
219 - "gc --cruft" \
219 + "gc" \
220 "-c gc.cruftPacks=true gc" \
221 - "-c gc.cruftPacks=false gc --cruft" \
222 - "-c feature.experimental=true gc" \
223 - "-c gc.cruftPacks=true -c feature.experimental=false gc"
221 + "-c gc.cruftPacks=false gc --cruft"
222 do
223 test_expect_success "git $argv generates a cruft pack" '
224 test_when_finished "rm -fr repo" &&
@@ -244,11 +242,9 @@ do
242 done
243
244 for argv in \
247 - "gc" \
245 + "gc --no-cruft" \
246 "-c gc.cruftPacks=false gc" \
249 - "-c gc.cruftPacks=true gc --no-cruft" \
250 - "-c feature.expiremental=true -c gc.cruftPacks=false gc" \
251 - "-c feature.experimental=false gc"
247 + "-c gc.cruftPacks=true gc --no-cruft"
248 do
249 test_expect_success "git $argv does not generate a cruft pack" '
250 test_when_finished "rm -fr repo" &&