4
5
. ./test-lib.sh
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 'creating many notes with git-notes' '
34
num_notes=300 &&
35
i=0 &&
46
47
test_expect_success 'many notes created correctly with git-notes' '
48
git log | grep "^ " > output &&
23
- i=300 &&
49
+ i=$num_notes &&
50
while test $i -gt 0
51
do
52
echo " commit #$i" &&
56
test_cmp expect output
57
'
58
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
59
+test_expect_success 'stable fanout 0 is followed by stable fanout 1' '
60
+ i=$num_notes &&
61
+ fanout=0 &&
62
+ while test $i -gt 0
63
do
38
- echo $path | grep "^../[0-9a-f]*$" || {
39
- echo "Invalid path \"$path\"" &&
40
- return 1;
41
- }
42
- done
64
+ i=$(($i - 1)) &&
65
+ if touched_one_note_with_fanout refs/notes/commits~$i A $fanout
66
+ then
67
+ continue
68
+ elif test $fanout -eq 0
69
+ then
70
+ fanout=1 &&
71
+ if all_notes_have_fanout refs/notes/commits~$i $fanout
72
+ then
73
+ echo "Fanout 0 -> 1 at refs/notes/commits~$i" &&
74
+ continue
75
+ fi
76
+ fi &&
77
+ echo "Failed fanout=$fanout check at refs/notes/commits~$i" &&
78
+ git ls-tree -r --name-only refs/notes/commits~$i &&
79
+ return 1
80
+ done &&
81
+ all_notes_have_fanout refs/notes/commits 1
82
'
83
84
test_expect_success 'deleting most notes with git-notes' '
46
- num_notes=250 &&
85
+ remove_notes=285 &&
86
i=0 &&
87
git rev-list HEAD |
49
- while test $i -lt $num_notes && read sha1
88
+ while test $i -lt $remove_notes && read sha1
89
do
90
i=$(($i + 1)) &&
91
test_tick &&
53
- git notes remove "$sha1" ||
54
- exit 1
92
+ git notes remove "$sha1" 2>/dev/null || return 1
93
done
94
'
95
96
test_expect_success 'most notes deleted correctly with git-notes' '
59
- git log HEAD~250 | grep "^ " > output &&
60
- i=50 &&
97
+ git log HEAD~$remove_notes | grep "^ " > output &&
98
+ i=$(($num_notes - $remove_notes)) &&
99
while test $i -gt 0
100
do
101
echo " commit #$i" &&
105
test_cmp expect output
106
'
107
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
108
+test_expect_success 'stable fanout 1 is followed by stable fanout 0' '
109
+ i=$remove_notes &&
110
+ fanout=1 &&
111
+ while test $i -gt 0
112
do
75
- echo $path | grep -v "^../.*" || {
76
- echo "Invalid path \"$path\"" &&
77
- return 1;
78
- }
79
- done
113
+ i=$(($i - 1)) &&
114
+ if touched_one_note_with_fanout refs/notes/commits~$i D $fanout
115
+ then
116
+ continue
117
+ elif test $fanout -eq 1
118
+ then
119
+ fanout=0 &&
120
+ if all_notes_have_fanout refs/notes/commits~$i $fanout
121
+ then
122
+ echo "Fanout 1 -> 0 at refs/notes/commits~$i" &&
123
+ continue
124
+ fi
125
+ fi &&
126
+ echo "Failed fanout=$fanout check at refs/notes/commits~$i" &&
127
+ git ls-tree -r --name-only refs/notes/commits~$i &&
128
+ return 1
129
+ done &&
130
+ all_notes_have_fanout refs/notes/commits 0
131
'
132
133
test_done