Skip to content

Commit f25e33c

Browse files
ttaylorrgitster
authored andcommitted
builtin/repack.c: do not repack single packs with --geometric
In 0fabafd (builtin/repack.c: add '--geometric' option, 2021-02-22), the 'git repack --geometric' code aborts early when there is zero or one pack. When there are no packs, this code does the right thing by placing the split at "0". But when there is exactly one pack, the split is placed at "1", which means that "git repack --geometric" (with any factor) repacks all of the objects in a single pack. This is wasteful, and the remaining code in split_pack_geometry() does the right thing (not repacking the objects in a single pack) even when only one pack is present. Loosen the guard to only stop when there aren't any packs, and let the rest of the code do the right thing. Add a test to ensure that this is the case. Noticed-by: Junio C Hamano <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0fabafd commit f25e33c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

builtin/repack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ static void split_pack_geometry(struct pack_geometry *geometry, int factor)
351351
uint32_t split;
352352
off_t total_size = 0;
353353

354-
if (geometry->pack_nr <= 1) {
354+
if (!geometry->pack_nr) {
355355
geometry->split = geometry->pack_nr;
356356
return;
357357
}

t/t7703-repack-geometric.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ test_expect_success '--geometric with no packs' '
2020
)
2121
'
2222

23+
test_expect_success '--geometric with one pack' '
24+
git init geometric &&
25+
test_when_finished "rm -fr geometric" &&
26+
(
27+
cd geometric &&
28+
29+
test_commit "base" &&
30+
git repack -d &&
31+
32+
git repack --geometric 2 >out &&
33+
34+
test_i18ngrep "Nothing new to pack" out
35+
)
36+
'
37+
2338
test_expect_success '--geometric with an intact progression' '
2439
git init geometric &&
2540
test_when_finished "rm -fr geometric" &&

0 commit comments

Comments
 (0)