Skip to content

Commit e3e24de

Browse files
ttaylorrgitster
authored andcommitted
builtin/gc.c: make gc.cruftPacks enabled by default
Back in 5b92477 (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 a50036d (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 5b92477, 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c58100a commit e3e24de

File tree

6 files changed

+11
-21
lines changed

6 files changed

+11
-21
lines changed

Documentation/config/feature.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ feature.experimental::
1414
+
1515
* `fetch.negotiationAlgorithm=skipping` may improve fetch negotiation times by
1616
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.
2017

2118
feature.manyFiles::
2219
Enable config options that optimize for repos with many files in the

Documentation/config/gc.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ gc.packRefs::
8484
gc.cruftPacks::
8585
Store unreachable objects in a cruft pack (see
8686
linkgit:git-repack[1]) instead of as loose objects. The default
87-
is `false`.
87+
is `true`.
8888

8989
gc.pruneExpire::
9090
When 'git gc' is run, it will call 'prune --expire 2.weeks.ago'

Documentation/git-gc.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ other housekeeping tasks (e.g. rerere, working trees, reflog...) will
5454
be performed as well.
5555

5656

57-
--cruft::
57+
--[no-]cruft::
5858
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.
6061

6162
--prune=<date>::
6263
Prune loose objects older than date (default is 2 weeks ago,

Documentation/gitformat-pack.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,8 @@ result of repeatedly resetting the objects' mtimes to the present time.
611611

612612
If you are GC-ing repositories in a mixed version environment, consider omitting
613613
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.
616616

617617
=== Alternatives
618618

builtin/gc.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static const char * const builtin_gc_usage[] = {
4848

4949
static int pack_refs = 1;
5050
static int prune_reflogs = 1;
51-
static int cruft_packs = -1;
51+
static int cruft_packs = 1;
5252
static int aggressive_depth = 50;
5353
static int aggressive_window = 250;
5454
static int gc_auto_threshold = 6700;
@@ -608,10 +608,6 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
608608
if (prune_expire && parse_expiry_date(prune_expire, &dummy))
609609
die(_("failed to parse prune expiry value %s"), prune_expire);
610610

611-
prepare_repo_settings(the_repository);
612-
if (cruft_packs < 0)
613-
cruft_packs = the_repository->settings.gc_cruft_packs;
614-
615611
if (aggressive) {
616612
strvec_push(&repack, "-f");
617613
if (aggressive_depth > 0)

t/t6500-gc.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,9 @@ assert_no_cruft_packs () {
216216
}
217217

218218
for argv in \
219-
"gc --cruft" \
219+
"gc" \
220220
"-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"
224222
do
225223
test_expect_success "git $argv generates a cruft pack" '
226224
test_when_finished "rm -fr repo" &&
@@ -244,11 +242,9 @@ do
244242
done
245243

246244
for argv in \
247-
"gc" \
245+
"gc --no-cruft" \
248246
"-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"
252248
do
253249
test_expect_success "git $argv does not generate a cruft pack" '
254250
test_when_finished "rm -fr repo" &&

0 commit comments

Comments
 (0)