]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3305-notes-fanout.sh
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / t / t3305-notes-fanout.sh
CommitLineData
048cdd46
JH
1#!/bin/sh
2
b0032d1e 3test_description='Test that adding/removing many notes triggers automatic fanout restructuring'
048cdd46 4
7a98d9ab 5TEST_PASSES_SANITIZE_LEAK=true
048cdd46
JH
6. ./test-lib.sh
7
e1c52539
JH
8path_has_fanout() {
9 path=$1 &&
10 fanout=$2 &&
9e3bd8a3 11 after_last_slash=$(($(test_oid hexsz) - $fanout * 2)) &&
a764c37b 12 echo $path | grep -q -E "^([0-9a-f]{2}/){$fanout}[0-9a-f]{$after_last_slash}$"
e1c52539
JH
13}
14
15touched_one_note_with_fanout() {
16 notes_commit=$1 &&
17 modification=$2 && # 'A' for addition, 'D' for deletion
18 fanout=$3 &&
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;
22}
23
24all_notes_have_fanout() {
25 notes_commit=$1 &&
26 fanout=$2 &&
b6d775dd 27 git ls-tree -r --name-only $notes_commit |
e1c52539
JH
28 while read path
29 do
30 path_has_fanout $path $fanout || return 1
31 done
32}
33
dbc27477
JH
34test_expect_success 'tweak test environment' '
35 git checkout -b nondeterminism &&
36 test_commit A &&
37 git checkout --orphan with_notes;
38'
39
048cdd46
JH
40test_expect_success 'creating many notes with git-notes' '
41 num_notes=300 &&
42 i=0 &&
43 while test $i -lt $num_notes
44 do
45 i=$(($i + 1)) &&
46 test_tick &&
47 echo "file for commit #$i" > file &&
48 git add file &&
49 git commit -q -m "commit #$i" &&
aaec9bcf 50 git notes add -m "note #$i" || return 1
048cdd46
JH
51 done
52'
53
96ecf699 54test_expect_success 'many notes created correctly with git-notes' '
b6d775dd
ÆAB
55 git log >output.raw &&
56 grep "^ " output.raw >output &&
e1c52539 57 i=$num_notes &&
048cdd46
JH
58 while test $i -gt 0
59 do
60 echo " commit #$i" &&
61 echo " note #$i" &&
db5875aa 62 i=$(($i - 1)) || return 1
048cdd46
JH
63 done > expect &&
64 test_cmp expect output
65'
66
e1c52539
JH
67test_expect_success 'stable fanout 0 is followed by stable fanout 1' '
68 i=$num_notes &&
69 fanout=0 &&
70 while test $i -gt 0
048cdd46 71 do
e1c52539
JH
72 i=$(($i - 1)) &&
73 if touched_one_note_with_fanout refs/notes/commits~$i A $fanout
74 then
75 continue
76 elif test $fanout -eq 0
77 then
78 fanout=1 &&
79 if all_notes_have_fanout refs/notes/commits~$i $fanout
80 then
81 echo "Fanout 0 -> 1 at refs/notes/commits~$i" &&
82 continue
83 fi
84 fi &&
85 echo "Failed fanout=$fanout check at refs/notes/commits~$i" &&
86 git ls-tree -r --name-only refs/notes/commits~$i &&
87 return 1
88 done &&
89 all_notes_have_fanout refs/notes/commits 1
048cdd46
JH
90'
91
b0032d1e 92test_expect_success 'deleting most notes with git-notes' '
e1c52539 93 remove_notes=285 &&
b0032d1e 94 i=0 &&
b6d775dd 95 git rev-list HEAD >revs &&
e1c52539 96 while test $i -lt $remove_notes && read sha1
b0032d1e
JH
97 do
98 i=$(($i + 1)) &&
b0032d1e 99 test_tick &&
b6d775dd
ÆAB
100 git notes remove "$sha1" || return 1
101 done <revs
b0032d1e
JH
102'
103
104test_expect_success 'most notes deleted correctly with git-notes' '
e1c52539
JH
105 git log HEAD~$remove_notes | grep "^ " > output &&
106 i=$(($num_notes - $remove_notes)) &&
b0032d1e
JH
107 while test $i -gt 0
108 do
109 echo " commit #$i" &&
110 echo " note #$i" &&
db5875aa 111 i=$(($i - 1)) || return 1
b0032d1e
JH
112 done > expect &&
113 test_cmp expect output
114'
115
e1c52539
JH
116test_expect_success 'stable fanout 1 is followed by stable fanout 0' '
117 i=$remove_notes &&
118 fanout=1 &&
119 while test $i -gt 0
b0032d1e 120 do
e1c52539
JH
121 i=$(($i - 1)) &&
122 if touched_one_note_with_fanout refs/notes/commits~$i D $fanout
123 then
124 continue
125 elif test $fanout -eq 1
126 then
127 fanout=0 &&
128 if all_notes_have_fanout refs/notes/commits~$i $fanout
129 then
130 echo "Fanout 1 -> 0 at refs/notes/commits~$i" &&
131 continue
132 fi
133 fi &&
134 echo "Failed fanout=$fanout check at refs/notes/commits~$i" &&
135 git ls-tree -r --name-only refs/notes/commits~$i &&
136 return 1
137 done &&
138 all_notes_have_fanout refs/notes/commits 0
b0032d1e
JH
139'
140
048cdd46 141test_done