Merge branch 'js/plug-leaks' into maint
[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 create_repo () {
11         number_of_commits=$1
12         nr=0
13         test -d .git || {
14         git init &&
15         (
16                 while test $nr -lt $number_of_commits
17                 do
18                         nr=$(($nr+1))
19                         mark=$(($nr+$nr))
20                         notemark=$(($mark+1))
21                         test_tick &&
22                         cat <<-INPUT_END &&
23                         commit refs/heads/master
24                         mark :$mark
25                         committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
26                         data <<COMMIT
27                         commit #$nr
28                         COMMIT
29
30                         M 644 inline file
31                         data <<EOF
32                         file in commit #$nr
33                         EOF
34
35                         blob
36                         mark :$notemark
37                         data <<EOF
38                         note for commit #$nr
39                         EOF
40
41                         INPUT_END
42                         echo "N :$notemark :$mark" >>note_commit
43                 done &&
44                 test_tick &&
45                 cat <<-INPUT_END &&
46                 commit refs/notes/commits
47                 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
48                 data <<COMMIT
49                 notes
50                 COMMIT
51
52                 INPUT_END
53
54                 cat note_commit
55         ) |
56         git fast-import --quiet &&
57         git config core.notesRef refs/notes/commits
58         }
59 }
60
61 test_notes () {
62         count=$1 &&
63         git config core.notesRef refs/notes/commits &&
64         git log | grep "^    " >output &&
65         i=$count &&
66         while test $i -gt 0
67         do
68                 echo "    commit #$i" &&
69                 echo "    note for commit #$i" &&
70                 i=$(($i-1))
71         done >expect &&
72         test_cmp expect output
73 }
74
75 write_script time_notes <<\EOF
76         mode=$1
77         i=1
78         while test $i -lt $2
79         do
80                 case $1 in
81                 no-notes)
82                         GIT_NOTES_REF=non-existing
83                         export GIT_NOTES_REF
84                         ;;
85                 notes)
86                         unset GIT_NOTES_REF
87                         ;;
88                 esac
89                 git log
90                 i=$(($i+1))
91         done >/dev/null
92 EOF
93
94 time_notes () {
95         for mode in no-notes notes
96         do
97                 echo $mode
98                 /usr/bin/time ../time_notes $mode $1
99         done
100 }
101
102 do_tests () {
103         count=$1 pr=${2-}
104
105         test_expect_success $pr "setup $count" '
106                 mkdir "$count" &&
107                 (
108                         cd "$count" &&
109                         create_repo "$count"
110                 )
111         '
112
113         test_expect_success $pr 'notes work' '
114                 (
115                         cd "$count" &&
116                         test_notes "$count"
117                 )
118         '
119
120         test_expect_success "USR_BIN_TIME${pr:+,$pr}" 'notes timing with /usr/bin/time' '
121                 (
122                         cd "$count" &&
123                         time_notes 100
124                 )
125         '
126 }
127
128 do_tests 10
129 for count in 100 1000 10000
130 do
131         do_tests "$count" EXPENSIVE
132 done
133
134 test_done