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 BATCH_CONFIGURATION
='-c core.fsync=loose-object -c core.fsyncmethod=batch'
54 test_expect_success
'unpack big object in stream (core.fsyncmethod=batch)' '
56 GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
57 git -C dest.git $BATCH_CONFIGURATION unpack-objects <pack-$PACK.pack &&
58 grep fsync/hardware-flush trace2.txt &&
59 test_dir_is_empty dest.git/objects/pack &&
60 git -C dest.git cat-file --batch-check="%(objectname)" <obj-list >current &&
64 test_expect_success
'do not unpack existing large objects' '
66 git -C dest.git index-pack --stdin <pack-$PACK.pack &&
67 git -C dest.git unpack-objects <pack-$PACK.pack &&
69 # The destination came up with the exact same pack...
70 DEST_PACK=$(echo dest.git/objects/pack/pack-*.pack) &&
71 test_cmp pack-$PACK.pack $DEST_PACK &&
73 # ...and wrote no loose objects
74 test_stdout_line_count = 0 find dest.git/objects -type f ! -name "pack-*"