1#!/bin/sh
2#
3# Copyright (c) 2007 Johannes E. Schindelin
4#
56
test_description='Test commit notes index (expensive!)'
78
. ./test-lib.sh
910
create_repo () {
11number_of_commits=$1
12nr=0
13test -d .git || {
14git init &&
15(
16while test $nr -lt $number_of_commits
17do
18nr=$(($nr+1))
19mark=$(($nr+$nr))
20notemark=$(($mark+1))
21test_tick &&
22cat <<-INPUT_END &&
23commit refs/heads/master
24mark :$mark
25committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
26data <<COMMIT
27commit #$nr
28COMMIT
2930
M 644 inline file
31data <<EOF
32file in commit #$nr
33EOF
3435
blob
36mark :$notemark
37data <<EOF
38note for commit #$nr
39EOF
4041
INPUT_END
42echo "N :$notemark :$mark" >>note_commit
43done &&
44test_tick &&
45cat <<-INPUT_END &&
46commit refs/notes/commits
47committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
48data <<COMMIT
49notes
50COMMIT
5152
INPUT_END
5354
cat note_commit
55) |
56git fast-import --quiet &&
57git config core.notesRef refs/notes/commits
58}
59}
6061
test_notes () {
62count=$1 &&
63git config core.notesRef refs/notes/commits &&
64git log | grep "^ " >output &&
65i=$count &&
66while test $i -gt 0
67do
68echo " commit #$i" &&
69echo " note for commit #$i" &&
70i=$(($i-1))
71done >expect &&
72test_cmp expect output
73}
7475
write_script time_notes <<\EOF
76mode=$1
77i=1
78while test $i -lt $2
79do
80case $1 in
81no-notes)
82GIT_NOTES_REF=non-existing
83export GIT_NOTES_REF
84;;
85notes)
86unset GIT_NOTES_REF
87;;
88esac
89git log
90i=$(($i+1))
91done >/dev/null
92EOF
9394
time_notes () {
95for mode in no-notes notes
96do
97echo $mode
98/usr/bin/time ../time_notes $mode $1
99done
100}
101102
do_tests () {
103count=$1 pr=${2-}
104105
test_expect_success $pr "setup $count" '
106mkdir "$count" &&
107(
108cd "$count" &&
109create_repo "$count"
110)
111'
112113
test_expect_success $pr 'notes work' '
114(
115cd "$count" &&
116test_notes "$count"
117)
118'
119120
test_expect_success "USR_BIN_TIME${pr:+,$pr}" 'notes timing with /usr/bin/time' '
121(
122cd "$count" &&
123time_notes 100
124)
125'
126}
127128
do_tests 10
129for count in 100 1000 10000
130do
131do_tests "$count" EXPENSIVE
132done
133134
test_done