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