-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
- Loading branch information
Thomas Rast
authored and
Junio C Hamano
committed
Dec 6, 2011
1 parent
1aed2fe
commit 4eb0346
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/bin/sh | ||
|
||
test_description="Test whether cache-tree is properly updated | ||
Tests whether various commands properly update and/or rewrite the | ||
cache-tree extension. | ||
" | ||
. ./test-lib.sh | ||
|
||
cmp_cache_tree () { | ||
test-dump-cache-tree >actual && | ||
sed "s/$_x40/SHA/" <actual >filtered && | ||
test_cmp "$1" filtered | ||
} | ||
|
||
# We don't bother with actually checking the SHA1: | ||
# test-dump-cache-tree already verifies that all existing data is | ||
# correct. | ||
test_shallow_cache_tree () { | ||
echo "SHA " \ | ||
"($(git ls-files|wc -l) entries, 0 subtrees)" >expect && | ||
cmp_cache_tree expect | ||
} | ||
|
||
test_invalid_cache_tree () { | ||
echo "invalid (0 subtrees)" >expect && | ||
echo "SHA #(ref) " \ | ||
"($(git ls-files|wc -l) entries, 0 subtrees)" >>expect && | ||
cmp_cache_tree expect | ||
} | ||
|
||
test_no_cache_tree () { | ||
: >expect && | ||
cmp_cache_tree expect | ||
} | ||
|
||
test_expect_failure 'initial commit has cache-tree' ' | ||
test_commit foo && | ||
test_shallow_cache_tree | ||
' | ||
|
||
test_expect_success 'read-tree HEAD establishes cache-tree' ' | ||
git read-tree HEAD && | ||
test_shallow_cache_tree | ||
' | ||
|
||
test_expect_success 'git-add invalidates cache-tree' ' | ||
test_when_finished "git reset --hard; git read-tree HEAD" && | ||
echo "I changed this file" > foo && | ||
git add foo && | ||
test_invalid_cache_tree | ||
' | ||
|
||
test_expect_success 'update-index invalidates cache-tree' ' | ||
test_when_finished "git reset --hard; git read-tree HEAD" && | ||
echo "I changed this file" > foo && | ||
git update-index --add foo && | ||
test_invalid_cache_tree | ||
' | ||
|
||
test_expect_success 'write-tree establishes cache-tree' ' | ||
test-scrap-cache-tree && | ||
git write-tree && | ||
test_shallow_cache_tree | ||
' | ||
|
||
test_expect_success 'test-scrap-cache-tree works' ' | ||
git read-tree HEAD && | ||
test-scrap-cache-tree && | ||
test_no_cache_tree | ||
' | ||
|
||
test_expect_failure 'second commit has cache-tree' ' | ||
test_commit bar && | ||
test_shallow_cache_tree | ||
' | ||
|
||
test_expect_failure 'reset --hard gives cache-tree' ' | ||
test-scrap-cache-tree && | ||
git reset --hard && | ||
test_shallow_cache_tree | ||
' | ||
|
||
test_expect_failure 'reset --hard without index gives cache-tree' ' | ||
rm -f .git/index && | ||
git reset --hard && | ||
test_shallow_cache_tree | ||
' | ||
|
||
test_expect_failure 'checkout gives cache-tree' ' | ||
git checkout HEAD^ && | ||
test_shallow_cache_tree | ||
' | ||
|
||
test_done |