3 test_description
='Test that adding/removing many notes triggers automatic fanout restructuring'
10 after_last_slash
=$
(($
(test_oid hexsz
) - $fanout * 2)) &&
11 echo $path |
grep -q "^\([0-9a-f]\{2\}/\)\{$fanout\}[0-9a-f]\{$after_last_slash\}$"
14 touched_one_note_with_fanout
() {
16 modification
=$2 && # 'A' for addition, 'D' for deletion
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;
23 all_notes_have_fanout
() {
26 git ls-tree
-r --name-only $notes_commit 2>/dev
/null |
29 path_has_fanout
$path $fanout ||
return 1
33 test_expect_success
'tweak test environment' '
34 git checkout -b nondeterminism &&
36 git checkout --orphan with_notes;
39 test_expect_success
'creating many notes with git-notes' '
42 while test $i -lt $num_notes
46 echo "file for commit #$i" > file &&
48 git commit -q -m "commit #$i" &&
49 git notes add -m "note #$i" || return 1
53 test_expect_success
'many notes created correctly with git-notes' '
54 git log | grep "^ " > output &&
62 test_cmp expect output
65 test_expect_success
'stable fanout 0 is followed by stable fanout 1' '
71 if touched_one_note_with_fanout refs/notes/commits~$i A $fanout
74 elif test $fanout -eq 0
77 if all_notes_have_fanout refs/notes/commits~$i $fanout
79 echo "Fanout 0 -> 1 at refs/notes/commits~$i" &&
83 echo "Failed fanout=$fanout check at refs/notes/commits~$i" &&
84 git ls-tree -r --name-only refs/notes/commits~$i &&
87 all_notes_have_fanout refs/notes/commits 1
90 test_expect_success
'deleting most notes with git-notes' '
94 while test $i -lt $remove_notes && read sha1
98 git notes remove "$sha1" 2>/dev/null || return 1
102 test_expect_success
'most notes deleted correctly with git-notes' '
103 git log HEAD~$remove_notes | grep "^ " > output &&
104 i=$(($num_notes - $remove_notes)) &&
107 echo " commit #$i" &&
111 test_cmp expect output
114 test_expect_success
'stable fanout 1 is followed by stable fanout 0' '
120 if touched_one_note_with_fanout refs/notes/commits~$i D $fanout
123 elif test $fanout -eq 1
126 if all_notes_have_fanout refs/notes/commits~$i $fanout
128 echo "Fanout 1 -> 0 at refs/notes/commits~$i" &&
132 echo "Failed fanout=$fanout check at refs/notes/commits~$i" &&
133 git ls-tree -r --name-only refs/notes/commits~$i &&
136 all_notes_have_fanout refs/notes/commits 0