Skip to content

Commit 3da50fb

Browse files
neerajsi-msftdscho
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 936ac64 commit 3da50fb

File tree

4 files changed

+109
-14
lines changed

4 files changed

+109
-14
lines changed

t/lib-unique-files.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

t/t3700-add.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ test_description='Test of git add, including the -- option.'
88
TEST_PASSES_SANITIZE_LEAK=true
99
. ./test-lib.sh
1010

11+
. $TEST_DIRECTORY/lib-unique-files.sh
12+
1113
# Test the file mode "$1" of the file "$2" in the index.
1214
test_mode_in_index () {
1315
case "$(git ls-files -s "$2")" in
@@ -34,6 +36,32 @@ test_expect_success \
3436
'Test that "git add -- -q" works' \
3537
'touch -- -q && git add -- -q'
3638

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+
3765
test_expect_success \
3866
'git add: Test that executable bit is not used if core.filemode=0' \
3967
'git config core.filemode 0 &&

t/t3903-stash.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
99
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1010

1111
. ./test-lib.sh
12+
. $TEST_DIRECTORY/lib-unique-files.sh
1213

1314
test_expect_success 'usage on cmd and subcommand invalid option' '
1415
test_expect_code 129 git stash --invalid-option 2>usage &&
@@ -1410,6 +1411,25 @@ test_expect_success 'stash handles skip-worktree entries nicely' '
14101411
git rev-parse --verify refs/stash:A.t
14111412
'
14121413

1414+
1415+
BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch'
1416+
1417+
test_expect_success 'stash with core.fsyncmethod=batch' "
1418+
test_create_unique_files 2 4 files_base_dir &&
1419+
GIT_TEST_FSYNC=1 git $BATCH_CONFIGURATION stash push -u -- ./files_base_dir/ &&
1420+
1421+
# The files were untracked, so use the third parent,
1422+
# which contains the untracked files
1423+
git ls-tree -r stash^3 -- ./files_base_dir/ |
1424+
test_parse_ls_tree_oids >stashed_files_oids &&
1425+
1426+
# We created 2 dirs with 4 files each (8 files total) above
1427+
test_line_count = 8 stashed_files_oids &&
1428+
git cat-file --batch-check='%(objectname)' <stashed_files_oids >stashed_files_actual &&
1429+
test_cmp stashed_files_oids stashed_files_actual
1430+
"
1431+
1432+
14131433
test_expect_success 'git stash succeeds despite directory/file change' '
14141434
test_create_repo directory_file_switch_v1 &&
14151435
(

t/t5300-pack-object.sh

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,27 @@ test_expect_success 'pack-objects with bogus arguments' '
161161
'
162162

163163
check_unpack () {
164+
local packname="$1" &&
165+
local object_list="$2" &&
166+
local git_config="$3" &&
164167
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
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
176175
}
177176

178177
test_expect_success 'unpack without delta' '
179-
check_unpack test-1-${packname_1}
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"
180185
'
181186

182187
test_expect_success 'pack with REF_DELTA' '
@@ -185,7 +190,11 @@ test_expect_success 'pack with REF_DELTA' '
185190
'
186191

187192
test_expect_success 'unpack with REF_DELTA' '
188-
check_unpack test-2-${packname_2}
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"
189198
'
190199

191200
test_expect_success 'pack with OFS_DELTA' '
@@ -195,7 +204,11 @@ test_expect_success 'pack with OFS_DELTA' '
195204
'
196205

197206
test_expect_success 'unpack with OFS_DELTA' '
198-
check_unpack test-3-${packname_3}
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"
199212
'
200213

201214
test_expect_success 'compare delta flavors' '

0 commit comments

Comments
 (0)