Add an expensive test for git-notes
git-notes have the potential of being pretty expensive, so test with a lot of commits. A lot. So to make things cheaper, you have to opt-in explicitely, by setting the environment variable GIT_NOTES_TIMING_TESTS. This patch has been improved by the following contributions: - Junio C Hamano: tests: fix "export var=val" Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Oct 9, 2009 at 12:22 UTC
a5b0c24f3e9a29f8fe496f49db82f2e3f1b687ce
1 file changed
+98
t/t3302-notes-index-expensive.sh
new
+98
@@ -0,0 +1,98 @@
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 -z "$GIT_NOTES_TIMING_TESTS" && {
11
+ say Skipping timing tests
12
+ test_done
13
+ exit
14
+}
15
+
16
+create_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
+ GIT_INDEX_FILE=.git/temp; export GIT_INDEX_FILE;
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
+
47
+test_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
+
60
+cat > time_notes << \EOF
61
+ mode=$1
62
+ i=1
63
+ while [ $i -lt $2 ]; do
64
+ case $1 in
65
+ no-notes)
66
+ GIT_NOTES_REF=non-existing; export GIT_NOTES_REF
67
+ ;;
68
+ notes)
69
+ unset GIT_NOTES_REF
70
+ ;;
71
+ esac
72
+ git log >/dev/null
73
+ i=$(($i+1))
74
+ done
75
+EOF
76
+
77
+time_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
+
85
+for 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
+ )
96
+done
97
+
98
+test_done