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