Skip to content

Commit fc23c39

Browse files
committed
Merge branch 'tb/enable-cruft-packs-by-default'
When "gc" needs to retain unreachable objects, packing them into cruft packs (instead of exploding them into loose object files) has been offered as a more efficient option for some time. Now the use of cruft packs has been made the default and no longer considered an experimental feature. * tb/enable-cruft-packs-by-default: repository.h: drop unused `gc_cruft_packs` builtin/gc.c: make `gc.cruftPacks` enabled by default t/t9300-fast-import.sh: prepare for `gc --cruft` by default t/t6500-gc.sh: add additional test cases t/t6500-gc.sh: refactor cruft pack tests t/t6501-freshen-objects.sh: prepare for `gc --cruft` by default t/t5304-prune.sh: prepare for `gc --cruft` by default builtin/gc.c: ignore cruft packs with `--keep-largest-pack` builtin/repack.c: fix incorrect reference to '-C' pack-write.c: plug a leak in stage_tmp_packfiles()
2 parents f85cd43 + 029a632 commit fc23c39

File tree

13 files changed

+118
-125
lines changed

13 files changed

+118
-125
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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ gc.autoDetach::
4343
if the system supports it. Default is true.
4444

4545
gc.bigPackThreshold::
46-
If non-zero, all packs larger than this limit are kept when
47-
`git gc` is run. This is very similar to `--keep-largest-pack`
48-
except that all packs that meet the threshold are kept, not
49-
just the largest pack. Defaults to zero. Common unit suffixes of
50-
'k', 'm', or 'g' are supported.
46+
If non-zero, all non-cruft packs larger than this limit are kept
47+
when `git gc` is run. This is very similar to
48+
`--keep-largest-pack` except that all non-cruft packs that meet
49+
the threshold are kept, not just the largest pack. Defaults to
50+
zero. Common unit suffixes of 'k', 'm', or 'g' are supported.
5151
+
5252
Note that if the number of kept packs is more than gc.autoPackLimit,
5353
this configuration variable is ignored, all packs except the base pack
@@ -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: 7 additions & 5 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,
@@ -77,9 +78,10 @@ be performed as well.
7778
instance running on this repository.
7879

7980
--keep-largest-pack::
80-
All packs except the largest pack and those marked with a
81-
`.keep` files are consolidated into a single pack. When this
82-
option is used, `gc.bigPackThreshold` is ignored.
81+
All packs except the largest non-cruft pack, any packs marked
82+
with a `.keep` file, and any cruft pack(s) are consolidated into
83+
a single pack. When this option is used, `gc.bigPackThreshold`
84+
is ignored.
8385

