Merge branch 'rs/diff-parseopts-cleanup'
[git/gitster.git] / t / t5316-pack-delta-depth.sh
blobeb4ef3dda4d6e501b9be6c7b85d90a0fd55e5c7f
1 #!/bin/sh
3 test_description='pack-objects breaks long cross-pack delta chains'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 # This mirrors a repeated push setup:
10 # 1. A client repeatedly modifies some files, makes a
11 # commit, and pushes the result. It does this N times
12 # before we get around to repacking.
14 # 2. Each push generates a thin pack with the new version of
15 # various objects. Let's consider some file in the root tree
16 # which is updated in each commit.
18 # When generating push number X, we feed commit X-1 (and
19 # thus blob X-1) as a preferred base. The resulting pack has
20 # blob X as a thin delta against blob X-1.
22 # On the receiving end, "index-pack --fix-thin" will
23 # complete the pack with a base copy of blob X-1.
25 # 3. In older versions of git, if we used the delta from
26 # pack X, then we'd always find blob X-1 as a base in the
27 # same pack (and generate a fresh delta).
29 # But with the pack mru, we jump from delta to delta
30 # following the traversal order:
32 # a. We grab blob X from pack X as a delta, putting it at
33 # the tip of our mru list.
35 # b. Eventually we move onto commit X-1. We need other
36 # objects which are only in pack X-1 (in the test code
37 # below, it's the containing tree). That puts pack X-1
38 # at the tip of our mru list.
40 # c. Eventually we look for blob X-1, and we find the
41 # version in pack X-1 (because it's the mru tip).
43 # Now we have blob X as a delta against X-1, which is a delta
44 # against X-2, and so forth.
46 # In the real world, these small pushes would get exploded by
47 # unpack-objects rather than "index-pack --fix-thin", but the
48 # same principle applies to larger pushes (they only need one
49 # repeatedly-modified file to generate the delta chain).
51 test_expect_success 'create series of packs' '
52 test-tool genrandom foo 4096 >content &&
53 prev= &&
54 for i in $(test_seq 1 10)
56 cat content >file &&
57 echo $i >>file &&
58 git add file &&
59 git commit -m $i &&
60 cur=$(git rev-parse HEAD^{tree}) &&
62 if test -n "$prev"
63 then
64 echo "-$prev"
65 fi &&
66 echo $cur &&
67 echo "$(git rev-parse :file) file"
68 } | git pack-objects --stdout >tmp &&
69 GIT_TRACE2_EVENT=$PWD/trace \
70 git index-pack -v --stdin --fix-thin <tmp || return 1 &&
71 grep -c region_enter.*progress trace >enter &&
72 grep -c region_leave.*progress trace >leave &&
73 test_cmp enter leave &&
74 prev=$cur
75 done
78 max_chain() {
79 git index-pack --verify-stat-only "$1" >output &&
80 perl -lne '
81 BEGIN { $len = 0 }
82 /chain length = (\d+)/ and $len = $1;
83 END { print $len }
84 ' output
87 # Note that this whole setup is pretty reliant on the current
88 # packing heuristics. We double-check that our test case
89 # actually produces a long chain. If it doesn't, it should be
90 # adjusted (or scrapped if the heuristics have become too unreliable)
91 test_expect_success 'packing produces a long delta' '
92 # Use --window=0 to make sure we are seeing reused deltas,
93 # not computing a new long chain.
94 pack=$(git pack-objects --all --window=0 </dev/null pack) &&
95 echo 9 >expect &&
96 max_chain pack-$pack.pack >actual &&
97 test_cmp expect actual
100 test_expect_success '--depth limits depth' '
101 pack=$(git pack-objects --all --depth=5 </dev/null pack) &&
102 echo 5 >expect &&
103 max_chain pack-$pack.pack >actual &&
104 test_cmp expect actual
107 test_expect_success '--depth=0 disables deltas' '
108 pack=$(git pack-objects --all --depth=0 </dev/null pack) &&
109 echo 0 >expect &&
110 max_chain pack-$pack.pack >actual &&
111 test_cmp expect actual
114 test_expect_success 'negative depth disables deltas' '
115 pack=$(git pack-objects --all --depth=-1 </dev/null pack) &&
116 echo 0 >expect &&
117 max_chain pack-$pack.pack >actual &&
118 test_cmp expect actual
121 test_done