@@ -4,6 +4,38 @@ test_description='Test that adding/removing many notes triggers automatic fanout
4
4
5
5
. ./test-lib.sh
6
6
7
+ path_has_fanout () {
8
+ path=$1 &&
9
+ fanout=$2 &&
10
+ after_last_slash=$(( 40 - $fanout * 2 )) &&
11
+ echo $path | grep -q " ^\([0-9a-f]\{2\}/\)\{$fanout \}[0-9a-f]\{$after_last_slash \}$"
12
+ }
13
+
14
+ touched_one_note_with_fanout () {
15
+ notes_commit=$1 &&
16
+ modification=$2 && # 'A' for addition, 'D' for deletion
17
+ fanout=$3 &&
18
+ diff=$( git diff-tree --no-commit-id --name-status --root -r $notes_commit ) &&
19
+ path=$( echo $diff | sed -e " s/^$modification [\t ]//" ) &&
20
+ path_has_fanout " $path " $fanout ;
21
+ }
22
+
23
+ all_notes_have_fanout () {
24
+ notes_commit=$1 &&
25
+ fanout=$2 &&
26
+ git ls-tree -r --name-only $notes_commit 2> /dev/null |
27
+ while read path
28
+ do
29
+ path_has_fanout $path $fanout || return 1
30
+ done
31
+ }
32
+
33
+ test_expect_success ' tweak test environment' '
34
+ git checkout -b nondeterminism &&
35
+ test_commit A &&
36
+ git checkout --orphan with_notes;
37
+ '
38
+
7
39
test_expect_success ' creating many notes with git-notes' '
8
40
num_notes=300 &&
9
41
i=0 &&
@@ -20,7 +52,7 @@ test_expect_success 'creating many notes with git-notes' '
20
52
21
53
test_expect_success ' many notes created correctly with git-notes' '
22
54
git log | grep "^ " > output &&
23
- i=300 &&
55
+ i=$num_notes &&
24
56
while test $i -gt 0
25
57
do
26
58
echo " commit #$i" &&
@@ -30,34 +62,46 @@ test_expect_success 'many notes created correctly with git-notes' '
30
62
test_cmp expect output
31
63
'
32
64
33
- test_expect_success ' many notes created with git-notes triggers fanout' '
34
- # Expect entire notes tree to have a fanout == 1
35
- git ls-tree -r --name-only refs/notes/commits |
36
- while read path
65
+ test_expect_success ' stable fanout 0 is followed by stable fanout 1 ' '
66
+ i=$num_notes &&
67
+ fanout=0 &&
68
+ while test $i -gt 0
37
69
do
38
- echo $path | grep "^../[0-9a-f]*$" || {
39
- echo "Invalid path \"$path\"" &&
40
- return 1;
41
- }
42
- done
70
+ i=$(($i - 1)) &&
71
+ if touched_one_note_with_fanout refs/notes/commits~$i A $fanout
72
+ then
73
+ continue
74
+ elif test $fanout -eq 0
75
+ then
76
+ fanout=1 &&
77
+ if all_notes_have_fanout refs/notes/commits~$i $fanout
78
+ then
79
+ echo "Fanout 0 -> 1 at refs/notes/commits~$i" &&
80
+ continue
81
+ fi
82
+ fi &&
83
+ echo "Failed fanout=$fanout check at refs/notes/commits~$i" &&
84
+ git ls-tree -r --name-only refs/notes/commits~$i &&
85
+ return 1
86
+ done &&
87
+ all_notes_have_fanout refs/notes/commits 1
43
88
'
44
89
45
90
test_expect_success ' deleting most notes with git-notes' '
46
- num_notes=250 &&
91
+ remove_notes=285 &&
47
92
i=0 &&
48
93
git rev-list HEAD |
49
- while test $i -lt $num_notes && read sha1
94
+ while test $i -lt $remove_notes && read sha1
50
95
do
51
96
i=$(($i + 1)) &&
52
97
test_tick &&
53
- git notes remove "$sha1" ||
54
- exit 1
98
+ git notes remove "$sha1" 2>/dev/null || return 1
55
99
done
56
100
'
57
101
58
102
test_expect_success ' most notes deleted correctly with git-notes' '
59
- git log HEAD~250 | grep "^ " > output &&
60
- i=50 &&
103
+ git log HEAD~$remove_notes | grep "^ " > output &&
104
+ i=$(($num_notes - $remove_notes)) &&
61
105
while test $i -gt 0
62
106
do
63
107
echo " commit #$i" &&
@@ -67,16 +111,29 @@ test_expect_success 'most notes deleted correctly with git-notes' '
67
111
test_cmp expect output
68
112
'
69
113
70
- test_expect_success ' deleting most notes triggers fanout consolidation ' '
71
- # Expect entire notes tree to have a fanout == 0
72
- git ls-tree -r --name-only refs/notes/commits |
73
- while read path
114
+ test_expect_success ' stable fanout 1 is followed by stable fanout 0 ' '
115
+ i=$remove_notes &&
116
+ fanout=1 &&
117
+ while test $i -gt 0
74
118
do
75
- echo $path | grep -v "^../.*" || {
76
- echo "Invalid path \"$path\"" &&
77
- return 1;
78
- }
79
- done
119
+ i=$(($i - 1)) &&
120
+ if touched_one_note_with_fanout refs/notes/commits~$i D $fanout
121
+ then
122
+ continue
123
+ elif test $fanout -eq 1
124
+ then
125
+ fanout=0 &&
126
+ if all_notes_have_fanout refs/notes/commits~$i $fanout
127
+ then
128
+ echo "Fanout 1 -> 0 at refs/notes/commits~$i" &&
129
+ continue
130
+ fi
131
+ fi &&
132
+ echo "Failed fanout=$fanout check at refs/notes/commits~$i" &&
133
+ git ls-tree -r --name-only refs/notes/commits~$i &&
134
+ return 1
135
+ done &&
136
+ all_notes_have_fanout refs/notes/commits 0
80
137
'
81
138
82
139
test_done
0 commit comments