Git fork
at reftables-rust 141 lines 4.5 kB view raw
1#!/bin/sh 2 3test_description='pack-objects object selection using sparse algorithm' 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 6 7. ./test-lib.sh 8 9test_expect_success 'setup repo' ' 10 test_commit initial && 11 for i in $(test_seq 1 3) 12 do 13 mkdir f$i && 14 for j in $(test_seq 1 3) 15 do 16 mkdir f$i/f$j && 17 echo $j >f$i/f$j/data.txt || return 1 18 done 19 done && 20 git add . && 21 git commit -m "Initialized trees" && 22 for i in $(test_seq 1 3) 23 do 24 git checkout -b topic$i main && 25 echo change-$i >f$i/f$i/data.txt && 26 git commit -a -m "Changed f$i/f$i/data.txt" || return 1 27 done && 28 cat >packinput.txt <<-EOF && 29 topic1 30 ^topic2 31 ^topic3 32 EOF 33 git rev-parse \ 34 topic1 \ 35 topic1^{tree} \ 36 topic1:f1 \ 37 topic1:f1/f1 \ 38 topic1:f1/f1/data.txt | sort >expect_objects.txt 39' 40 41test_expect_success 'non-sparse pack-objects' ' 42 git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack && 43 git index-pack -o nonsparse.idx nonsparse.pack && 44 git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt && 45 test_cmp expect_objects.txt nonsparse_objects.txt 46' 47 48test_expect_success 'sparse pack-objects' ' 49 git pack-objects --stdout --revs --sparse <packinput.txt >sparse.pack && 50 git index-pack -o sparse.idx sparse.pack && 51 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt && 52 test_cmp expect_objects.txt sparse_objects.txt 53' 54 55test_expect_success 'duplicate a folder from f3 and commit to topic1' ' 56 git checkout topic1 && 57 echo change-3 >f3/f3/data.txt && 58 git commit -a -m "Changed f3/f3/data.txt" && 59 git rev-parse \ 60 topic1~1 \ 61 topic1~1^{tree} \ 62 topic1^{tree} \ 63 topic1 \ 64 topic1:f1 \ 65 topic1:f1/f1 \ 66 topic1:f1/f1/data.txt | sort >required_objects.txt 67' 68 69test_expect_success 'non-sparse pack-objects' ' 70 git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack && 71 git index-pack -o nonsparse.idx nonsparse.pack && 72 git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt && 73 comm -1 -2 required_objects.txt nonsparse_objects.txt >nonsparse_required_objects.txt && 74 test_cmp required_objects.txt nonsparse_required_objects.txt 75' 76 77test_expect_success 'sparse pack-objects' ' 78 git pack-objects --stdout --revs --sparse <packinput.txt >sparse.pack && 79 git index-pack -o sparse.idx sparse.pack && 80 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt && 81 comm -1 -2 required_objects.txt sparse_objects.txt >sparse_required_objects.txt && 82 test_cmp required_objects.txt sparse_required_objects.txt 83' 84 85# Demonstrate that the algorithms differ when we copy a tree wholesale 86# from one folder to another. 87 88test_expect_success 'duplicate a folder from f1 into f3' ' 89 mkdir f3/f4 && 90 cp -r f1/f1/* f3/f4 && 91 git add f3/f4 && 92 git commit -m "Copied f1/f1 to f3/f4" && 93 cat >packinput.txt <<-EOF && 94 topic1 95 ^topic1~1 96 EOF 97 git rev-parse \ 98 topic1 \ 99 topic1^{tree} \ 100 topic1:f3 | sort >required_objects.txt 101' 102 103test_expect_success 'non-sparse pack-objects' ' 104 git pack-objects --stdout --revs --no-sparse <packinput.txt >nonsparse.pack && 105 git index-pack -o nonsparse.idx nonsparse.pack && 106 git show-index <nonsparse.idx | awk "{print \$2}" >nonsparse_objects.txt && 107 comm -1 -2 required_objects.txt nonsparse_objects.txt >nonsparse_required_objects.txt && 108 test_cmp required_objects.txt nonsparse_required_objects.txt 109' 110 111# --sparse is enabled by default by pack.useSparse 112test_expect_success 'sparse pack-objects' ' 113 GIT_TEST_PACK_SPARSE=-1 && 114 git rev-parse \ 115 topic1 \ 116 topic1^{tree} \ 117 topic1:f3 \ 118 topic1:f3/f4 \ 119 topic1:f3/f4/data.txt | sort >expect_sparse_objects.txt && 120 git pack-objects --stdout --revs <packinput.txt >sparse.pack && 121 git index-pack -o sparse.idx sparse.pack && 122 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt && 123 test_cmp expect_sparse_objects.txt sparse_objects.txt 124' 125 126test_expect_success 'pack.useSparse enables algorithm' ' 127 git config pack.useSparse true && 128 git pack-objects --stdout --revs <packinput.txt >sparse.pack && 129 git index-pack -o sparse.idx sparse.pack && 130 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt && 131 test_cmp expect_sparse_objects.txt sparse_objects.txt 132' 133 134test_expect_success 'pack.useSparse overridden' ' 135 git pack-objects --stdout --revs --no-sparse <packinput.txt >sparse.pack && 136 git index-pack -o sparse.idx sparse.pack && 137 git show-index <sparse.idx | awk "{print \$2}" >sparse_objects.txt && 138 test_cmp required_objects.txt sparse_objects.txt 139' 140 141test_done