3 # Copyright (c) 2022 Han Xin
6 test_description
='git unpack-objects with large objects'
8 TEST_PASSES_SANITIZE_LEAK
=true
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" \
28 test_expect_success
'set memory limitation to 1MB' '
30 export GIT_ALLOC_LIMIT
33 test_expect_success
'unpack-objects failed under memory limitation' '
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' '
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' '
48 git -C dest.git unpack-objects <pack-$PACK.pack &&
49 test_dir_is_empty dest.git/objects/pack
52 check_fsync_events
() {
58 -e '/^{"event":"data",.*"category":"fsync",/ {
59 s/.*"category":"fsync",//;
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)' '
71 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
73 git -C dest.git $BATCH_CONFIGURATION unpack-objects <pack-$PACK.pack &&
74 if grep "core.fsyncMethod = batch is unsupported" trace2.txt
80 check_fsync_events trace2.txt <<-EOF &&
81 "key":"fsync/writeout-only","value":"6"
82 "key":"fsync/hardware-flush","value":"$flush_count"
85 test_dir_is_empty dest.git/objects/pack &&
86 git -C dest.git cat-file --batch-check="%(objectname)" <obj-list >current &&
90 test_expect_success
'do not unpack existing large objects' '
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-*"