| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git rev-list using object filtering' |
| 4 | |
| 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | # Test the blob:none filter. |
| 11 | |
| 12 | test_expect_success 'setup r1' ' |
| 13 | echo "{print \$1}" >print_1.awk && |
| 14 | echo "{print \$2}" >print_2.awk && |
| 15 | |
| 16 | git init r1 && |
| 17 | for n in 1 2 3 4 5 |
| 18 | do |
| 19 | echo "This is file: $n" > r1/file.$n && |
| 20 | git -C r1 add file.$n && |
| 21 | git -C r1 commit -m "$n" || return 1 |
| 22 | done |
| 23 | ' |
| 24 | |
| 25 | test_expect_success 'verify blob:none omits all 5 blobs' ' |
| 26 | git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \ |
| 27 | >ls_files_result && |
| 28 | awk -f print_2.awk ls_files_result | |
| 29 | sort >expected && |
| 30 | |
| 31 | git -C r1 rev-list --quiet --objects --filter-print-omitted \ |
| 32 | --filter=blob:none HEAD >revs && |
| 33 | awk -f print_1.awk revs | |
| 34 | sed "s/~//" | |
| 35 | sort >observed && |
| 36 | |
| 37 | test_cmp expected observed |
| 38 | ' |
| 39 | |
| 40 | test_expect_success 'specify blob explicitly prevents filtering' ' |
| 41 | file_3=$(git -C r1 ls-files -s file.3 | |
| 42 | awk -f print_2.awk) && |
| 43 | |
| 44 | file_4=$(git -C r1 ls-files -s file.4 | |
| 45 | awk -f print_2.awk) && |
| 46 | |
| 47 | git -C r1 rev-list --objects --filter=blob:none HEAD $file_3 >observed && |
| 48 | grep "$file_3" observed && |
| 49 | ! grep "$file_4" observed |
| 50 | ' |
| 51 | |
| 52 | test_expect_success 'verify emitted+omitted == all' ' |
| 53 | git -C r1 rev-list --objects HEAD >revs && |
| 54 | awk -f print_1.awk revs | |
| 55 | sort >expected && |
| 56 | |
| 57 | git -C r1 rev-list --objects --filter-print-omitted --filter=blob:none \ |
| 58 | HEAD >revs && |
| 59 | awk -f print_1.awk revs | |
| 60 | sed "s/~//" | |
| 61 | sort >observed && |
| 62 | |
| 63 | test_cmp expected observed |
| 64 | ' |
| 65 | |
| 66 | |
| 67 | # Test blob:limit=<n>[kmg] filter. |
| 68 | # We boundary test around the size parameter. The filter is strictly less than |
| 69 | # the value, so size 500 and 1000 should have the same results, but 1001 should |
| 70 | # filter more. |
| 71 | |
| 72 | test_expect_success 'setup r2' ' |
| 73 | git init r2 && |
| 74 | for n in 1000 10000 |
| 75 | do |
| 76 | printf "%"$n"s" X > r2/large.$n && |
| 77 | git -C r2 add large.$n && |
| 78 | git -C r2 commit -m "$n" || return 1 |
| 79 | done |
| 80 | ' |
| 81 | |
| 82 | test_expect_success 'verify blob:limit=500 omits all blobs' ' |
| 83 | git -C r2 ls-files -s large.1000 large.10000 >ls_files_result && |
| 84 | awk -f print_2.awk ls_files_result | |
| 85 | sort >expected && |
| 86 | |
| 87 | git -C r2 rev-list --quiet --objects --filter-print-omitted \ |
| 88 | --filter=blob:limit=500 HEAD >revs && |
| 89 | awk -f print_1.awk revs | |
| 90 | sed "s/~//" | |
| 91 | sort >observed && |
| 92 | |
| 93 | test_cmp expected observed |
| 94 | ' |
| 95 | |
| 96 | test_expect_success 'verify emitted+omitted == all' ' |
| 97 | git -C r2 rev-list --objects HEAD >revs && |
| 98 | awk -f print_1.awk revs | |
| 99 | sort >expected && |
| 100 | |
| 101 | git -C r2 rev-list --objects --filter-print-omitted \ |
| 102 | --filter=blob:limit=500 HEAD >revs && |
| 103 | awk -f print_1.awk revs | |
| 104 | sed "s/~//" | |
| 105 | sort >observed && |
| 106 | |
| 107 | test_cmp expected observed |
| 108 | ' |
| 109 | |
| 110 | test_expect_success 'verify blob:limit=1000' ' |
| 111 | git -C r2 ls-files -s large.1000 large.10000 >ls_files_result && |
| 112 | awk -f print_2.awk ls_files_result | |
| 113 | sort >expected && |
| 114 | |
| 115 | git -C r2 rev-list --quiet --objects --filter-print-omitted \ |
| 116 | --filter=blob:limit=1000 HEAD >revs && |
| 117 | awk -f print_1.awk revs | |
| 118 | sed "s/~//" | |
| 119 | sort >observed && |
| 120 | |
| 121 | test_cmp expected observed |
| 122 | ' |
| 123 | |
| 124 | test_expect_success 'verify blob:limit=1001' ' |
| 125 | git -C r2 ls-files -s large.10000 >ls_files_result && |
| 126 | awk -f print_2.awk ls_files_result | |
| 127 | sort >expected && |
| 128 | |
| 129 | git -C r2 rev-list --quiet --objects --filter-print-omitted \ |
| 130 | --filter=blob:limit=1001 HEAD >revs && |
| 131 | awk -f print_1.awk revs | |
| 132 | sed "s/~//" | |
| 133 | sort >observed && |
| 134 | |
| 135 | test_cmp expected observed |
| 136 | ' |
| 137 | |
| 138 | test_expect_success 'verify blob:limit=1k' ' |
| 139 | git -C r2 ls-files -s large.10000 >ls_files_result && |
| 140 | awk -f print_2.awk ls_files_result | |
| 141 | sort >expected && |
| 142 | |
| 143 | git -C r2 rev-list --quiet --objects --filter-print-omitted \ |
| 144 | --filter=blob:limit=1k HEAD >revs && |
| 145 | awk -f print_1.awk revs | |
| 146 | sed "s/~//" | |
| 147 | sort >observed && |
| 148 | |
| 149 | test_cmp expected observed |
| 150 | ' |
| 151 | |
| 152 | test_expect_success 'verify blob:limit=1m' ' |
| 153 | git -C r2 rev-list --quiet --objects --filter-print-omitted \ |
| 154 | --filter=blob:limit=1m HEAD >revs && |
| 155 | awk -f print_1.awk revs | |
| 156 | sed "s/~//" | |
| 157 | sort >observed && |
| 158 | |
| 159 | test_must_be_empty observed |
| 160 | ' |
| 161 | |
| 162 | # Test object:type=<type> filter. |
| 163 | |
| 164 | test_expect_success 'setup object-type' ' |
| 165 | test_create_repo object-type && |
| 166 | test_commit --no-tag -C object-type message blob && |
| 167 | git -C object-type tag tag -m tag-message |
| 168 | ' |
| 169 | |
| 170 | test_expect_success 'verify object:type= fails with invalid type' ' |
| 171 | test_must_fail git -C object-type rev-list --objects --filter=object:type= HEAD && |
| 172 | test_must_fail git -C object-type rev-list --objects --filter=object:type=invalid HEAD |
| 173 | ' |
| 174 | |
| 175 | test_expect_success 'verify object:type=blob prints blob and commit' ' |
| 176 | git -C object-type rev-parse HEAD >expected && |
| 177 | printf "%s blob\n" $(git -C object-type rev-parse HEAD:blob) >>expected && |
| 178 | git -C object-type rev-list --objects --filter=object:type=blob HEAD >actual && |
| 179 | test_cmp expected actual |
| 180 | ' |
| 181 | |
| 182 | test_expect_success 'verify object:type=tree prints tree and commit' ' |
| 183 | ( |
| 184 | git -C object-type rev-parse HEAD && |
| 185 | printf "%s \n" $(git -C object-type rev-parse HEAD^{tree}) |
| 186 | ) >expected && |
| 187 | git -C object-type rev-list --objects --filter=object:type=tree HEAD >actual && |
| 188 | test_cmp expected actual |
| 189 | ' |
| 190 | |
| 191 | test_expect_success 'verify object:type=commit prints commit' ' |
| 192 | git -C object-type rev-parse HEAD >expected && |
| 193 | git -C object-type rev-list --objects --filter=object:type=commit HEAD >actual && |
| 194 | test_cmp expected actual |
| 195 | ' |
| 196 | |
| 197 | test_expect_success 'verify object:type=tag prints tag' ' |
| 198 | ( |
| 199 | git -C object-type rev-parse HEAD && |
| 200 | printf "%s tag\n" $(git -C object-type rev-parse tag) |
| 201 | ) >expected && |
| 202 | git -C object-type rev-list --objects --filter=object:type=tag tag >actual && |
| 203 | test_cmp expected actual |
| 204 | ' |
| 205 | |
| 206 | test_expect_success 'verify object:type=blob prints only blob with --filter-provided-objects' ' |
| 207 | printf "%s blob\n" $(git -C object-type rev-parse HEAD:blob) >expected && |
| 208 | git -C object-type rev-list --objects \ |
| 209 | --filter=object:type=blob --filter-provided-objects HEAD >actual && |
| 210 | test_cmp expected actual |
| 211 | ' |
| 212 | |
| 213 | test_expect_success 'verify object:type=tree prints only tree with --filter-provided-objects' ' |
| 214 | printf "%s \n" $(git -C object-type rev-parse HEAD^{tree}) >expected && |
| 215 | git -C object-type rev-list --objects \ |
| 216 | --filter=object:type=tree HEAD --filter-provided-objects >actual && |
| 217 | test_cmp expected actual |
| 218 | ' |
| 219 | |
| 220 | test_expect_success 'verify object:type=commit prints only commit with --filter-provided-objects' ' |
| 221 | git -C object-type rev-parse HEAD >expected && |
| 222 | git -C object-type rev-list --objects \ |
| 223 | --filter=object:type=commit --filter-provided-objects HEAD >actual && |
| 224 | test_cmp expected actual |
| 225 | ' |
| 226 | |
| 227 | test_expect_success 'verify object:type=tag prints only tag with --filter-provided-objects' ' |
| 228 | printf "%s tag\n" $(git -C object-type rev-parse tag) >expected && |
| 229 | git -C object-type rev-list --objects \ |
| 230 | --filter=object:type=tag --filter-provided-objects tag >actual && |
| 231 | test_cmp expected actual |
| 232 | ' |
| 233 | |
| 234 | # Test sparse:path=<path> filter. |
| 235 | # !!!! |
| 236 | # NOTE: sparse:path filter support has been dropped for security reasons, |
| 237 | # so the tests have been changed to make sure that using it fails. |
| 238 | # !!!! |
| 239 | # Use a local file containing a sparse-checkout specification to filter |
| 240 | # out blobs not required for the corresponding sparse-checkout. We do not |
| 241 | # require sparse-checkout to actually be enabled. |
| 242 | |
| 243 | test_expect_success 'setup r3' ' |
| 244 | git init r3 && |
| 245 | mkdir r3/dir1 && |
| 246 | for n in sparse1 sparse2 |
| 247 | do |
| 248 | echo "This is file: $n" > r3/$n && |
| 249 | git -C r3 add $n && |
| 250 | echo "This is file: dir1/$n" > r3/dir1/$n && |
| 251 | git -C r3 add dir1/$n || return 1 |
| 252 | done && |
| 253 | git -C r3 commit -m "sparse" && |
| 254 | echo dir1/ >pattern1 && |
| 255 | echo sparse1 >pattern2 |
| 256 | ' |
| 257 | |
| 258 | test_expect_success 'verify sparse:path=pattern1 fails' ' |
| 259 | test_must_fail git -C r3 rev-list --quiet --objects \ |
| 260 | --filter-print-omitted --filter=sparse:path=../pattern1 HEAD |
| 261 | ' |
| 262 | |
| 263 | test_expect_success 'verify sparse:path=pattern2 fails' ' |
| 264 | test_must_fail git -C r3 rev-list --quiet --objects \ |
| 265 | --filter-print-omitted --filter=sparse:path=../pattern2 HEAD |
| 266 | ' |
| 267 | |
| 268 | # Test sparse:oid=<oid-ish> filter. |
| 269 | # Use a blob containing a sparse-checkout specification to filter |
| 270 | # out blobs not required for the corresponding sparse-checkout. We do not |
| 271 | # require sparse-checkout to actually be enabled. |
| 272 | |
| 273 | test_expect_success 'setup r3 part 2' ' |
| 274 | echo dir1/ >r3/pattern && |
| 275 | git -C r3 add pattern && |
| 276 | git -C r3 commit -m "pattern" |
| 277 | ' |
| 278 | |
| 279 | test_expect_success 'verify sparse:oid=OID omits top-level files' ' |
| 280 | git -C r3 ls-files -s pattern sparse1 sparse2 >ls_files_result && |
| 281 | awk -f print_2.awk ls_files_result | |
| 282 | sort >expected && |
| 283 | |
| 284 | oid=$(git -C r3 ls-files -s pattern | awk -f print_2.awk) && |
| 285 | |
| 286 | git -C r3 rev-list --quiet --objects --filter-print-omitted \ |
| 287 | --filter=sparse:oid=$oid HEAD >revs && |
| 288 | awk -f print_1.awk revs | |
| 289 | sed "s/~//" | |
| 290 | sort >observed && |
| 291 | |
| 292 | test_cmp expected observed |
| 293 | ' |
| 294 | |
| 295 | test_expect_success 'verify sparse:oid=oid-ish omits top-level files' ' |
| 296 | git -C r3 ls-files -s pattern sparse1 sparse2 >ls_files_result && |
| 297 | awk -f print_2.awk ls_files_result | |
| 298 | sort >expected && |
| 299 | |
| 300 | git -C r3 rev-list --quiet --objects --filter-print-omitted \ |
| 301 | --filter=sparse:oid=main:pattern HEAD >revs && |
| 302 | awk -f print_1.awk revs | |
| 303 | sed "s/~//" | |
| 304 | sort >observed && |
| 305 | |
| 306 | test_cmp expected observed |
| 307 | ' |
| 308 | |
| 309 | test_expect_success 'rev-list W/ --missing=print and --missing=allow-any for trees' ' |
| 310 | TREE=$(git -C r3 rev-parse HEAD:dir1) && |
| 311 | |
| 312 | # Create a spare repo because we will be deleting objects from this one. |
| 313 | git clone r3 r3.b && |
| 314 | |
| 315 | rm r3.b/.git/objects/$(echo $TREE | sed "s|^..|&/|") && |
| 316 | |
| 317 | git -C r3.b rev-list --quiet --missing=print --objects HEAD \ |
| 318 | >missing_objs 2>rev_list_err && |
| 319 | echo "?$TREE" >expected && |
| 320 | test_cmp expected missing_objs && |
| 321 | |
| 322 | # do not complain when a missing tree cannot be parsed |
| 323 | test_must_be_empty rev_list_err && |
| 324 | |
| 325 | git -C r3.b rev-list --missing=allow-any --objects HEAD \ |
| 326 | >objs 2>rev_list_err && |
| 327 | ! grep $TREE objs && |
| 328 | test_must_be_empty rev_list_err |
| 329 | ' |
| 330 | |
| 331 | # Test tree:0 filter. |
| 332 | |
| 333 | test_expect_success 'verify tree:0 includes trees in "filtered" output' ' |
| 334 | git -C r3 rev-list --quiet --objects --filter-print-omitted \ |
| 335 | --filter=tree:0 HEAD >revs && |
| 336 | |
| 337 | awk -f print_1.awk revs | |
| 338 | sed s/~// | |
| 339 | xargs -n1 git -C r3 cat-file -t >unsorted_filtered_types && |
| 340 | |
| 341 | sort -u unsorted_filtered_types >filtered_types && |
| 342 | test_write_lines blob tree >expected && |
| 343 | test_cmp expected filtered_types |
| 344 | ' |
| 345 | |
| 346 | # Make sure tree:0 does not iterate through any trees. |
| 347 | |
| 348 | test_expect_success 'verify skipping tree iteration when not collecting omits' ' |
| 349 | GIT_TRACE=1 git -C r3 rev-list \ |
| 350 | --objects --filter=tree:0 HEAD 2>filter_trace && |
| 351 | grep "Skipping contents of tree [.][.][.]" filter_trace >actual && |
| 352 | # One line for each commit traversed. |
| 353 | test_line_count = 2 actual && |
| 354 | |
| 355 | # Make sure no other trees were considered besides the root. |
| 356 | ! grep "Skipping contents of tree [^.]" filter_trace && |
| 357 | |
| 358 | # Try this again with "combine:". If both sub-filters are skipping |
| 359 | # trees, the composite filter should also skip trees. This is not |
| 360 | # important unless the user does combine:tree:X+tree:Y or another filter |
| 361 | # besides "tree:" is implemented in the future which can skip trees. |
| 362 | GIT_TRACE=1 git -C r3 rev-list \ |
| 363 | --objects --filter=combine:tree:1+tree:3 HEAD 2>filter_trace && |
| 364 | |
| 365 | # Only skip the dir1/ tree, which is shared between the two commits. |
| 366 | grep "Skipping contents of tree " filter_trace >actual && |
| 367 | test_write_lines "Skipping contents of tree dir1/..." >expected && |
| 368 | test_cmp expected actual |
| 369 | ' |
| 370 | |
| 371 | # Test tree:# filters. |
| 372 | |
| 373 | expect_has () { |
| 374 | commit=$1 && |
| 375 | name=$2 && |
| 376 | |
| 377 | hash=$(git -C r3 rev-parse $commit:$name) && |
| 378 | grep "^$hash $name$" actual |
| 379 | } |
| 380 | |
| 381 | test_expect_success 'verify tree:1 includes root trees' ' |
| 382 | git -C r3 rev-list --objects --filter=tree:1 HEAD >actual && |
| 383 | |
| 384 | # We should get two root directories and two commits. |
| 385 | expect_has HEAD "" && |
| 386 | expect_has HEAD~1 "" && |
| 387 | test_line_count = 4 actual |
| 388 | ' |
| 389 | |
| 390 | test_expect_success 'verify tree:2 includes root trees and immediate children' ' |
| 391 | git -C r3 rev-list --objects --filter=tree:2 HEAD >actual && |
| 392 | |
| 393 | expect_has HEAD "" && |
| 394 | expect_has HEAD~1 "" && |
| 395 | expect_has HEAD dir1 && |
| 396 | expect_has HEAD pattern && |
| 397 | expect_has HEAD sparse1 && |
| 398 | expect_has HEAD sparse2 && |
| 399 | |
| 400 | # There are also 2 commit objects |
| 401 | test_line_count = 8 actual |
| 402 | ' |
| 403 | |
| 404 | test_expect_success 'verify tree:3 includes everything expected' ' |
| 405 | git -C r3 rev-list --objects --filter=tree:3 HEAD >actual && |
| 406 | |
| 407 | expect_has HEAD "" && |
| 408 | expect_has HEAD~1 "" && |
| 409 | expect_has HEAD dir1 && |
| 410 | expect_has HEAD dir1/sparse1 && |
| 411 | expect_has HEAD dir1/sparse2 && |
| 412 | expect_has HEAD pattern && |
| 413 | expect_has HEAD sparse1 && |
| 414 | expect_has HEAD sparse2 && |
| 415 | |
| 416 | # There are also 2 commit objects |
| 417 | test_line_count = 10 actual |
| 418 | ' |
| 419 | |
| 420 | test_expect_success 'combine:... for a simple combination' ' |
| 421 | git -C r3 rev-list --objects --filter=combine:tree:2+blob:none HEAD \ |
| 422 | >actual && |
| 423 | |
| 424 | expect_has HEAD "" && |
| 425 | expect_has HEAD~1 "" && |
| 426 | expect_has HEAD dir1 && |
| 427 | |
| 428 | # There are also 2 commit objects |
| 429 | test_line_count = 5 actual && |
| 430 | |
| 431 | cp actual expected && |
| 432 | |
| 433 | # Try again using repeated --filter - this is equivalent to a manual |
| 434 | # combine with "combine:...+..." |
| 435 | git -C r3 rev-list --objects --filter=combine:tree:2 \ |
| 436 | --filter=blob:none HEAD >actual && |
| 437 | |
| 438 | test_cmp expected actual |
| 439 | ' |
| 440 | |
| 441 | test_expect_success 'combine:... with URL encoding' ' |
| 442 | git -C r3 rev-list --objects \ |
| 443 | --filter=combine:tree%3a2+blob:%6Eon%65 HEAD >actual && |
| 444 | |
| 445 | expect_has HEAD "" && |
| 446 | expect_has HEAD~1 "" && |
| 447 | expect_has HEAD dir1 && |
| 448 | |
| 449 | # There are also 2 commit objects |
| 450 | test_line_count = 5 actual |
| 451 | ' |
| 452 | |
| 453 | expect_invalid_filter_spec () { |
| 454 | spec="$1" && |
| 455 | err="$2" && |
| 456 | |
| 457 | test_must_fail git -C r3 rev-list --objects --filter="$spec" HEAD \ |
| 458 | >actual 2>actual_stderr && |
| 459 | test_must_be_empty actual && |
| 460 | test_grep "$err" actual_stderr |
| 461 | } |
| 462 | |
| 463 | test_expect_success 'combine:... while URL-encoding things that should not be' ' |
| 464 | expect_invalid_filter_spec combine%3Atree:2+blob:none \ |
| 465 | "invalid filter-spec" |
| 466 | ' |
| 467 | |
| 468 | test_expect_success 'combine: with nothing after the :' ' |
| 469 | expect_invalid_filter_spec combine: "expected something after combine:" |
| 470 | ' |
| 471 | |
| 472 | test_expect_success 'parse error in first sub-filter in combine:' ' |
| 473 | expect_invalid_filter_spec combine:tree:asdf+blob:none \ |
| 474 | "expected .tree:<depth>." |
| 475 | ' |
| 476 | |
| 477 | test_expect_success 'combine:... with non-encoded reserved chars' ' |
| 478 | expect_invalid_filter_spec combine:tree:2+sparse:@xyz \ |
| 479 | "must escape char in sub-filter-spec: .@." && |
| 480 | expect_invalid_filter_spec combine:tree:2+sparse:\` \ |
| 481 | "must escape char in sub-filter-spec: .\`." && |
| 482 | expect_invalid_filter_spec combine:tree:2+sparse:~abc \ |
| 483 | "must escape char in sub-filter-spec: .\~." |
| 484 | ' |
| 485 | |
| 486 | test_expect_success 'combine:... with edge-case hex digits: Ff Aa 0 9' ' |
| 487 | git -C r3 rev-list --objects --filter="combine:tree:2+bl%6Fb:n%6fne" \ |
| 488 | HEAD >actual && |
| 489 | test_line_count = 5 actual && |
| 490 | git -C r3 rev-list --objects --filter="combine:tree%3A2+blob%3anone" \ |
| 491 | HEAD >actual && |
| 492 | test_line_count = 5 actual && |
| 493 | git -C r3 rev-list --objects --filter="combine:tree:%30" HEAD >actual && |
| 494 | test_line_count = 2 actual && |
| 495 | git -C r3 rev-list --objects --filter="combine:tree:%39+blob:none" \ |
| 496 | HEAD >actual && |
| 497 | test_line_count = 5 actual |
| 498 | ' |
| 499 | |
| 500 | test_expect_success 'add sparse pattern blobs whose paths have reserved chars' ' |
| 501 | cp r3/pattern r3/pattern1+renamed% && |
| 502 | cp r3/pattern "r3/p;at%ter+n" && |
| 503 | cp r3/pattern r3/^~pattern && |
| 504 | git -C r3 add pattern1+renamed% "p;at%ter+n" ^~pattern && |
| 505 | git -C r3 commit -m "add sparse pattern files with reserved chars" |
| 506 | ' |
| 507 | |
| 508 | test_expect_success 'combine:... with more than two sub-filters' ' |
| 509 | git -C r3 rev-list --objects \ |
| 510 | --filter=combine:tree:3+blob:limit=40+sparse:oid=main:pattern \ |
| 511 | HEAD >actual && |
| 512 | |
| 513 | expect_has HEAD "" && |
| 514 | expect_has HEAD~1 "" && |
| 515 | expect_has HEAD~2 "" && |
| 516 | expect_has HEAD dir1 && |
| 517 | expect_has HEAD dir1/sparse1 && |
| 518 | expect_has HEAD dir1/sparse2 && |
| 519 | |
| 520 | # Should also have 3 commits |
| 521 | test_line_count = 9 actual && |
| 522 | |
| 523 | # Try again, this time making sure the last sub-filter is only |
| 524 | # URL-decoded once. |
| 525 | cp actual expect && |
| 526 | |
| 527 | git -C r3 rev-list --objects \ |
| 528 | --filter=combine:tree:3+blob:limit=40+sparse:oid=main:pattern1%2brenamed%25 \ |
| 529 | HEAD >actual && |
| 530 | test_cmp expect actual && |
| 531 | |
| 532 | # Use the same composite filter again, but with a pattern file name that |
| 533 | # requires encoding multiple characters, and use implicit filter |
| 534 | # combining. |
| 535 | test_when_finished "rm -f trace1" && |
| 536 | GIT_TRACE=$(pwd)/trace1 git -C r3 rev-list --objects \ |
| 537 | --filter=tree:3 --filter=blob:limit=40 \ |
| 538 | --filter=sparse:oid="main:p;at%ter+n" \ |
| 539 | HEAD >actual && |
| 540 | |
| 541 | test_cmp expect actual && |
| 542 | grep "Add to combine filter-spec: sparse:oid=main:p%3bat%25ter%2bn" \ |
| 543 | trace1 && |
| 544 | |
| 545 | # Repeat the above test, but this time, the characters to encode are in |
| 546 | # the LHS of the combined filter. |
| 547 | test_when_finished "rm -f trace2" && |
| 548 | GIT_TRACE=$(pwd)/trace2 git -C r3 rev-list --objects \ |
| 549 | --filter=sparse:oid=main:^~pattern \ |
| 550 | --filter=tree:3 --filter=blob:limit=40 \ |
| 551 | HEAD >actual && |
| 552 | |
| 553 | test_cmp expect actual && |
| 554 | grep "Add to combine filter-spec: sparse:oid=main:%5e%7epattern" \ |
| 555 | trace2 |
| 556 | ' |
| 557 | |
| 558 | # Test provisional omit collection logic with a repo that has objects appearing |
| 559 | # at multiple depths - first deeper than the filter's threshold, then shallow. |
| 560 | |
| 561 | test_expect_success 'setup r4' ' |
| 562 | git init r4 && |
| 563 | |
| 564 | echo foo > r4/foo && |
| 565 | mkdir r4/subdir && |
| 566 | echo bar > r4/subdir/bar && |
| 567 | |
| 568 | mkdir r4/filt && |
| 569 | cp -r r4/foo r4/subdir r4/filt && |
| 570 | |
| 571 | git -C r4 add foo subdir filt && |
| 572 | git -C r4 commit -m "commit msg" |
| 573 | ' |
| 574 | |
| 575 | expect_has_with_different_name () { |
| 576 | repo=$1 && |
| 577 | name=$2 && |
| 578 | |
| 579 | hash=$(git -C $repo rev-parse HEAD:$name) && |
| 580 | ! grep "^$hash $name$" actual && |
| 581 | grep "^$hash " actual && |
| 582 | ! grep "~$hash" actual |
| 583 | } |
| 584 | |
| 585 | test_expect_success 'test tree:# filter provisional omit for blob and tree' ' |
| 586 | git -C r4 rev-list --objects --filter-print-omitted --filter=tree:2 \ |
| 587 | HEAD >actual && |
| 588 | expect_has_with_different_name r4 filt/foo && |
| 589 | expect_has_with_different_name r4 filt/subdir |
| 590 | ' |
| 591 | |
| 592 | test_expect_success 'verify skipping tree iteration when collecting omits' ' |
| 593 | GIT_TRACE=1 git -C r4 rev-list --filter-print-omitted \ |
| 594 | --objects --filter=tree:0 HEAD 2>filter_trace && |
| 595 | grep "^Skipping contents of tree " filter_trace >actual && |
| 596 | |
| 597 | echo "Skipping contents of tree subdir/..." >expect && |
| 598 | test_cmp expect actual |
| 599 | ' |
| 600 | |
| 601 | test_expect_success 'setup r5' ' |
| 602 | git init r5 && |
| 603 | mkdir -p r5/subdir && |
| 604 | |
| 605 | echo 1 >r5/short-root && |
| 606 | echo 12345 >r5/long-root && |
| 607 | echo a >r5/subdir/short-subdir && |
| 608 | echo abcde >r5/subdir/long-subdir && |
| 609 | |
| 610 | git -C r5 add short-root long-root subdir && |
| 611 | git -C r5 commit -m "commit msg" |
| 612 | ' |
| 613 | |
| 614 | test_expect_success 'verify collecting omits in combined: filter' ' |
| 615 | # Note that this test guards against the naive implementation of simply |
| 616 | # giving both filters the same "omits" set and expecting it to |
| 617 | # automatically merge them. |
| 618 | git -C r5 rev-list --objects --quiet --filter-print-omitted \ |
| 619 | --filter=combine:tree:2+blob:limit=3 HEAD >actual && |
| 620 | |
| 621 | # Expect 0 trees/commits, 3 blobs omitted (all blobs except short-root) |
| 622 | omitted_1=$(echo 12345 | git hash-object --stdin) && |
| 623 | omitted_2=$(echo a | git hash-object --stdin) && |
| 624 | omitted_3=$(echo abcde | git hash-object --stdin) && |
| 625 | |
| 626 | grep "~$omitted_1" actual && |
| 627 | grep "~$omitted_2" actual && |
| 628 | grep "~$omitted_3" actual && |
| 629 | test_line_count = 3 actual |
| 630 | ' |
| 631 | |
| 632 | # Test tree:<depth> where a tree is iterated to twice - once where a subentry is |
| 633 | # too deep to be included, and again where the blob inside it is shallow enough |
| 634 | # to be included. This makes sure we don't use LOFR_MARK_SEEN incorrectly (we |
| 635 | # can't use it because a tree can be iterated over again at a lower depth). |
| 636 | |
| 637 | test_expect_success 'tree:<depth> where we iterate over tree at two levels' ' |
| 638 | git init r5 && |
| 639 | |
| 640 | mkdir -p r5/a/subdir/b && |
| 641 | echo foo > r5/a/subdir/b/foo && |
| 642 | |
| 643 | mkdir -p r5/subdir/b && |
| 644 | echo foo > r5/subdir/b/foo && |
| 645 | |
| 646 | git -C r5 add a subdir && |
| 647 | git -C r5 commit -m "commit msg" && |
| 648 | |
| 649 | git -C r5 rev-list --objects --filter=tree:4 HEAD >actual && |
| 650 | expect_has_with_different_name r5 a/subdir/b/foo |
| 651 | ' |
| 652 | |
| 653 | test_expect_success 'tree:<depth> which filters out blob but given as arg' ' |
| 654 | blob_hash=$(git -C r4 rev-parse HEAD:subdir/bar) && |
| 655 | |
| 656 | git -C r4 rev-list --objects --filter=tree:1 HEAD $blob_hash >actual && |
| 657 | grep ^$blob_hash actual |
| 658 | ' |
| 659 | |
| 660 | # Delete some loose objects and use rev-list, but WITHOUT any filtering. |
| 661 | # This models previously omitted objects that we did not receive. |
| 662 | |
| 663 | test_expect_success 'rev-list W/ --missing=print' ' |
| 664 | git -C r1 ls-files -s file.1 file.2 file.3 file.4 file.5 \ |
| 665 | >ls_files_result && |
| 666 | awk -f print_2.awk ls_files_result | |
| 667 | sort >expected && |
| 668 | |
| 669 | for id in `sed "s|..|&/|" expected` |
| 670 | do |
| 671 | rm r1/.git/objects/$id || return 1 |
| 672 | done && |
| 673 | |
| 674 | git -C r1 rev-list --quiet --missing=print --objects HEAD >revs && |
| 675 | awk -f print_1.awk revs | |
| 676 | sed "s/?//" | |
| 677 | sort >observed && |
| 678 | |
| 679 | test_cmp expected observed |
| 680 | ' |
| 681 | |
| 682 | test_expect_success 'rev-list W/O --missing fails' ' |
| 683 | test_must_fail git -C r1 rev-list --quiet --objects HEAD |
| 684 | ' |
| 685 | |
| 686 | test_expect_success 'rev-list W/ missing=allow-any' ' |
| 687 | git -C r1 rev-list --quiet --missing=allow-any --objects HEAD |
| 688 | ' |
| 689 | |
| 690 | # Test expansion of filter specs. |
| 691 | |
| 692 | test_expect_success 'expand blob limit in protocol' ' |
| 693 | git -C r2 config --local uploadpack.allowfilter 1 && |
| 694 | GIT_TRACE_PACKET="$(pwd)/trace" git -c protocol.version=2 clone \ |
| 695 | --filter=blob:limit=1k "file://$(pwd)/r2" limit && |
| 696 | ! grep "blob:limit=1k" trace && |
| 697 | grep "blob:limit=1024" trace |
| 698 | ' |
| 699 | |
| 700 | test_expect_success EXPENSIVE 'large sparse filter file ignored' ' |
| 701 | blob=$(dd if=/dev/zero bs=101M count=1 | |
| 702 | git hash-object -w --stdin) && |
| 703 | test_must_fail \ |
| 704 | git rev-list --all --objects --filter=sparse:oid=$blob 2>err && |
| 705 | cat >expect <<-EOF && |
| 706 | warning: ignoring excessively large pattern blob: $blob |
| 707 | fatal: unable to parse sparse filter data in $blob |
| 708 | EOF |
| 709 | test_cmp expect err |
| 710 | ' |
| 711 | |
| 712 | test_done |