Skip to content

Commit

Permalink
builtin/repack.c: do not repack single packs with --geometric
Browse files Browse the repository at this point in the history
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 <gitster@pobox.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
ttaylorr authored and gitster committed Mar 5, 2021
1 parent 0fabafd commit f25e33c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion builtin/repack.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ static void split_pack_geometry(struct pack_geometry *geometry, int factor)
uint32_t split;
off_t total_size = 0;

if (geometry->pack_nr <= 1) {
if (!geometry->pack_nr) {
geometry->split = geometry->pack_nr;
return;
}
Expand Down
15 changes: 15 additions & 0 deletions t/t7703-repack-geometric.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ test_expect_success '--geometric with no packs' '
)
'

test_expect_success '--geometric with one pack' '
git init geometric &&
test_when_finished "rm -fr geometric" &&
(
cd geometric &&
test_commit "base" &&
git repack -d &&
git repack --geometric 2 >out &&
test_i18ngrep "Nothing new to pack" out
)
'

test_expect_success '--geometric with an intact progression' '
git init geometric &&
test_when_finished "rm -fr geometric" &&
Expand Down

0 comments on commit f25e33c

Please sign in to comment.