Merge branch 'lh/submodule-tree-traversal' (early part)
[git/dscho.git] / t / t3302-notes-index-expensive.sh
blob00d27bf6ef0b1003d0dfedb9eea522467284ce00
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='Test commit notes index (expensive!)'
8 . ./test-lib.sh
10 test -z "$GIT_NOTES_TIMING_TESTS" && {
11 say Skipping timing tests
12 test_done
13 exit
16 create_repo () {
17 number_of_commits=$1
18 nr=0
19 parent=
20 test -d .git || {
21 git init &&
22 tree=$(git write-tree) &&
23 while [ $nr -lt $number_of_commits ]; do
24 test_tick &&
25 commit=$(echo $nr | git commit-tree $tree $parent) ||
26 return
27 parent="-p $commit"
28 nr=$(($nr+1))
29 done &&
30 git update-ref refs/heads/master $commit &&
32 export GIT_INDEX_FILE=.git/temp;
33 git rev-list HEAD | cat -n | sed "s/^[ ][ ]*/ /g" |
34 while read nr sha1; do
35 blob=$(echo note $nr | git hash-object -w --stdin) &&
36 echo $sha1 | sed "s/^/0644 $blob 0 /"
37 done | git update-index --index-info &&
38 tree=$(git write-tree) &&
39 test_tick &&
40 commit=$(echo notes | git commit-tree $tree) &&
41 git update-ref refs/notes/commits $commit
42 } &&
43 git config core.notesRef refs/notes/commits
47 test_notes () {
48 count=$1 &&
49 git config core.notesRef refs/notes/commits &&
50 git log | grep "^ " > output &&
51 i=1 &&
52 while [ $i -le $count ]; do
53 echo " $(($count-$i))" &&
54 echo " note $i" &&
55 i=$(($i+1));
56 done > expect &&
57 git diff expect output
60 cat > time_notes << \EOF
61 mode=$1
62 i=1
63 while [ $i -lt $2 ]; do
64 case $1 in
65 no-notes)
66 export GIT_NOTES_REF=non-existing
68 notes)
69 unset GIT_NOTES_REF
71 esac
72 git log >/dev/null
73 i=$(($i+1))
74 done
75 EOF
77 time_notes () {
78 for mode in no-notes notes
80 echo $mode
81 /usr/bin/time sh ../time_notes $mode $1
82 done
85 for count in 10 100 1000 10000; do
87 mkdir $count
88 (cd $count;
90 test_expect_success "setup $count" "create_repo $count"
92 test_expect_success 'notes work' "test_notes $count"
94 test_expect_success 'notes timing' "time_notes 100"
96 done
98 test_done