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 -z "$GIT_NOTES_TIMING_TESTS" && {
11 say Skipping timing tests
12 test_done
13 exit
14}
15
16create_repo () {
17 number_of_commits=$1
18 nr=0
19 parent=
20 test -d .git || {
21 git init &&
22 tree=$(git write-tree) &&
23 while [ $nr -lt $number_of_commits ]; do
24 test_tick &&
25 commit=$(echo $nr | git commit-tree $tree $parent) ||
26 return
27 parent="-p $commit"
28 nr=$(($nr+1))
29 done &&
30 git update-ref refs/heads/master $commit &&
31 {
32 export GIT_INDEX_FILE=.git/temp;
33 git rev-list HEAD | cat -n | sed "s/^[ ][ ]*/ /g" |
34 while read nr sha1; do
35 blob=$(echo note $nr | git hash-object -w --stdin) &&
36 echo $sha1 | sed "s/^/0644 $blob 0 /"
37 done | git update-index --index-info &&
38 tree=$(git write-tree) &&
39 test_tick &&
40 commit=$(echo notes | git commit-tree $tree) &&
41 git update-ref refs/notes/commits $commit
42 } &&
43 git config core.notesRef refs/notes/commits
44 }
45}
46
47test_notes () {
48 count=$1 &&
49 git config core.notesRef refs/notes/commits &&
50 git log | grep "^ " > output &&
51 i=1 &&
52 while [ $i -le $count ]; do
53 echo " $(($count-$i))" &&
54 echo " note $i" &&
55 i=$(($i+1));
56 done > expect &&
57 git diff expect output
58}
59
60cat > time_notes << \EOF
61 mode=$1
62 i=1
63 while [ $i -lt $2 ]; do
64 case $1 in
65 no-notes)
66 export GIT_NOTES_REF=non-existing
67 ;;
68 notes)
69 unset GIT_NOTES_REF
70 ;;
71 esac
72 git log >/dev/null
73 i=$(($i+1))
74 done
75EOF
76
77time_notes () {
78 for mode in no-notes notes
79 do
80 echo $mode
81 /usr/bin/time sh ../time_notes $mode $1
82 done
83}
84
85for count in 10 100 1000 10000; do
86
87 mkdir $count
88 (cd $count;
89
90 test_expect_success "setup $count" "create_repo $count"
91
92 test_expect_success 'notes work' "test_notes $count"
93
94 test_expect_success 'notes timing' "time_notes 100"
95 )
96done
97
98test_done