Git fork

Merge branch 'jk/test-seq-format'

A test helper "test_seq" function learned the "-f <fmt>" option,
which allowed us to simplify a lot of test scripts.

* jk/test-seq-format:
test-lib: teach test_seq the -f option
t7422: replace confusing printf with echo

+34 -63
+2 -2
t/t0021-conversion.sh
··· 281 281 test_expect_success 'filtering large input to small output should use little memory' ' 282 282 test_config filter.devnull.clean "cat >/dev/null" && 283 283 test_config filter.devnull.required true && 284 - for i in $(test_seq 1 30); do printf "%1048576d" 1 || return 1; done >30MB && 284 + test_seq -f "%1048576d" 1 30 >30MB && 285 285 echo "30MB filter=devnull" >.gitattributes && 286 286 GIT_MMAP_LIMIT=1m GIT_ALLOC_LIMIT=1m git add 30MB 287 287 ' ··· 299 299 test_expect_success EXPENSIVE 'filter large file' ' 300 300 test_config filter.largefile.smudge cat && 301 301 test_config filter.largefile.clean cat && 302 - for i in $(test_seq 1 2048); do printf "%1048576d" 1 || return 1; done >2GB && 302 + test_seq -f "%1048576d" 1 2048 >2GB && 303 303 echo "2GB filter=largefile" >.gitattributes && 304 304 git add 2GB 2>err && 305 305 test_must_be_empty err &&
+1 -5
t/t0610-reftable-basics.sh
··· 477 477 test_commit --no-tag initial && 478 478 479 479 head=$(git rev-parse HEAD) && 480 - for i in $(test_seq 100) 481 - do 482 - printf "%s commit\trefs/heads/branch-%s\n" "$head" "$i" || 483 - return 1 484 - done >expect && 480 + test_seq -f "$head commit\trefs/heads/branch-%d" 100 >expect && 485 481 printf "%s commit\trefs/heads/main\n" "$head" >>expect && 486 482 487 483 for i in $(test_seq 100)
+5 -8
t/t0612-reftable-jgit-compatibility.sh
··· 112 112 cd repo && 113 113 114 114 test_commit A && 115 - awk " 116 - BEGIN { 117 - print \"start\"; 118 - for (i = 0; i < 10000; i++) 119 - printf \"create refs/heads/branch-%d HEAD\n\", i; 120 - print \"commit\"; 121 - } 122 - " >input && 115 + { 116 + echo start && 117 + test_seq -f "create refs/heads/branch-%d HEAD" 10000 && 118 + echo commit 119 + } >input && 123 120 git update-ref --stdin <input && 124 121 125 122 test_same_refs &&
+4 -20
t/t0613-reftable-write-options.sh
··· 66 66 ( 67 67 cd repo && 68 68 test_commit initial && 69 - for i in $(test_seq 200) 70 - do 71 - printf "update refs/heads/branch-%d HEAD\n" "$i" || 72 - return 1 73 - done >input && 69 + test_seq -f "update refs/heads/branch-%d HEAD" 200 >input && 74 70 git update-ref --stdin <input && 75 71 git pack-refs && 76 72 ··· 180 176 ( 181 177 cd repo && 182 178 test_commit initial && 183 - for i in $(test_seq 10) 184 - do 185 - printf "update refs/heads/branch-%d HEAD\n" "$i" || 186 - return 1 187 - done >input && 179 + test_seq -f "update refs/heads/branch-%d HEAD" 10 >input && 188 180 git update-ref --stdin <input && 189 181 git -c reftable.restartInterval=1 pack-refs && 190 182 ··· 224 216 ( 225 217 cd repo && 226 218 test_commit initial && 227 - for i in $(test_seq 5) 228 - do 229 - printf "update refs/heads/branch-%d HEAD\n" "$i" || 230 - return 1 231 - done >input && 219 + test_seq -f "update refs/heads/branch-%d HEAD" 5 >input && 232 220 git update-ref --stdin <input && 233 221 git -c reftable.blockSize=100 pack-refs && 234 222 ··· 263 251 ( 264 252 cd repo && 265 253 test_commit initial && 266 - for i in $(test_seq 5) 267 - do 268 - printf "update refs/heads/branch-%d HEAD\n" "$i" || 269 - return 1 270 - done >input && 254 + test_seq -f "update refs/heads/branch-%d HEAD" 5 >input && 271 255 git update-ref --stdin <input && 272 256 git -c reftable.blockSize=100 -c reftable.indexObjects=false pack-refs && 273 257
+2 -8
t/t1400-update-ref.sh
··· 1380 1380 1381 1381 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches does not burst open file limit' ' 1382 1382 ( 1383 - for i in $(test_seq 33) 1384 - do 1385 - echo "create refs/heads/$i HEAD" || exit 1 1386 - done >large_input && 1383 + test_seq -f "create refs/heads/%d HEAD" 33 >large_input && 1387 1384 run_with_limited_open_files git update-ref --stdin <large_input && 1388 1385 git rev-parse --verify -q refs/heads/33 1389 1386 ) ··· 1391 1388 1392 1389 test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction deleting branches does not burst open file limit' ' 1393 1390 ( 1394 - for i in $(test_seq 33) 1395 - do 1396 - echo "delete refs/heads/$i HEAD" || exit 1 1397 - done >large_input && 1391 + test_seq -f "delete refs/heads/%d HEAD" 33 >large_input && 1398 1392 run_with_limited_open_files git update-ref --stdin <large_input && 1399 1393 test_must_fail git rev-parse --verify -q refs/heads/33 1400 1394 )
+1 -4
t/t5004-archive-corner-cases.sh
··· 176 176 blob=$(echo $s | git hash-object -w --stdin) && 177 177 178 178 # create tree containing 65500 entries of that blob 179 - for i in $(test_seq 1 65500) 180 - do 181 - echo "100644 blob $blob $i" || return 1 182 - done >tree && 179 + test_seq -f "100644 blob $blob\t%d" 1 65500 >tree && 183 180 tree=$(git mktree <tree) && 184 181 185 182 # zip it, creating an archive a bit bigger than 4GB
+2 -8
t/t6422-merge-rename-corner-cases.sh
··· 1146 1146 cd simple_${sideL}_${sideR} && 1147 1147 1148 1148 # Create some related files now 1149 - for i in $(test_seq 1 10) 1150 - do 1151 - echo Random base content line $i 1152 - done >file_v1 && 1149 + test_seq -f "Random base content line %d" 1 10 >file_v1 && 1153 1150 cp file_v1 file_v2 && 1154 1151 echo modification >>file_v2 && 1155 1152 ··· 1293 1290 cd nested_conflicts_from_rename_rename && 1294 1291 1295 1292 # Create some related files now 1296 - for i in $(test_seq 1 10) 1297 - do 1298 - echo Random base content line $i 1299 - done >file_v1 && 1293 + test_seq -f "Random base content line %d" 1 10 >file_v1 && 1300 1294 1301 1295 cp file_v1 file_v2 && 1302 1296 cp file_v1 file_v3 &&
+3 -6
t/t7422-submodule-output.sh
··· 180 180 COMMIT=$(git rev-parse HEAD) && 181 181 for i in $(test_seq 2000) 182 182 do 183 - printf "[submodule \"sm-$i\"]\npath = recursive-submodule-path-$i\n" "$i" || 183 + echo "[submodule \"sm-$i\"]" && 184 + echo "path = recursive-submodule-path-$i" || 184 185 return 1 185 186 done >gitmodules && 186 187 BLOB=$(git hash-object -w --stdin <gitmodules) && 187 188 188 189 printf "100644 blob $BLOB\t.gitmodules\n" >tree && 189 - for i in $(test_seq 2000) 190 - do 191 - printf "160000 commit $COMMIT\trecursive-submodule-path-%d\n" "$i" || 192 - return 1 193 - done >>tree && 190 + test_seq -f "160000 commit $COMMIT\trecursive-submodule-path-%d" 2000 >>tree && 194 191 TREE=$(git mktree <tree) && 195 192 196 193 COMMIT=$(git commit-tree "$TREE") &&
+14 -2
t/test-lib-functions.sh
··· 1451 1451 # test_seq 1 5 -- outputs 1 2 3 4 5 one line at a time 1452 1452 # 1453 1453 # or with one argument (end), in which case it starts counting 1454 - # from 1. 1454 + # from 1. In addition to the start/end arguments, you can pass an optional 1455 + # printf format. For example: 1456 + # 1457 + # test_seq -f "line %d" 1 5 1458 + # 1459 + # would print 5 lines, "line 1" through "line 5". 1455 1460 1456 1461 test_seq () { 1462 + local fmt="%d" 1463 + case "$1" in 1464 + -f) 1465 + fmt="$2" 1466 + shift 2 1467 + ;; 1468 + esac 1457 1469 case $# in 1458 1470 1) set 1 "$@" ;; 1459 1471 2) ;; ··· 1462 1474 test_seq_counter__=$1 1463 1475 while test "$test_seq_counter__" -le "$2" 1464 1476 do 1465 - echo "$test_seq_counter__" 1477 + printf "$fmt\n" "$test_seq_counter__" 1466 1478 test_seq_counter__=$(( $test_seq_counter__ + 1 )) 1467 1479 done 1468 1480 }