Git 2.45
[git/gitster.git] / t / t5351-unpack-large-objects.sh
blob43cbcd5d497ecaef33c97032e7c5a8729fb4c01c
1 #!/bin/sh
3 # Copyright (c) 2022 Han Xin
6 test_description='git unpack-objects with large objects'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 prepare_dest () {
12 test_when_finished "rm -rf dest.git" &&
13 git init --bare dest.git &&
14 git -C dest.git config core.bigFileThreshold "$1"
17 test_expect_success "create large objects (1.5 MB) and PACK" '
18 test-tool genrandom foo 1500000 >big-blob &&
19 test_commit --append foo big-blob &&
20 test-tool genrandom bar 1500000 >big-blob &&
21 test_commit --append bar big-blob &&
22 PACK=$(echo HEAD | git pack-objects --revs pack) &&
23 git verify-pack -v pack-$PACK.pack >out &&
24 sed -n -e "s/^\([0-9a-f][0-9a-f]*\).*\(commit\|tree\|blob\).*/\1/p" \
25 <out >obj-list
28 test_expect_success 'set memory limitation to 1MB' '
29 GIT_ALLOC_LIMIT=1m &&
30 export GIT_ALLOC_LIMIT
33 test_expect_success 'unpack-objects failed under memory limitation' '
34 prepare_dest 2m &&
35 test_must_fail git -C dest.git unpack-objects <pack-$PACK.pack 2>err &&
36 grep "fatal: attempting to allocate" err
39 test_expect_success 'unpack-objects works with memory limitation in dry-run mode' '
40 prepare_dest 2m &&
41 git -C dest.git unpack-objects -n <pack-$PACK.pack &&
42 test_stdout_line_count = 0 find dest.git/objects -type f &&
43 test_dir_is_empty dest.git/objects/pack
46 test_expect_success 'unpack big object in stream' '
47 prepare_dest 1m &&
48 git -C dest.git unpack-objects <pack-$PACK.pack &&
49 test_dir_is_empty dest.git/objects/pack
52 check_fsync_events () {
53 local trace="$1" &&
54 shift &&
56 cat >expect &&
57 sed -n \
58 -e '/^{"event":"counter",.*"category":"fsync",/ {
59 s/.*"category":"fsync",//;
60 s/}$//;
62 }' \
63 <"$trace" >actual &&
64 test_cmp expect actual
67 BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch'
69 test_expect_success 'unpack big object in stream (core.fsyncmethod=batch)' '
70 prepare_dest 1m &&
71 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
72 GIT_TEST_FSYNC=true \
73 git -C dest.git $BATCH_CONFIGURATION unpack-objects <pack-$PACK.pack &&
74 if grep "core.fsyncMethod = batch is unsupported" trace2.txt
75 then
76 flush_count=7
77 else
78 flush_count=1
79 fi &&
80 check_fsync_events trace2.txt <<-EOF &&
81 "name":"writeout-only","count":6
82 "name":"hardware-flush","count":$flush_count
83 EOF
85 test_dir_is_empty dest.git/objects/pack &&
86 git -C dest.git cat-file --batch-check="%(objectname)" <obj-list >current &&
87 cmp obj-list current
90 test_expect_success 'do not unpack existing large objects' '
91 prepare_dest 1m &&
92 git -C dest.git index-pack --stdin <pack-$PACK.pack &&
93 git -C dest.git unpack-objects <pack-$PACK.pack &&
95 # The destination came up with the exact same pack...
96 DEST_PACK=$(echo dest.git/objects/pack/pack-*.pack) &&
97 cmp pack-$PACK.pack $DEST_PACK &&
99 # ...and wrote no loose objects
100 test_stdout_line_count = 0 find dest.git/objects -type f ! -name "pack-*"
103 test_done