|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +test_description='git rev-list with object filtering' |
| 4 | + |
| 5 | +. ./test-lib.sh |
| 6 | + |
| 7 | +# test the omit-all filter |
| 8 | + |
| 9 | +test_expect_success 'setup' ' |
| 10 | + for n in 1 2 3 4 5 ; do \ |
| 11 | + echo $n > file.$n ; \ |
| 12 | + git add file.$n ; \ |
| 13 | + git commit -m "$n" ; \ |
| 14 | + done |
| 15 | +' |
| 16 | + |
| 17 | +test_expect_success 'omit-all-blobs omitted 5 blobs' ' |
| 18 | + git rev-list HEAD --objects --filter-print-manifest --filter-omit-all-blobs >filtered.output && |
| 19 | + grep "^~" filtered.output >blobs.omitted && |
| 20 | + test $(cat blobs.omitted | wc -l) = 5 |
| 21 | +' |
| 22 | + |
| 23 | +test_expect_success 'omit-all-blobs blob sha match' ' |
| 24 | + sed "s/~//" <blobs.omitted | awk "{print \$1;}" | sort >blobs.sha && |
| 25 | +
|
| 26 | + git rev-list HEAD --objects >normal.output && |
| 27 | + awk "/file/ {print \$1;}" <normal.output | sort >normal.sha && |
| 28 | + test_cmp blobs.sha normal.sha |
| 29 | +' |
| 30 | + |
| 31 | +test_expect_success 'omit-all-blobs nothing else changed' ' |
| 32 | + grep -v "file" <normal.output | sort >normal.other && |
| 33 | +
|
| 34 | + grep -v "~" <filtered.output | sort >filtered.other && |
| 35 | + test_cmp filtered.other normal.other |
| 36 | +' |
| 37 | + |
| 38 | +# test the size-based filtering. |
| 39 | + |
| 40 | +test_expect_success 'setup_large' ' |
| 41 | + for n in 1000 10000 ; do \ |
| 42 | + printf "%"$n"s" X > large.$n ; \ |
| 43 | + git add large.$n ; \ |
| 44 | + git commit -m "$n" ; \ |
| 45 | + done |
| 46 | +' |
| 47 | + |
| 48 | +test_expect_success 'omit-large-blobs omit 2 blobs' ' |
| 49 | + git rev-list HEAD --objects --filter-print-manifest --filter-omit-large-blobs=500 >filtered.output && |
| 50 | + grep "^~" filtered.output >blobs.omitted && |
| 51 | + test $(cat blobs.omitted | wc -l) = 2 |
| 52 | +' |
| 53 | + |
| 54 | +test_expect_success 'omit-large-blobs blob sha match' ' |
| 55 | + sed "s/~//" <blobs.omitted | awk "{print \$1;}" | sort >blobs.sha && |
| 56 | +
|
| 57 | + git rev-list HEAD --objects >normal.output && |
| 58 | + awk "/large/ {print \$1;}" <normal.output | sort >normal.sha && |
| 59 | + test_cmp blobs.sha normal.sha |
| 60 | +' |
| 61 | + |
| 62 | +test_expect_success 'omit-large-blobs nothing else changed' ' |
| 63 | + grep -v "large" <normal.output | sort >normal.other && |
| 64 | +
|
| 65 | + grep -v "~" <filtered.output | sort >filtered.other && |
| 66 | + test_cmp filtered.other normal.other |
| 67 | +' |
| 68 | + |
| 69 | +# boundary test around the size parameter. |
| 70 | +# filter is strictly less than the value, so size 500 and 1000 should have the |
| 71 | +# same results, but 1001 should filter more. |
| 72 | + |
| 73 | +test_expect_success 'omit-large-blobs omit 2 blobs' ' |
| 74 | + git rev-list HEAD --objects --filter-print-manifest --filter-omit-large-blobs=1000 >filtered.output && |
| 75 | + grep "^~" filtered.output >blobs.omitted && |
| 76 | + test $(cat blobs.omitted | wc -l) = 2 |
| 77 | +' |
| 78 | + |
| 79 | +test_expect_success 'omit-large-blobs omit 1 blob' ' |
| 80 | + git rev-list HEAD --objects --filter-print-manifest --filter-omit-large-blobs=1001 >filtered.output && |
| 81 | + grep "^~" filtered.output >blobs.omitted && |
| 82 | + test $(cat blobs.omitted | wc -l) = 1 |
| 83 | +' |
| 84 | + |
| 85 | +test_expect_success 'omit-large-blobs omit 1 blob (1k)' ' |
| 86 | + git rev-list HEAD --objects --filter-print-manifest --filter-omit-large-blobs=1k >filtered.output && |
| 87 | + grep "^~" filtered.output >blobs.omitted && |
| 88 | + test $(cat blobs.omitted | wc -l) = 1 |
| 89 | +' |
| 90 | + |
| 91 | +test_expect_success 'omit-large-blobs omit no blob (1m)' ' |
| 92 | + git rev-list HEAD --objects --filter-print-manifest --filter-omit-large-blobs=1m >filtered.output && |
| 93 | + test_must_fail grep "^~" filtered.output |
| 94 | +' |
| 95 | + |
| 96 | +# Test sparse-pattern filtering (using explicit local patterns). |
| 97 | +# We use the same disk format as sparse-checkout to specify the |
| 98 | +# filtering, but do not require sparse-checkout to be enabled. |
| 99 | + |
| 100 | +test_expect_success 'setup using sparse file' ' |
| 101 | + mkdir dir1 && |
| 102 | + for n in sparse1 sparse2 ; do \ |
| 103 | + echo $n > $n ; \ |
| 104 | + git add $n ; \ |
| 105 | + echo dir1/$n > dir1/$n ; \ |
| 106 | + git add dir1/$n ; \ |
| 107 | + done && |
| 108 | + git commit -m "sparse" && |
| 109 | + echo dir1/ >pattern1 && |
| 110 | + echo sparse1 >pattern2 |
| 111 | +' |
| 112 | + |
| 113 | +# pattern1 should only include the 2 dir1/* files. |
| 114 | +# and omit the 5 file.*, 2 large.*, and 2 top-level sparse* files. |
| 115 | +test_expect_success 'sparse using path pattern1' ' |
| 116 | + git rev-list HEAD --objects --filter-print-manifest --filter-use-path=pattern1 >filtered.output && |
| 117 | +
|
| 118 | + grep "^~" filtered.output >blobs.omitted && |
| 119 | + test $(cat blobs.omitted | wc -l) = 9 && |
| 120 | +
|
| 121 | + grep "dir1/sparse" filtered.output >blobs.included && |
| 122 | + test $(cat blobs.included | wc -l) = 2 |
| 123 | +' |
| 124 | + |
| 125 | +# pattern2 should include the sparse1 and dir1/sparse1. |
| 126 | +# and omit the 5 file.*, 2 large.*, and the 2 sparse2 files. |
| 127 | +test_expect_success 'sparse using path pattern2' ' |
| 128 | + git rev-list HEAD --objects --filter-print-manifest --filter-use-path=pattern2 >filtered.output && |
| 129 | +
|
| 130 | + grep "^~" filtered.output >blobs.omitted && |
| 131 | + test $(cat blobs.omitted | wc -l) = 9 && |
| 132 | +
|
| 133 | + grep "sparse1" filtered.output >blobs.included && |
| 134 | + test $(cat blobs.included | wc -l) = 2 |
| 135 | +' |
| 136 | + |
| 137 | +# Test sparse-pattern filtering (using a blob in the repo). |
| 138 | +# This could be used to later let pack-objects do filtering. |
| 139 | + |
| 140 | +# pattern1 should only include the 2 dir1/* files. |
| 141 | +# and omit the 5 file.*, 2 large.*, 2 top-level sparse*, and 1 pattern file. |
| 142 | +test_expect_success 'sparse using OID for pattern1' ' |
| 143 | + git add pattern1 && |
| 144 | + git commit -m "pattern1" && |
| 145 | +
|
| 146 | + git rev-list HEAD --objects >normal.output && |
| 147 | + grep "pattern1" <normal.output | awk "{print \$1;}" >pattern1.oid && |
| 148 | +
|
| 149 | + git rev-list HEAD --objects --filter-print-manifest --filter-use-blob=`cat pattern1.oid` >filtered.output && |
| 150 | +
|
| 151 | + grep "^~" filtered.output >blobs.omitted && |
| 152 | + test $(cat blobs.omitted | wc -l) = 10 && |
| 153 | +
|
| 154 | + grep "dir1/sparse" filtered.output >blobs.included && |
| 155 | + test $(cat blobs.included | wc -l) = 2 |
| 156 | +' |
| 157 | + |
| 158 | +# repeat previous test but use blob-ish expression rather than OID. |
| 159 | +test_expect_success 'sparse using blob-ish to get OID for pattern spec' ' |
| 160 | + git rev-list HEAD --objects --filter-print-manifest --filter-use-blob=HEAD:pattern1 >filtered.output && |
| 161 | +
|
| 162 | + grep "^~" filtered.output >blobs.omitted && |
| 163 | + test $(cat blobs.omitted | wc -l) = 10 && |
| 164 | +
|
| 165 | + grep "dir1/sparse" filtered.output >blobs.included && |
| 166 | + test $(cat blobs.included | wc -l) = 2 |
| 167 | +' |
| 168 | + |
| 169 | +# pattern2 should include the sparse1 and dir1/sparse1. |
| 170 | +# and omit the 5 file.*, 2 large.*, 2 top-level sparse*, and 2 pattern files. |
| 171 | +test_expect_success 'sparse using OID for pattern2' ' |
| 172 | + git add pattern2 && |
| 173 | + git commit -m "pattern2" && |
| 174 | +
|
| 175 | + git rev-list HEAD --objects >normal.output && |
| 176 | + grep "pattern2" <normal.output | awk "{print \$1;}" >pattern2.oid && |
| 177 | +
|
| 178 | + git rev-list HEAD --objects --filter-print-manifest --filter-use-blob=`cat pattern2.oid` >filtered.output && |
| 179 | +
|
| 180 | + grep "^~" filtered.output >blobs.omitted && |
| 181 | + test $(cat blobs.omitted | wc -l) = 11 && |
| 182 | +
|
| 183 | + grep "sparse1" filtered.output >blobs.included && |
| 184 | + test $(cat blobs.included | wc -l) = 2 |
| 185 | +' |
| 186 | + |
| 187 | +# repeat previous test but use blob-ish expression rather than OID. |
| 188 | +test_expect_success 'sparse using blob-ish rather than OID for pattern2' ' |
| 189 | + git rev-list HEAD --objects --filter-print-manifest --filter-use-blob=HEAD:pattern2 >filtered.output && |
| 190 | +
|
| 191 | + grep "^~" filtered.output >blobs.omitted && |
| 192 | + test $(cat blobs.omitted | wc -l) = 11 && |
| 193 | +
|
| 194 | + grep "sparse1" filtered.output >blobs.included && |
| 195 | + test $(cat blobs.included | wc -l) = 2 |
| 196 | +' |
| 197 | + |
| 198 | +test_done |
0 commit comments