Skip to content

Commit facedc7

Browse files
SiddharthShrimaligitster
authored andcommitted
repack: do not rebuild packs on --dry-run
"git repack --drop-filtered --dry-run" is documented to list the objects that would be dropped "without rebuilding any pack or deleting anything", but it does both. This is a bug in cmd_repack(): after printing the candidates, the --dry-run block falls through into the regular repack code. repack_promisor_objects() writes a new promisor pack, and with -d, existing_packs_remove_redundant() deletes the old packs. The existing guard only skips the implied "delete_redundant = 1", so it does not stop an explicit -d, and it does not stop the new pack from being written either. This has been broken since --dry-run was introduced in 1e746b0 (builtin/repack: add --drop-filtered and --dry-run options). The --dry-run block never returned early, so a dry run has always gone on to do a regular repack. It was not broken by a later change. Fix it by returning right after the candidates are listed, and add a test that checks the pack directory is unchanged with and without -d. A dry run can no longer get past that point, so the two "!dry_run" checks that tried to keep it from deleting or dropping anything are now redundant. Reported-by: Coy Geek <coygeek@gmail.com> Helped-by: D. Ben Knoble <ben.knoble@gmail.com> Helped-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent a018953 commit facedc7

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

‎builtin/repack.c‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,9 @@ int cmd_repack(int argc,
351351
/*
352352
* Dropping objects means rebuilding the promisor packs
353353
* without them and then removing the old packs, so the
354-
* redundant packs must be deleted. Imply -d on a real run.
354+
* redundant packs must be deleted. Imply -d.
355355
*/
356-
if (!dry_run)
357-
delete_redundant = 1;
356+
delete_redundant = 1;
358357

359358
ret = enumerate_promisor_blobs(repo, &po_args.filter_options, &drop_oids);
360359

@@ -391,6 +390,13 @@ int cmd_repack(int argc,
391390
oidset_iter_init(&drop_oids, &iter);
392391
while ((oid = oidset_iter_next(&iter)))
393392
printf("%s\n", oid_to_hex(oid));
393+
394+
/*
395+
* Only list the candidates to be dropped; skip
396+
* the actual repack
397+
*/
398+
ret = 0;
399+
goto cleanup;
394400
}
395401
}
396402

@@ -505,7 +511,7 @@ int cmd_repack(int argc,
505511

506512
if (pack_everything & ALL_INTO_ONE) {
507513
repack_promisor_objects(repo, &po_args, &names, packtmp,
508-
(drop_filtered && !dry_run) ? &drop_oids : NULL);
514+
drop_filtered ? &drop_oids : NULL);
509515

510516
if (existing_packs_has_non_kept(&existing) &&
511517
delete_redundant &&

‎t/t7706-repack-drop-filtered.sh‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,25 @@ test_expect_success '--dry-run does not remove the filtered objects' '
135135
git -C repo cat-file -e "$BIG"
136136
'
137137

138+
test_expect_success '--dry-run leaves the pack directory untouched' '
139+
BIG=$(cat big_oid) &&
140+
packdir=repo/.git/objects/pack &&
141+
142+
for opt in "" -d
143+
do
144+
ls $packdir >before &&
145+
146+
git -C repo -c repack.writeBitmaps=false \
147+
repack --drop-filtered --filter=blob:limit=1k \
148+
--dry-run -a $opt >out &&
149+
150+
ls $packdir >after &&
151+
test_cmp before after &&
152+
test_grep "$BIG" out &&
153+
git -C repo cat-file -e "$BIG" || return 1
154+
done
155+
'
156+
138157
test_expect_success '--drop-filtered removes the promisor blob locally' '
139158
BIG=$(cat big_oid) &&
140159
SMALL=$(cat small_oid) &&

0 commit comments

Comments
 (0)