rebase: use correct base for --keep-base when a branch is given
[alt-git.git] / t / t3305-notes-fanout.sh
blob9976d787f4721c898d52eb0211399b145c9e1872
1 #!/bin/sh
3 test_description='Test that adding/removing many notes triggers automatic fanout restructuring'
5 . ./test-lib.sh
7 path_has_fanout() {
8 path=$1 &&
9 fanout=$2 &&
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() {
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;
23 all_notes_have_fanout() {
24 notes_commit=$1 &&
25 fanout=$2 &&
26 git ls-tree -r --name-only $notes_commit |
27 while read path
29 path_has_fanout $path $fanout || return 1
30 done
33 test_expect_success 'tweak test environment' '
34 git checkout -b nondeterminism &&
35 test_commit A &&
36 git checkout --orphan with_notes;
39 test_expect_success 'creating many notes with git-notes' '
40 num_notes=300 &&
41 i=0 &&
42 while test $i -lt $num_notes
44 i=$(($i + 1)) &&
45 test_tick &&
46 echo "file for commit #$i" > file &&
47 git add file &&
48 git commit -q -m "commit #$i" &&
49 git notes add -m "note #$i" || return 1
50 done
53 test_expect_success !SANITIZE_LEAK 'many notes created correctly with git-notes' '
54 git log >output.raw &&
55 grep "^ " output.raw >output &&
56 i=$num_notes &&
57 while test $i -gt 0
59 echo " commit #$i" &&
60 echo " note #$i" &&
61 i=$(($i - 1)) || return 1
62 done > expect &&
63 test_cmp expect output
66 test_expect_success 'stable fanout 0 is followed by stable fanout 1' '
67 i=$num_notes &&
68 fanout=0 &&
69 while test $i -gt 0
71 i=$(($i - 1)) &&
72 if touched_one_note_with_fanout refs/notes/commits~$i A $fanout
73 then
74 continue
75 elif test $fanout -eq 0
76 then
77 fanout=1 &&
78 if all_notes_have_fanout refs/notes/commits~$i $fanout
79 then
80 echo "Fanout 0 -> 1 at refs/notes/commits~$i" &&
81 continue
83 fi &&
84 echo "Failed fanout=$fanout check at refs/notes/commits~$i" &&
85 git ls-tree -r --name-only refs/notes/commits~$i &&
86 return 1
87 done &&
88 all_notes_have_fanout refs/notes/commits 1
91 test_expect_success 'deleting most notes with git-notes' '
92 remove_notes=285 &&
93 i=0 &&
94 git rev-list HEAD >revs &&
95 while test $i -lt $remove_notes && read sha1
97 i=$(($i + 1)) &&
98 test_tick &&
99 git notes remove "$sha1" || return 1
100 done <revs
103 test_expect_success 'most notes deleted correctly with git-notes' '
104 git log HEAD~$remove_notes | grep "^ " > output &&
105 i=$(($num_notes - $remove_notes)) &&
106 while test $i -gt 0
108 echo " commit #$i" &&
109 echo " note #$i" &&
110 i=$(($i - 1)) || return 1
111 done > expect &&
112 test_cmp expect output
115 test_expect_success 'stable fanout 1 is followed by stable fanout 0' '
116 i=$remove_notes &&
117 fanout=1 &&
118 while test $i -gt 0
120 i=$(($i - 1)) &&
121 if touched_one_note_with_fanout refs/notes/commits~$i D $fanout
122 then
123 continue
124 elif test $fanout -eq 1
125 then
126 fanout=0 &&
127 if all_notes_have_fanout refs/notes/commits~$i $fanout
128 then
129 echo "Fanout 1 -> 0 at refs/notes/commits~$i" &&
130 continue
132 fi &&
133 echo "Failed fanout=$fanout check at refs/notes/commits~$i" &&
134 git ls-tree -r --name-only refs/notes/commits~$i &&
135 return 1
136 done &&
137 all_notes_have_fanout refs/notes/commits 0
140 test_done