Git fork

core.fsyncmethod: tests for batch mode

Add test cases to exercise batch mode for:
* 'git add'
* 'git stash'
* 'git update-index'
* 'git unpack-objects'

These tests ensure that the added data winds up in the object database.

In this change we introduce a new test helper lib-unique-files.sh. The
goal of this library is to create a tree of files that have different
oids from any other files that may have been created in the current test
repo. This helps us avoid missing validation of an object being added
due to it already being in the repo.

Signed-off-by: Neeraj Singh <neerajsi@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Neeraj Singh and committed by
Junio C Hamano
d42bab44 fb2d0db5

+109 -14
+34
t/lib-unique-files.sh
···
··· 1 + # Helper to create files with unique contents 2 + 3 + # Create multiple files with unique contents within this test run. Takes the 4 + # number of directories, the number of files in each directory, and the base 5 + # directory. 6 + # 7 + # test_create_unique_files 2 3 my_dir -- Creates 2 directories with 3 files 8 + # each in my_dir, all with contents 9 + # different from previous invocations 10 + # of this command in this run. 11 + 12 + test_create_unique_files () { 13 + test "$#" -ne 3 && BUG "3 param" 14 + 15 + local dirs="$1" && 16 + local files="$2" && 17 + local basedir="$3" && 18 + local counter="0" && 19 + local i && 20 + local j && 21 + test_tick && 22 + local basedata="$basedir$test_tick" && 23 + rm -rf "$basedir" && 24 + for i in $(test_seq $dirs) 25 + do 26 + local dir="$basedir/dir$i" && 27 + mkdir -p "$dir" && 28 + for j in $(test_seq $files) 29 + do 30 + counter=$((counter + 1)) && 31 + echo "$basedata.$counter">"$dir/file$j.txt" 32 + done 33 + done 34 + }
+28
t/t3700-add.sh
··· 8 TEST_PASSES_SANITIZE_LEAK=true 9 . ./test-lib.sh 10 11 # Test the file mode "$1" of the file "$2" in the index. 12 test_mode_in_index () { 13 case "$(git ls-files -s "$2")" in ··· 33 test_expect_success \ 34 'Test that "git add -- -q" works' \ 35 'touch -- -q && git add -- -q' 36 37 test_expect_success \ 38 'git add: Test that executable bit is not used if core.filemode=0' \
··· 8 TEST_PASSES_SANITIZE_LEAK=true 9 . ./test-lib.sh 10 11 + . $TEST_DIRECTORY/lib-unique-files.sh 12 + 13 # Test the file mode "$1" of the file "$2" in the index. 14 test_mode_in_index () { 15 case "$(git ls-files -s "$2")" in ··· 35 test_expect_success \ 36 'Test that "git add -- -q" works' \ 37 'touch -- -q && git add -- -q' 38 + 39 + BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch' 40 + 41 + test_expect_success 'git add: core.fsyncmethod=batch' " 42 + test_create_unique_files 2 4 files_base_dir1 && 43 + GIT_TEST_FSYNC=1 git $BATCH_CONFIGURATION add -- ./files_base_dir1/ && 44 + git ls-files --stage files_base_dir1/ | 45 + test_parse_ls_files_stage_oids >added_files_oids && 46 + 47 + # We created 2 subdirs with 4 files each (8 files total) above 48 + test_line_count = 8 added_files_oids && 49 + git cat-file --batch-check='%(objectname)' <added_files_oids >added_files_actual && 50 + test_cmp added_files_oids added_files_actual 51 + " 52 + 53 + test_expect_success 'git update-index: core.fsyncmethod=batch' " 54 + test_create_unique_files 2 4 files_base_dir2 && 55 + find files_base_dir2 ! -type d -print | xargs git $BATCH_CONFIGURATION update-index --add -- && 56 + git ls-files --stage files_base_dir2 | 57 + test_parse_ls_files_stage_oids >added_files2_oids && 58 + 59 + # We created 2 subdirs with 4 files each (8 files total) above 60 + test_line_count = 8 added_files2_oids && 61 + git cat-file --batch-check='%(objectname)' <added_files2_oids >added_files2_actual && 62 + test_cmp added_files2_oids added_files2_actual 63 + " 64 65 test_expect_success \ 66 'git add: Test that executable bit is not used if core.filemode=0' \
+20
t/t3903-stash.sh
··· 9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 10 11 . ./test-lib.sh 12 13 test_expect_success 'usage on cmd and subcommand invalid option' ' 14 test_expect_code 129 git stash --invalid-option 2>usage && ··· 1335 1336 git rev-parse --verify refs/stash:A.t 1337 ' 1338 1339 test_expect_success 'git stash succeeds despite directory/file change' ' 1340 test_create_repo directory_file_switch_v1 &&
··· 9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 10 11 . ./test-lib.sh 12 + . $TEST_DIRECTORY/lib-unique-files.sh 13 14 test_expect_success 'usage on cmd and subcommand invalid option' ' 15 test_expect_code 129 git stash --invalid-option 2>usage && ··· 1336 1337 git rev-parse --verify refs/stash:A.t 1338 ' 1339 + 1340 + 1341 + BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch' 1342 + 1343 + test_expect_success 'stash with core.fsyncmethod=batch' " 1344 + test_create_unique_files 2 4 files_base_dir && 1345 + GIT_TEST_FSYNC=1 git $BATCH_CONFIGURATION stash push -u -- ./files_base_dir/ && 1346 + 1347 + # The files were untracked, so use the third parent, 1348 + # which contains the untracked files 1349 + git ls-tree -r stash^3 -- ./files_base_dir/ | 1350 + test_parse_ls_tree_oids >stashed_files_oids && 1351 + 1352 + # We created 2 dirs with 4 files each (8 files total) above 1353 + test_line_count = 8 stashed_files_oids && 1354 + git cat-file --batch-check='%(objectname)' <stashed_files_oids >stashed_files_actual && 1355 + test_cmp stashed_files_oids stashed_files_actual 1356 + " 1357 + 1358 1359 test_expect_success 'git stash succeeds despite directory/file change' ' 1360 test_create_repo directory_file_switch_v1 &&
+27 -14
t/t5300-pack-object.sh
··· 161 ' 162 163 check_unpack () { 164 test_when_finished "rm -rf git2" && 165 - git init --bare git2 && 166 - git -C git2 unpack-objects -n <"$1".pack && 167 - git -C git2 unpack-objects <"$1".pack && 168 - (cd .git && find objects -type f -print) | 169 - while read path 170 - do 171 - cmp git2/$path .git/$path || { 172 - echo $path differs. 173 - return 1 174 - } 175 - done 176 } 177 178 test_expect_success 'unpack without delta' ' 179 - check_unpack test-1-${packname_1} 180 ' 181 182 test_expect_success 'pack with REF_DELTA' ' ··· 185 ' 186 187 test_expect_success 'unpack with REF_DELTA' ' 188 - check_unpack test-2-${packname_2} 189 ' 190 191 test_expect_success 'pack with OFS_DELTA' ' ··· 195 ' 196 197 test_expect_success 'unpack with OFS_DELTA' ' 198 - check_unpack test-3-${packname_3} 199 ' 200 201 test_expect_success 'compare delta flavors' '
··· 161 ' 162 163 check_unpack () { 164 + local packname="$1" && 165 + local object_list="$2" && 166 + local git_config="$3" && 167 test_when_finished "rm -rf git2" && 168 + git $git_config init --bare git2 && 169 + ( 170 + git $git_config -C git2 unpack-objects -n <"$packname".pack && 171 + git $git_config -C git2 unpack-objects <"$packname".pack && 172 + git $git_config -C git2 cat-file --batch-check="%(objectname)" 173 + ) <"$object_list" >current && 174 + cmp "$object_list" current 175 } 176 177 test_expect_success 'unpack without delta' ' 178 + check_unpack test-1-${packname_1} obj-list 179 + ' 180 + 181 + BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch' 182 + 183 + test_expect_success 'unpack without delta (core.fsyncmethod=batch)' ' 184 + check_unpack test-1-${packname_1} obj-list "$BATCH_CONFIGURATION" 185 ' 186 187 test_expect_success 'pack with REF_DELTA' ' ··· 190 ' 191 192 test_expect_success 'unpack with REF_DELTA' ' 193 + check_unpack test-2-${packname_2} obj-list 194 + ' 195 + 196 + test_expect_success 'unpack with REF_DELTA (core.fsyncmethod=batch)' ' 197 + check_unpack test-2-${packname_2} obj-list "$BATCH_CONFIGURATION" 198 ' 199 200 test_expect_success 'pack with OFS_DELTA' ' ··· 204 ' 205 206 test_expect_success 'unpack with OFS_DELTA' ' 207 + check_unpack test-3-${packname_3} obj-list 208 + ' 209 + 210 + test_expect_success 'unpack with OFS_DELTA (core.fsyncmethod=batch)' ' 211 + check_unpack test-3-${packname_3} obj-list "$BATCH_CONFIGURATION" 212 ' 213 214 test_expect_success 'compare delta flavors' '