3 test_description
='Test that adding/removing many notes triggers automatic fanout restructuring'
5 TEST_PASSES_SANITIZE_LEAK
=true
11 after_last_slash
=$
(($
(test_oid hexsz
) - $fanout * 2)) &&
12 echo $path |
grep -q "^\([0-9a-f]\{2\}/\)\{$fanout\}[0-9a-f]\{$after_last_slash\}$"
15 touched_one_note_with_fanout
() {
17 modification
=$2 && # 'A' for addition, 'D' for deletion
19 diff=$
(git diff-tree
--no-commit-id --name-status --root -r $notes_commit) &&
20 path
=$
(echo $diff |
sed -e "s/^$modification[\t ]//") &&
21 path_has_fanout
"$path" $fanout;
24 all_notes_have_fanout
() {
27 git ls-tree
-r --name-only $notes_commit |
30 path_has_fanout
$path $fanout ||
return 1
34 test_expect_success
'tweak test environment' '
35 git checkout -b nondeterminism &&
37 git checkout --orphan with_notes;
40 test_expect_success
'creating many notes with git-notes' '
43 while test $i -lt $num_notes
47 echo "file for commit #$i" > file &&
49 git commit -q -m "commit #$i" &&
50 git notes add -m "note #$i" || return 1
54 test_expect_success
'many notes created correctly with git-notes' '
55 git log >output.raw &&
56 grep "^ " output.raw >output &&
62 i=$(($i - 1)) || return 1
64 test_cmp expect output
67 test_expect_success
'stable fanout 0 is followed by stable fanout 1' '
73 if touched_one_note_with_fanout refs/notes/commits~$i A $fanout
76 elif test $fanout -eq 0
79 if all_notes_have_fanout refs/notes/commits~$i $fanout
81 echo "Fanout 0 -> 1 at refs/notes/commits~$i" &&
85 echo "Failed fanout=$fanout check at refs/notes/commits~$i" &&
86 git ls-tree -r --name-only refs/notes/commits~$i &&
89 all_notes_have_fanout refs/notes/commits 1
92 test_expect_success
'deleting most notes with git-notes' '
95 git rev-list HEAD >revs &&
96 while test $i -lt $remove_notes && read sha1
100 git notes remove "$sha1" || return 1
104 test_expect_success
'most notes deleted correctly with git-notes' '
105 git log HEAD~$remove_notes | grep "^ " > output &&
106 i=$(($num_notes - $remove_notes)) &&
109 echo " commit #$i" &&
111 i=$(($i - 1)) || return 1
113 test_cmp expect output
116 test_expect_success
'stable fanout 1 is followed by stable fanout 0' '
122 if touched_one_note_with_fanout refs/notes/commits~$i D $fanout
125 elif test $fanout -eq 1
128 if all_notes_have_fanout refs/notes/commits~$i $fanout
130 echo "Fanout 1 -> 0 at refs/notes/commits~$i" &&
134 echo "Failed fanout=$fanout check at refs/notes/commits~$i" &&
135 git ls-tree -r --name-only refs/notes/commits~$i &&
138 all_notes_have_fanout refs/notes/commits 0