Merge branch 'ks/combine-diff'
[git] / t / t5310-pack-bitmaps.sh
1 #!/bin/sh
2
3 test_description='exercise basic bitmap functionality'
4 . ./test-lib.sh
5
6 test_expect_success 'setup repo with moderate-sized history' '
7         for i in $(test_seq 1 10); do
8                 test_commit $i
9         done &&
10         git checkout -b other HEAD~5 &&
11         for i in $(test_seq 1 10); do
12                 test_commit side-$i
13         done &&
14         git checkout master &&
15         blob=$(echo tagged-blob | git hash-object -w --stdin) &&
16         git tag tagged-blob $blob &&
17         git config pack.writebitmaps true &&
18         git config pack.writebitmaphashcache true
19 '
20
21 test_expect_success 'full repack creates bitmaps' '
22         git repack -ad &&
23         ls .git/objects/pack/ | grep bitmap >output &&
24         test_line_count = 1 output
25 '
26
27 test_expect_success 'rev-list --test-bitmap verifies bitmaps' '
28         git rev-list --test-bitmap HEAD
29 '
30
31 rev_list_tests() {
32         state=$1
33
34         test_expect_success "counting commits via bitmap ($state)" '
35                 git rev-list --count HEAD >expect &&
36                 git rev-list --use-bitmap-index --count HEAD >actual &&
37                 test_cmp expect actual
38         '
39
40         test_expect_success "counting partial commits via bitmap ($state)" '
41                 git rev-list --count HEAD~5..HEAD >expect &&
42                 git rev-list --use-bitmap-index --count HEAD~5..HEAD >actual &&
43                 test_cmp expect actual
44         '
45
46         test_expect_success "counting non-linear history ($state)" '
47                 git rev-list --count other...master >expect &&
48                 git rev-list --use-bitmap-index --count other...master >actual &&
49                 test_cmp expect actual
50         '
51
52         test_expect_success "enumerate --objects ($state)" '
53                 git rev-list --objects --use-bitmap-index HEAD >tmp &&
54                 cut -d" " -f1 <tmp >tmp2 &&
55                 sort <tmp2 >actual &&
56                 git rev-list --objects HEAD >tmp &&
57                 cut -d" " -f1 <tmp >tmp2 &&
58                 sort <tmp2 >expect &&
59                 test_cmp expect actual
60         '
61
62         test_expect_success "bitmap --objects handles non-commit objects ($state)" '
63                 git rev-list --objects --use-bitmap-index HEAD tagged-blob >actual &&
64                 grep $blob actual
65         '
66 }
67
68 rev_list_tests 'full bitmap'
69
70 test_expect_success 'clone from bitmapped repository' '
71         git clone --no-local --bare . clone.git &&
72         git rev-parse HEAD >expect &&
73         git --git-dir=clone.git rev-parse HEAD >actual &&
74         test_cmp expect actual
75 '
76
77 test_expect_success 'setup further non-bitmapped commits' '
78         for i in $(test_seq 1 10); do
79                 test_commit further-$i
80         done
81 '
82
83 rev_list_tests 'partial bitmap'
84
85 test_expect_success 'fetch (partial bitmap)' '
86         git --git-dir=clone.git fetch origin master:master &&
87         git rev-parse HEAD >expect &&
88         git --git-dir=clone.git rev-parse HEAD >actual &&
89         test_cmp expect actual
90 '
91
92 test_expect_success 'incremental repack cannot create bitmaps' '
93         test_commit more-1 &&
94         test_must_fail git repack -d
95 '
96
97 test_expect_success 'incremental repack can disable bitmaps' '
98         test_commit more-2 &&
99         git repack -d --no-write-bitmap-index
100 '
101
102 test_expect_success 'full repack, reusing previous bitmaps' '
103         git repack -ad &&
104         ls .git/objects/pack/ | grep bitmap >output &&
105         test_line_count = 1 output
106 '
107
108 test_expect_success 'fetch (full bitmap)' '
109         git --git-dir=clone.git fetch origin master:master &&
110         git rev-parse HEAD >expect &&
111         git --git-dir=clone.git rev-parse HEAD >actual &&
112         test_cmp expect actual
113 '
114
115 test_lazy_prereq JGIT '
116         type jgit
117 '
118
119 test_expect_success JGIT 'we can read jgit bitmaps' '
120         git clone . compat-jgit &&
121         (
122                 cd compat-jgit &&
123                 rm -f .git/objects/pack/*.bitmap &&
124                 jgit gc &&
125                 git rev-list --test-bitmap HEAD
126         )
127 '
128
129 test_expect_success JGIT 'jgit can read our bitmaps' '
130         git clone . compat-us &&
131         (
132                 cd compat-us &&
133                 git repack -adb &&
134                 # jgit gc will barf if it does not like our bitmaps
135                 jgit gc
136         )
137 '
138
139 test_done