Skip to content

Commit 4eb0346

Browse files
trastgitster
authored andcommitted
Test the current state of the cache-tree optimization
The cache-tree optimization originally helped speed up write-tree operation. However, many commands no longer properly maintain -- or use an opportunity to cheaply generate -- the cache-tree data. In particular, this affects commit, checkout and reset. The notable examples that *do* write cache-tree data are read-tree and write-tree. This sadly means most people no longer benefit from the optimization, as they would not normally use the plumbing commands. Document the current state of affairs in a test file, in preparation for improvements in the area. Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1aed2fe commit 4eb0346

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

t/t0090-cache-tree.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/sh
2+
3+
test_description="Test whether cache-tree is properly updated
4+
5+
Tests whether various commands properly update and/or rewrite the
6+
cache-tree extension.
7+
"
8+
. ./test-lib.sh
9+
10+
cmp_cache_tree () {
11+
test-dump-cache-tree >actual &&
12+
sed "s/$_x40/SHA/" <actual >filtered &&
13+
test_cmp "$1" filtered
14+
}
15+
16+
# We don't bother with actually checking the SHA1:
17+
# test-dump-cache-tree already verifies that all existing data is
18+
# correct.
19+
test_shallow_cache_tree () {
20+
echo "SHA " \
21+
"($(git ls-files|wc -l) entries, 0 subtrees)" >expect &&
22+
cmp_cache_tree expect
23+
}
24+
25+
test_invalid_cache_tree () {
26+
echo "invalid (0 subtrees)" >expect &&
27+
echo "SHA #(ref) " \
28+
"($(git ls-files|wc -l) entries, 0 subtrees)" >>expect &&
29+
cmp_cache_tree expect
30+
}
31+
32+
test_no_cache_tree () {
33+
: >expect &&
34+
cmp_cache_tree expect
35+
}
36+
37+
test_expect_failure 'initial commit has cache-tree' '
38+
test_commit foo &&
39+
test_shallow_cache_tree
40+
'
41+
42+
test_expect_success 'read-tree HEAD establishes cache-tree' '
43+
git read-tree HEAD &&
44+
test_shallow_cache_tree
45+
'
46+
47+
test_expect_success 'git-add invalidates cache-tree' '
48+
test_when_finished "git reset --hard; git read-tree HEAD" &&
49+
echo "I changed this file" > foo &&
50+
git add foo &&
51+
test_invalid_cache_tree
52+
'
53+
54+
test_expect_success 'update-index invalidates cache-tree' '
55+
test_when_finished "git reset --hard; git read-tree HEAD" &&
56+
echo "I changed this file" > foo &&
57+
git update-index --add foo &&
58+
test_invalid_cache_tree
59+
'
60+
61+
test_expect_success 'write-tree establishes cache-tree' '
62+
test-scrap-cache-tree &&
63+
git write-tree &&
64+
test_shallow_cache_tree
65+
'
66+
67+
test_expect_success 'test-scrap-cache-tree works' '
68+
git read-tree HEAD &&
69+
test-scrap-cache-tree &&
70+
test_no_cache_tree
71+
'
72+
73+
test_expect_failure 'second commit has cache-tree' '
74+
test_commit bar &&
75+
test_shallow_cache_tree
76+
'
77+
78+
test_expect_failure 'reset --hard gives cache-tree' '
79+
test-scrap-cache-tree &&
80+
git reset --hard &&
81+
test_shallow_cache_tree
82+
'
83+
84+
test_expect_failure 'reset --hard without index gives cache-tree' '
85+
rm -f .git/index &&
86+
git reset --hard &&
87+
test_shallow_cache_tree
88+
'
89+
90+
test_expect_failure 'checkout gives cache-tree' '
91+
git checkout HEAD^ &&
92+
test_shallow_cache_tree
93+
'
94+
95+
test_done

0 commit comments

Comments
 (0)