blob: 7217c5e222baf0b99b934e36b9418c9d8e13ae9d [file] [log] [blame]
Johannes Schindelina5b0c242009-10-09 12:22:00 +02001#!/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
Johannes Schindelina5b0c242009-10-09 12:22:00 +020010create_repo () {
11 number_of_commits=$1
12 nr=0
Johannes Schindelina5b0c242009-10-09 12:22:00 +020013 test -d .git || {
14 git init &&
Johan Herland3ed24b62009-10-09 12:22:03 +020015 (
Junio C Hamanoac2803b2014-06-09 13:21:59 -070016 while test $nr -lt $number_of_commits
17 do
Johan Herland3ed24b62009-10-09 12:22:03 +020018 nr=$(($nr+1))
19 mark=$(($nr+$nr))
20 notemark=$(($mark+1))
21 test_tick &&
Junio C Hamanoac2803b2014-06-09 13:21:59 -070022 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
Johan Herland3ed24b62009-10-09 12:22:03 +020029
Junio C Hamanoac2803b2014-06-09 13:21:59 -070030 M 644 inline file
31 data <<EOF
32 file in commit #$nr
33 EOF
Johan Herland3ed24b62009-10-09 12:22:03 +020034
Junio C Hamanoac2803b2014-06-09 13:21:59 -070035 blob
36 mark :$notemark
37 data <<EOF
38 note for commit #$nr
39 EOF
Johan Herland3ed24b62009-10-09 12:22:03 +020040
Junio C Hamanoac2803b2014-06-09 13:21:59 -070041 INPUT_END
42 echo "N :$notemark :$mark" >>note_commit
Johan Herland3ed24b62009-10-09 12:22:03 +020043 done &&
Johannes Schindelina5b0c242009-10-09 12:22:00 +020044 test_tick &&
Junio C Hamanoac2803b2014-06-09 13:21:59 -070045 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
Johan Herland3ed24b62009-10-09 12:22:03 +020051
Junio C Hamanoac2803b2014-06-09 13:21:59 -070052 INPUT_END
Johan Herland3ed24b62009-10-09 12:22:03 +020053
54 cat note_commit
55 ) |
56 git fast-import --quiet &&
Johannes Schindelina5b0c242009-10-09 12:22:00 +020057 git config core.notesRef refs/notes/commits
58 }
59}
60
61test_notes () {
62 count=$1 &&
63 git config core.notesRef refs/notes/commits &&
Junio C Hamanoac2803b2014-06-09 13:21:59 -070064 git log | grep "^ " >output &&
Johan Herland3ed24b62009-10-09 12:22:03 +020065 i=$count &&
Junio C Hamanoac2803b2014-06-09 13:21:59 -070066 while test $i -gt 0
67 do
Johan Herland3ed24b62009-10-09 12:22:03 +020068 echo " commit #$i" &&
69 echo " note for commit #$i" &&
Junio C Hamanoac2803b2014-06-09 13:21:59 -070070 i=$(($i-1))
71 done >expect &&
Johan Herland3ed24b62009-10-09 12:22:03 +020072 test_cmp expect output
Johannes Schindelina5b0c242009-10-09 12:22:00 +020073}
74
Junio C Hamanoac2803b2014-06-09 13:21:59 -070075write_script time_notes <<\EOF
Johannes Schindelina5b0c242009-10-09 12:22:00 +020076 mode=$1
77 i=1
Junio C Hamanoac2803b2014-06-09 13:21:59 -070078 while test $i -lt $2
79 do
Johannes Schindelina5b0c242009-10-09 12:22:00 +020080 case $1 in
81 no-notes)
Junio C Hamanoac2803b2014-06-09 13:21:59 -070082 GIT_NOTES_REF=non-existing
83 export GIT_NOTES_REF
84 ;;
Johannes Schindelina5b0c242009-10-09 12:22:00 +020085 notes)
86 unset GIT_NOTES_REF
Junio C Hamanoac2803b2014-06-09 13:21:59 -070087 ;;
Johannes Schindelina5b0c242009-10-09 12:22:00 +020088 esac
Junio C Hamanoac2803b2014-06-09 13:21:59 -070089 git log
Johannes Schindelina5b0c242009-10-09 12:22:00 +020090 i=$(($i+1))
Junio C Hamanoac2803b2014-06-09 13:21:59 -070091 done >/dev/null
Johannes Schindelina5b0c242009-10-09 12:22:00 +020092EOF
93
94time_notes () {
95 for mode in no-notes notes
96 do
97 echo $mode
Junio C Hamanoac2803b2014-06-09 13:21:59 -070098 /usr/bin/time ../time_notes $mode $1
Johannes Schindelina5b0c242009-10-09 12:22:00 +020099 done
100}
101
Ævar Arnfjörð Bjarmasond0736f72010-08-10 23:37:48 +0000102do_tests () {
Junio C Hamano19c8c4a2014-06-09 13:43:19 -0700103 count=$1 pr=${2-}
Johannes Schindelina5b0c242009-10-09 12:22:00 +0200104
Junio C Hamanof23b1d02014-06-09 13:36:54 -0700105 test_expect_success $pr "setup $count" '
106 mkdir "$count" &&
107 (
108 cd "$count" &&
109 create_repo "$count"
110 )
Ævar Arnfjörð Bjarmasond0736f72010-08-10 23:37:48 +0000111 '
Johannes Schindelina5b0c242009-10-09 12:22:00 +0200112
Junio C Hamanof23b1d02014-06-09 13:36:54 -0700113 test_expect_success $pr 'notes work' '
114 (
115 cd "$count" &&
116 test_notes "$count"
117 )
118 '
Johannes Schindelina5b0c242009-10-09 12:22:00 +0200119
Junio C Hamano19c8c4a2014-06-09 13:43:19 -0700120 test_expect_success "USR_BIN_TIME${pr:+,$pr}" 'notes timing with /usr/bin/time' '
Junio C Hamanof23b1d02014-06-09 13:36:54 -0700121 (
122 cd "$count" &&
123 time_notes 100
124 )
125 '
Ævar Arnfjörð Bjarmasond0736f72010-08-10 23:37:48 +0000126}
127
Junio C Hamano19c8c4a2014-06-09 13:43:19 -0700128do_tests 10
Junio C Hamanoac2803b2014-06-09 13:21:59 -0700129for count in 100 1000 10000
130do
Junio C Hamano19c8c4a2014-06-09 13:43:19 -0700131 do_tests "$count" EXPENSIVE
Johannes Schindelina5b0c242009-10-09 12:22:00 +0200132done
133
134test_done