8486
AGGRESSIVE
8587
----------

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: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static const char * const builtin_gc_usage[] = {
5050

5151
static int pack_refs = 1;
5252
static int prune_reflogs = 1;
53-
static int cruft_packs = -1;
53+
static int cruft_packs = 1;
5454
static int aggressive_depth = 50;
5555
static int aggressive_window = 250;
5656
static int gc_auto_threshold = 6700;
@@ -221,7 +221,7 @@ static struct packed_git *find_base_packs(struct string_list *packs,
221221
struct packed_git *p, *base = NULL;
222222

223223
for (p = get_all_packs(the_repository); p; p = p->next) {
224-
if (!p->pack_local)
224+
if (!p->pack_local || p->is_cruft)
225225
continue;
226226
if (limit) {
227227
if (p->pack_size >= limit)
@@ -610,10 +610,6 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
610610
if (prune_expire && parse_expiry_date(prune_expire, &dummy))
611611
die(_("failed to parse prune expiry value %s"), prune_expire);
612612

613-
prepare_repo_settings(the_repository);
614-
if (cruft_packs < 0)
615-
cruft_packs = the_repository->settings.gc_cruft_packs;
616-
617613
if (aggressive) {
618614
strvec_push(&repack, "-f");
619615
if (aggressive_depth > 0)

builtin/repack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
810810
N_("same as -a, pack unreachable cruft objects separately"),
811811
PACK_CRUFT),
812812
OPT_STRING(0, "cruft-expiration", &cruft_expiration, N_("approxidate"),
813-
N_("with -C, expire objects older than this")),
813+
N_("with --cruft, expire objects older than this")),
814814
OPT_BOOL('d', NULL, &delete_redundant,
815815
N_("remove redundant packs, and run git-prune-packed")),
816816
OPT_BOOL('f', NULL, &po_args.no_reuse_delta,

pack-write.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,13 @@ static void write_mtimes_trailer(struct hashfile *f, const unsigned char *hash)
314314
hashwrite(f, hash, the_hash_algo->rawsz);
315315
}
316316

317-
static const char *write_mtimes_file(struct packing_data *to_pack,
318-
struct pack_idx_entry **objects,
319-
uint32_t nr_objects,
320-
const unsigned char *hash)
317+
static char *write_mtimes_file(struct packing_data *to_pack,
318+
struct pack_idx_entry **objects,
319+
uint32_t nr_objects,
320+
const unsigned char *hash)
321321
{
322322
struct strbuf tmp_file = STRBUF_INIT;
323-
const char *mtimes_name;
323+
char *mtimes_name;
324324
struct hashfile *f;
325325
int fd;
326326

@@ -546,7 +546,7 @@ void stage_tmp_packfiles(struct strbuf *name_buffer,
546546
char **idx_tmp_name)
547547
{
548548
const char *rev_tmp_name = NULL;
549-
const char *mtimes_tmp_name = NULL;
549+
char *mtimes_tmp_name = NULL;
550550

551551
if (adjust_shared_perm(pack_tmp_name))
552552
die_errno("unable to make temporary pack file readable");
@@ -572,6 +572,7 @@ void stage_tmp_packfiles(struct strbuf *name_buffer,
572572
rename_tmp_packfile(name_buffer, mtimes_tmp_name, "mtimes");
573573

574574
free((char *)rev_tmp_name);
575+
free(mtimes_tmp_name);
575576
}
576577

577578
void write_promisor_file(const char *promisor_name, struct ref **sought, int nr_sought)

repo-settings.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ void prepare_repo_settings(struct repository *r)
4141
repo_cfg_bool(r, "feature.experimental", &experimental, 0);
4242

4343
/* Defaults modified by feature.* */
44-
if (experimental) {
44+
if (experimental)
4545
r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
46-
r->settings.gc_cruft_packs = 1;
47-
}
4846
if (manyfiles) {
4947
r->settings.index_version = 4;
5048
r->settings.index_skip_hash = 1;

repository.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ struct repo_settings {
3333
int commit_graph_generation_version;
3434
int commit_graph_read_changed_paths;
3535
int gc_write_commit_graph;
36-
int gc_cruft_packs;
3736
int fetch_write_commit_graph;
3837
int command_requires_full_index;
3938
int sparse_index;

t/t5304-prune.sh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ test_expect_success 'prune --expire' '
6262
test_expect_success 'gc: implicit prune --expire' '
6363
add_blob &&
6464
test-tool chmtime =-$((2*$week-30)) $BLOB_FILE &&
65-
git gc &&
65+
git gc --no-cruft &&
6666
verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
6767
test_path_is_file $BLOB_FILE &&
6868
test-tool chmtime =-$((2*$week+1)) $BLOB_FILE &&
69-
git gc &&
69+
git gc --no-cruft &&
7070
verbose test $before = $(git count-objects | sed "s/ .*//") &&
7171
test_path_is_missing $BLOB_FILE
7272
'
@@ -86,7 +86,7 @@ test_expect_success 'gc: refuse to start with invalid gc.pruneExpire' '
8686

8787
test_expect_success 'gc: start with ok gc.pruneExpire' '
8888
git config gc.pruneExpire 2.days.ago &&
89-
git gc
89+
git gc --no-cruft
9090
'
9191

9292
test_expect_success 'prune: prune nonsense parameters' '
@@ -137,44 +137,44 @@ test_expect_success 'gc --no-prune' '
137137
add_blob &&
138138
test-tool chmtime =-$((5001*$day)) $BLOB_FILE &&
139139
git config gc.pruneExpire 2.days.ago &&
140-
git gc --no-prune &&
140+
git gc --no-prune --no-cruft &&
141141
verbose test 1 = $(git count-objects | sed "s/ .*//") &&
142142
test_path_is_file $BLOB_FILE
143143
'
144144

145145
test_expect_success 'gc respects gc.pruneExpire' '
146146
git config gc.pruneExpire 5002.days.ago &&
147-
git gc &&
147+
git gc --no-cruft &&
148148
test_path_is_file $BLOB_FILE &&
149149
git config gc.pruneExpire 5000.days.ago &&
150-
git gc &&
150+
git gc --no-cruft &&
151151
test_path_is_missing $BLOB_FILE
152152
'
153153

154154
test_expect_success 'gc --prune=<date>' '
155155
add_blob &&
156156
test-tool chmtime =-$((5001*$day)) $BLOB_FILE &&
157-
git gc --prune=5002.days.ago &&
157+
git gc --prune=5002.days.ago --no-cruft &&
158158
test_path_is_file $BLOB_FILE &&
159-
git gc --prune=5000.days.ago &&
159+
git gc --prune=5000.days.ago --no-cruft &&
160160
test_path_is_missing $BLOB_FILE
161161
'
162162

163163
test_expect_success 'gc --prune=never' '
164164
add_blob &&
165-
git gc --prune=never &&
165+
git gc --prune=never --no-cruft &&
166166
test_path_is_file $BLOB_FILE &&
167-
git gc --prune=now &&
167+
git gc --prune=now --no-cruft &&
168168
test_path_is_missing $BLOB_FILE
169169
'
170170

171171
test_expect_success 'gc respects gc.pruneExpire=never' '
172172
git config gc.pruneExpire never &&
173173
add_blob &&
174-
git gc &&
174+
git gc --no-cruft &&
175175
test_path_is_file $BLOB_FILE &&
176176
git config gc.pruneExpire now &&
177-
git gc &&
177+
git gc --no-cruft &&
178178
test_path_is_missing $BLOB_FILE
179179
'
180180

@@ -194,7 +194,7 @@ test_expect_success 'gc: prune old objects after local clone' '
194194
cd aclone &&
195195
verbose test 1 = $(git count-objects | sed "s/ .*//") &&
196196
test_path_is_file $BLOB_FILE &&
197-
git gc --prune &&
197+
git gc --prune --no-cruft &&
198198
verbose test 0 = $(git count-objects | sed "s/ .*//") &&
199199
test_path_is_missing $BLOB_FILE
200200
)
@@ -237,7 +237,7 @@ test_expect_success 'clean pack garbage with gc' '
237237
>.git/objects/pack/fake2.keep &&
238238
>.git/objects/pack/fake2.idx &&
239239
>.git/objects/pack/fake3.keep &&
240-
git gc &&
240+
git gc --no-cruft &&
241241
git count-objects -v 2>stderr &&
242242
grep "^warning:" stderr | sort >actual &&
243243
cat >expected <<\EOF &&

0 commit comments

Comments
 (0)