Merge branch 'tc/commit-abbrev-fix'
[git] / t / t3302-notes-index-expensive.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Johannes E. Schindelin
4 #
5
6 test_description='Test commit notes index (expensive!)'
7
8 . ./test-lib.sh
9
10 test -z "$GIT_NOTES_TIMING_TESTS" && {
11         say Skipping timing tests
12         test_done
13         exit
14 }
15
16 create_repo () {
17         number_of_commits=$1
18         nr=0
19         test -d .git || {
20         git init &&
21         (
22                 while [ $nr -lt $number_of_commits ]; do
23                         nr=$(($nr+1))
24                         mark=$(($nr+$nr))
25                         notemark=$(($mark+1))
26                         test_tick &&
27                         cat <<INPUT_END &&
28 commit refs/heads/master
29 mark :$mark
30 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
31 data <<COMMIT
32 commit #$nr
33 COMMIT
34
35 M 644 inline file
36 data <<EOF
37 file in commit #$nr
38 EOF
39
40 blob
41 mark :$notemark
42 data <<EOF
43 note for commit #$nr
44 EOF
45
46 INPUT_END
47
48                         echo "N :$notemark :$mark" >> note_commit
49                 done &&
50                 test_tick &&
51                 cat <<INPUT_END &&
52 commit refs/notes/commits
53 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
54 data <<COMMIT
55 notes
56 COMMIT
57
58 INPUT_END
59
60                 cat note_commit
61         ) |
62         git fast-import --quiet &&
63         git config core.notesRef refs/notes/commits
64         }
65 }
66
67 test_notes () {
68         count=$1 &&
69         git config core.notesRef refs/notes/commits &&
70         git log | grep "^    " > output &&
71         i=$count &&
72         while [ $i -gt 0 ]; do
73                 echo "    commit #$i" &&
74                 echo "    note for commit #$i" &&
75                 i=$(($i-1));
76         done > expect &&
77         test_cmp expect output
78 }
79
80 cat > time_notes << \EOF
81         mode=$1
82         i=1
83         while [ $i -lt $2 ]; do
84                 case $1 in
85                 no-notes)
86                         GIT_NOTES_REF=non-existing; export GIT_NOTES_REF
87                 ;;
88                 notes)
89                         unset GIT_NOTES_REF
90                 ;;
91                 esac
92                 git log >/dev/null
93                 i=$(($i+1))
94         done
95 EOF
96
97 time_notes () {
98         for mode in no-notes notes
99         do
100                 echo $mode
101                 /usr/bin/time sh ../time_notes $mode $1
102         done
103 }
104
105 for count in 10 100 1000 10000; do
106
107         mkdir $count
108         (cd $count;
109
110         test_expect_success "setup $count" "create_repo $count"
111
112         test_expect_success 'notes work' "test_notes $count"
113
114         test_expect_success 'notes timing' "time_notes 100"
115         )
116 done
117
118 test_done