userdiff: add a builtin pattern for dts files
[gitweb.git] / t / t5319-multi-pack-index.sh
index 1ebf19ec3cd559dbf9ae7205a225d6e49368a8d2..c72ca0439993bb25b3d0e25fa2ce5d399b49a2b7 100755 (executable)
@@ -363,4 +363,188 @@ test_expect_success 'verify incorrect 64-bit offset' '
                "incorrect object offset"
 '
 
+test_expect_success 'setup expire tests' '
+       mkdir dup &&
+       (
+               cd dup &&
+               git init &&
+               test-tool genrandom "data" 4096 >large_file.txt &&
+               git update-index --add large_file.txt &&
+               for i in $(test_seq 1 20)
+               do
+                       test_commit $i
+               done &&
+               git branch A HEAD &&
+               git branch B HEAD~8 &&
+               git branch C HEAD~13 &&
+               git branch D HEAD~16 &&
+               git branch E HEAD~18 &&
+               git pack-objects --revs .git/objects/pack/pack-A <<-EOF &&
+               refs/heads/A
+               ^refs/heads/B
+               EOF
+               git pack-objects --revs .git/objects/pack/pack-B <<-EOF &&
+               refs/heads/B
+               ^refs/heads/C
+               EOF
+               git pack-objects --revs .git/objects/pack/pack-C <<-EOF &&
+               refs/heads/C
+               ^refs/heads/D
+               EOF
+               git pack-objects --revs .git/objects/pack/pack-D <<-EOF &&
+               refs/heads/D
+               ^refs/heads/E
+               EOF
+               git pack-objects --revs .git/objects/pack/pack-E <<-EOF &&
+               refs/heads/E
+               EOF
+               git multi-pack-index write &&
+               cp -r .git/objects/pack .git/objects/pack-backup
+       )
+'
+
+test_expect_success 'expire does not remove any packs' '
+       (
+               cd dup &&
+               ls .git/objects/pack >expect &&
+               git multi-pack-index expire &&
+               ls .git/objects/pack >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'expire removes unreferenced packs' '
+       (
+               cd dup &&
+               git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
+               refs/heads/A
+               ^refs/heads/C
+               EOF
+               git multi-pack-index write &&
+               ls .git/objects/pack | grep -v -e pack-[AB] >expect &&
+               git multi-pack-index expire &&
+               ls .git/objects/pack >actual &&
+               test_cmp expect actual &&
+               ls .git/objects/pack/ | grep idx >expect-idx &&
+               test-tool read-midx .git/objects | grep idx >actual-midx &&
+               test_cmp expect-idx actual-midx &&
+               git multi-pack-index verify &&
+               git fsck
+       )
+'
+
+test_expect_success 'repack with minimum size does not alter existing packs' '
+       (
+               cd dup &&
+               rm -rf .git/objects/pack &&
+               mv .git/objects/pack-backup .git/objects/pack &&
+               touch -m -t 201901010000 .git/objects/pack/pack-D* &&
+               touch -m -t 201901010001 .git/objects/pack/pack-C* &&
+               touch -m -t 201901010002 .git/objects/pack/pack-B* &&
+               touch -m -t 201901010003 .git/objects/pack/pack-A* &&
+               ls .git/objects/pack >expect &&
+               MINSIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 1) &&
+               git multi-pack-index repack --batch-size=$MINSIZE &&
+               ls .git/objects/pack >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'repack creates a new pack' '
+       (
+               cd dup &&
+               ls .git/objects/pack/*idx >idx-list &&
+               test_line_count = 5 idx-list &&
+               THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 3 | tail -n 1) &&
+               BATCH_SIZE=$(($THIRD_SMALLEST_SIZE + 1)) &&
+               git multi-pack-index repack --batch-size=$BATCH_SIZE &&
+               ls .git/objects/pack/*idx >idx-list &&
+               test_line_count = 6 idx-list &&
+               test-tool read-midx .git/objects | grep idx >midx-list &&
+               test_line_count = 6 midx-list
+       )
+'
+
+test_expect_success 'expire removes repacked packs' '
+       (
+               cd dup &&
+               ls -al .git/objects/pack/*pack &&
+               ls -S .git/objects/pack/*pack | head -n 4 >expect &&
+               git multi-pack-index expire &&
+               ls -S .git/objects/pack/*pack >actual &&
+               test_cmp expect actual &&
+               test-tool read-midx .git/objects | grep idx >midx-list &&
+               test_line_count = 4 midx-list
+       )
+'
+
+test_expect_success 'expire works when adding new packs' '
+       (
+               cd dup &&
+               git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
+               refs/heads/A
+               ^refs/heads/B
+               EOF
+               git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
+               refs/heads/B
+               ^refs/heads/C
+               EOF
+               git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
+               refs/heads/C
+               ^refs/heads/D
+               EOF
+               git multi-pack-index write &&
+               git pack-objects --revs .git/objects/pack/a-pack <<-EOF &&
+               refs/heads/D
+               ^refs/heads/E
+               EOF
+               git multi-pack-index write &&
+               git pack-objects --revs .git/objects/pack/z-pack <<-EOF &&
+               refs/heads/E
+               EOF
+               git multi-pack-index expire &&
+               ls .git/objects/pack/ | grep idx >expect &&
+               test-tool read-midx .git/objects | grep idx >actual &&
+               test_cmp expect actual &&
+               git multi-pack-index verify
+       )
+'
+
+test_expect_success 'expire respects .keep files' '
+       (
+               cd dup &&
+               git pack-objects --revs .git/objects/pack/pack-all <<-EOF &&
+               refs/heads/A
+               EOF
+               git multi-pack-index write &&
+               PACKA=$(ls .git/objects/pack/a-pack*\.pack | sed s/\.pack\$//) &&
+               touch $PACKA.keep &&
+               git multi-pack-index expire &&
+               ls -S .git/objects/pack/a-pack* | grep $PACKA >a-pack-files &&
+               test_line_count = 3 a-pack-files &&
+               test-tool read-midx .git/objects | grep idx >midx-list &&
+               test_line_count = 2 midx-list
+       )
+'
+
+test_expect_success 'repack --batch-size=0 repacks everything' '
+       (
+               cd dup &&
+               rm .git/objects/pack/*.keep &&
+               ls .git/objects/pack/*idx >idx-list &&
+               test_line_count = 2 idx-list &&
+               git multi-pack-index repack --batch-size=0 &&
+               ls .git/objects/pack/*idx >idx-list &&
+               test_line_count = 3 idx-list &&
+               test-tool read-midx .git/objects | grep idx >midx-list &&
+               test_line_count = 3 midx-list &&
+               git multi-pack-index expire &&
+               ls -al .git/objects/pack/*idx >idx-list &&
+               test_line_count = 1 idx-list &&
+               git multi-pack-index repack --batch-size=0 &&
+               ls -al .git/objects/pack/*idx >new-idx-list &&
+               test_cmp idx-list new-idx-list
+       )
+'
+
 test_done