Browse Source
* tr/cache-tree: t0090: be prepared that 'wc -l' writes leading blanks reset: update cache-tree data when appropriate commit: write cache-tree data when writing index anyway Refactor cache_tree_update idiom from commit Test the current state of the cache-tree optimization Add test-scrap-cache-treemaint
Junio C Hamano
13 years ago
10 changed files with 142 additions and 11 deletions
@ -0,0 +1,93 @@
@@ -0,0 +1,93 @@
|
||||
#!/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 () { |
||||
printf "SHA (%d entries, 0 subtrees)\n" $(git ls-files|wc -l) >expect && |
||||
cmp_cache_tree expect |
||||
} |
||||
|
||||
test_invalid_cache_tree () { |
||||
echo "invalid (0 subtrees)" >expect && |
||||
printf "SHA #(ref) (%d entries, 0 subtrees)\n" $(git ls-files|wc -l) >>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_success 'second commit has cache-tree' ' |
||||
test_commit bar && |
||||
test_shallow_cache_tree |
||||
' |
||||
|
||||
test_expect_success 'reset --hard gives cache-tree' ' |
||||
test-scrap-cache-tree && |
||||
git reset --hard && |
||||
test_shallow_cache_tree |
||||
' |
||||
|
||||
test_expect_success '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 |
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
#include "cache.h" |
||||
#include "tree.h" |
||||
#include "cache-tree.h" |
||||
|
||||
static struct lock_file index_lock; |
||||
|
||||
int main(int ac, char **av) |
||||
{ |
||||
int fd = hold_locked_index(&index_lock, 1); |
||||
if (read_cache() < 0) |
||||
die("unable to read index file"); |
||||
active_cache_tree = NULL; |
||||
if (write_cache(fd, active_cache, active_nr) |
||||
|| commit_lock_file(&index_lock)) |
||||
die("unable to write index file"); |
||||
return 0; |
||||
} |
Loading…
Reference in new issue