]>
Commit | Line | Data |
---|---|---|
a1bf5ca2 HX |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2022 Han Xin | |
4 | # | |
5 | ||
6 | test_description='git unpack-objects with large objects' | |
7 | ||
3e3b9321 | 8 | TEST_PASSES_SANITIZE_LEAK=true |
a1bf5ca2 HX |
9 | . ./test-lib.sh |
10 | ||
11 | prepare_dest () { | |
12 | test_when_finished "rm -rf dest.git" && | |
aaf81223 HX |
13 | git init --bare dest.git && |
14 | git -C dest.git config core.bigFileThreshold "$1" | |
a1bf5ca2 HX |
15 | } |
16 | ||
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 && | |
aaf81223 HX |
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 | |
a1bf5ca2 HX |
26 | ' |
27 | ||
28 | test_expect_success 'set memory limitation to 1MB' ' | |
29 | GIT_ALLOC_LIMIT=1m && | |
30 | export GIT_ALLOC_LIMIT | |
31 | ' | |
32 | ||
33 | test_expect_success 'unpack-objects failed under memory limitation' ' | |
aaf81223 | 34 | prepare_dest 2m && |
a1bf5ca2 HX |
35 | test_must_fail git -C dest.git unpack-objects <pack-$PACK.pack 2>err && |
36 | grep "fatal: attempting to allocate" err | |
37 | ' | |
38 | ||
39 | test_expect_success 'unpack-objects works with memory limitation in dry-run mode' ' | |
aaf81223 | 40 | prepare_dest 2m && |
a1bf5ca2 HX |
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 | |
44 | ' | |
45 | ||
aaf81223 HX |
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 | |
50 | ' | |
51 | ||
3a251bac ÆAB |
52 | check_fsync_events () { |
53 | local trace="$1" && | |
54 | shift && | |
55 | ||
56 | cat >expect && | |
57 | sed -n \ | |
a27eecea | 58 | -e '/^{"event":"counter",.*"category":"fsync",/ { |
3a251bac ÆAB |
59 | s/.*"category":"fsync",//; |
60 | s/}$//; | |
61 | p; | |
62 | }' \ | |
63 | <"$trace" >actual && | |
64 | test_cmp expect actual | |
65 | } | |
66 | ||
aaf81223 HX |
67 | BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch' |
68 | ||
69 | test_expect_success 'unpack big object in stream (core.fsyncmethod=batch)' ' | |
70 | prepare_dest 1m && | |
71 | GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \ | |
3a251bac | 72 | GIT_TEST_FSYNC=true \ |
aaf81223 | 73 | git -C dest.git $BATCH_CONFIGURATION unpack-objects <pack-$PACK.pack && |
ce50f1f3 JS |
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 && | |
a27eecea BB |
81 | "name":"writeout-only","count":6 |
82 | "name":"hardware-flush","count":$flush_count | |
3a251bac ÆAB |
83 | EOF |
84 | ||
aaf81223 HX |
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 | |
88 | ' | |
89 | ||
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 && | |
94 | ||
95 | # The destination came up with the exact same pack... | |
96 | DEST_PACK=$(echo dest.git/objects/pack/pack-*.pack) && | |
32ed3314 | 97 | cmp pack-$PACK.pack $DEST_PACK && |
aaf81223 HX |
98 | |
99 | # ...and wrote no loose objects | |
100 | test_stdout_line_count = 0 find dest.git/objects -type f ! -name "pack-*" | |
101 | ' | |
102 | ||
a1bf5ca2 | 103 | test_done |