Skip to content

Commit 66731ff

Browse files
ttaylorrgitster
authored andcommitted
builtin/repack.c: ensure that names is sorted
The previous patch demonstrates a scenario where the list of packs written by `pack-objects` (and stored in the `names` string_list) is out-of-order, and can thus cause us to delete packs we shouldn't. This patch resolves that bug by ensuring that `names` is sorted in all cases, not just when delete_redundant && pack_everything & ALL_INTO_ONE is true. Because we did sort `names` in that case (which, prior to `--geometric` repacks, was the only time we would actually delete packs, this is only a bug for `--geometric` repacks. It would be sufficient to only sort `names` when `delete_redundant` is set to a non-zero value. But sorting a small list of strings is cheap, and it is defensive against future calls to `string_list_has_string()` on this list. Co-discovered-by: Victoria Dye <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aab7bea commit 66731ff

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

builtin/repack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
856856
if (!names.nr && !po_args.quiet)
857857
printf_ln(_("Nothing new to pack."));
858858

859+
string_list_sort(&names);
860+
859861
for_each_string_list_item(item, &names) {
860862
item->util = (void *)(uintptr_t)populate_pack_exts(item->string);
861863
}
@@ -896,7 +898,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
896898

897899
if (delete_redundant && pack_everything & ALL_INTO_ONE) {
898900
const int hexsz = the_hash_algo->hexsz;
899-
string_list_sort(&names);
900901
for_each_string_list_item(item, &existing_nonkept_packs) {
901902
char *sha1;
902903
size_t len = strlen(item->string);

t/t7703-repack-geometric.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ test_expect_success '--geometric chooses largest MIDX preferred pack' '
231231
)
232232
'
233233

234-
test_expect_failure '--geometric with pack.packSizeLimit' '
234+
test_expect_success '--geometric with pack.packSizeLimit' '
235235
git init pack-rewrite &&
236236
test_when_finished "rm -fr pack-rewrite" &&
237237
(

0 commit comments

Comments
 (0)