Skip to content

Commit ec9d465

Browse files
committed
Merge branch 'ds/midx-write-repack-fix'
Repacking a repository with multi-pack index started making stupid pack selections in Git 2.45, which has been corrected. * ds/midx-write-repack-fix: midx-write: revert use of --stdin-packs t5319: add failing test case for repack/expire
2 parents d19b6cd + 8fb6d11 commit ec9d465

File tree

2 files changed

+64
-9
lines changed

2 files changed

+64
-9
lines changed

midx-write.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,8 +1499,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
14991499
repo_config_get_bool(r, "repack.usedeltabaseoffset", &delta_base_offset);
15001500
repo_config_get_bool(r, "repack.usedeltaislands", &use_delta_islands);
15011501

1502-
strvec_pushl(&cmd.args, "pack-objects", "--stdin-packs", "--non-empty",
1503-
NULL);
1502+
strvec_push(&cmd.args, "pack-objects");
15041503

15051504
strvec_pushf(&cmd.args, "%s/pack/pack", object_dir);
15061505

@@ -1524,15 +1523,16 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
15241523
}
15251524

15261525
cmd_in = xfdopen(cmd.in, "w");
1527-
for (i = 0; i < m->num_packs; i++) {
1528-
struct packed_git *p = m->packs[i];
1529-
if (!p)
1526+
1527+
for (i = 0; i < m->num_objects; i++) {
1528+
struct object_id oid;
1529+
uint32_t pack_int_id = nth_midxed_pack_int_id(m, i);
1530+
1531+
if (!include_pack[pack_int_id])
15301532
continue;
15311533

1532-
if (include_pack[i])
1533-
fprintf(cmd_in, "%s\n", pack_basename(p));
1534-
else
1535-
fprintf(cmd_in, "^%s\n", pack_basename(p));
1534+
nth_midxed_object_oid(&oid, m, i);
1535+
fprintf(cmd_in, "%s\n", oid_to_hex(&oid));
15361536
}
15371537
fclose(cmd_in);
15381538

t/t5319-multi-pack-index.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,61 @@ test_expect_success 'repack --batch-size=<large> repacks everything' '
10271027
)
10281028
'
10291029

1030+
test_expect_success 'repack/expire loop' '
1031+
git init repack-expire &&
1032+
test_when_finished "rm -fr repack-expire" &&
1033+
(
1034+
cd repack-expire &&
1035+
1036+
test_commit_bulk 5 &&
1037+
1038+
# Create three overlapping pack-files
1039+
git rev-list --objects HEAD~3 >in-1 &&
1040+
git rev-list --objects HEAD~4..HEAD~2 >in-2 &&
1041+
git rev-list --objects HEAD~3..HEAD >in-3 &&
1042+
1043+
# Create disconnected blobs
1044+
obj1=$(git hash-object -w in-1) &&
1045+
obj2=$(git hash-object -w in-2) &&
1046+
obj3=$(git hash-object -w in-3) &&
1047+
1048+
echo $obj2 >>in-2 &&
1049+
echo $obj3 >>in-3 &&
1050+
1051+
for i in $(test_seq 3)
1052+
do
1053+
git pack-objects .git/objects/pack/test-$i <in-$i \
1054+
|| return 1
1055+
done &&
1056+
1057+
rm -fr .git/objects/pack/pack-* &&
1058+
git multi-pack-index write &&
1059+
1060+
for i in $(test_seq 3)
1061+
do
1062+
for file in $(ls .git/objects/pack/test-$i*)
1063+
do
1064+
test-tool chmtime =+$((3600*$i-25000)) $file || return 1
1065+
done || return 1
1066+
done &&
1067+
1068+
pack1=$(ls .git/objects/pack/test-1-*.pack) &&
1069+
pack2=$(ls .git/objects/pack/test-2-*.pack) &&
1070+
pack3=$(ls .git/objects/pack/test-3-*.pack) &&
1071+
1072+
# Prevent test-1 from being rewritten.
1073+
touch "${pack1%.pack}.keep" &&
1074+
1075+
# This repack-expire loop should repack all non-kept packs
1076+
# into a new pack and then delete the old packs.
1077+
git multi-pack-index repack &&
1078+
git multi-pack-index expire &&
1079+
1080+
test_path_is_missing $pack3 &&
1081+
test_path_is_missing $pack2
1082+
)
1083+
'
1084+
10301085
test_expect_success 'load reverse index when missing .idx, .pack' '
10311086
git init repo &&
10321087
test_when_finished "rm -fr repo" &&

0 commit comments

Comments
 (0)