read-cache: delete unused hashing methods
[git] / t / t3303-notes-subtrees.sh
1 #!/bin/sh
2
3 test_description='Test commit notes organized in subtrees'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 number_of_commits=100
11
12 start_note_commit () {
13         test_tick &&
14         cat <<INPUT_END
15 commit refs/notes/commits
16 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
17 data <<COMMIT
18 notes
19 COMMIT
20
21 from refs/notes/commits^0
22 deleteall
23 INPUT_END
24
25 }
26
27 verify_notes () {
28         git log | grep "^    " > output &&
29         i=$number_of_commits &&
30         while [ $i -gt 0 ]; do
31                 echo "    commit #$i" &&
32                 echo "    note for commit #$i" &&
33                 i=$(($i-1));
34         done > expect &&
35         test_cmp expect output
36 }
37
38 test_expect_success "setup: create $number_of_commits commits" '
39
40         (
41                 nr=0 &&
42                 while [ $nr -lt $number_of_commits ]; do
43                         nr=$(($nr+1)) &&
44                         test_tick &&
45                         cat <<INPUT_END
46 commit refs/heads/main
47 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
48 data <<COMMIT
49 commit #$nr
50 COMMIT
51
52 M 644 inline file
53 data <<EOF
54 file in commit #$nr
55 EOF
56
57 INPUT_END
58
59                 done &&
60                 test_tick &&
61                 cat <<INPUT_END
62 commit refs/notes/commits
63 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
64 data <<COMMIT
65 no notes
66 COMMIT
67
68 deleteall
69
70 INPUT_END
71
72         ) |
73         git fast-import --quiet &&
74         git config core.notesRef refs/notes/commits
75 '
76
77 test_sha1_based () {
78         (
79                 start_note_commit &&
80                 nr=$number_of_commits &&
81                 git rev-list refs/heads/main |
82                 while read sha1; do
83                         note_path=$(echo "$sha1" | sed "$1")
84                         cat <<INPUT_END &&
85 M 100644 inline $note_path
86 data <<EOF
87 note for commit #$nr
88 EOF
89
90 INPUT_END
91
92                         nr=$(($nr-1))
93                 done
94         ) |
95         git fast-import --quiet
96 }
97
98 test_expect_success 'test notes in 2/38-fanout' 'test_sha1_based "s|^..|&/|"'
99 test_expect_success 'verify notes in 2/38-fanout' 'verify_notes'
100
101 test_expect_success 'test notes in 2/2/36-fanout' 'test_sha1_based "s|^\(..\)\(..\)|\1/\2/|"'
102 test_expect_success 'verify notes in 2/2/36-fanout' 'verify_notes'
103
104 test_expect_success 'test notes in 2/2/2/34-fanout' 'test_sha1_based "s|^\(..\)\(..\)\(..\)|\1/\2/\3/|"'
105 test_expect_success 'verify notes in 2/2/2/34-fanout' 'verify_notes'
106
107 test_same_notes () {
108         (
109                 start_note_commit &&
110                 nr=$number_of_commits &&
111                 git rev-list refs/heads/main |
112                 while read sha1; do
113                         first_note_path=$(echo "$sha1" | sed "$1")
114                         second_note_path=$(echo "$sha1" | sed "$2")
115                         cat <<INPUT_END &&
116 M 100644 inline $second_note_path
117 data <<EOF
118 note for commit #$nr
119 EOF
120
121 M 100644 inline $first_note_path
122 data <<EOF
123 note for commit #$nr
124 EOF
125
126 INPUT_END
127
128                         nr=$(($nr-1))
129                 done
130         ) |
131         git fast-import --quiet
132 }
133
134 test_expect_success 'test same notes in no fanout and 2/38-fanout' 'test_same_notes "s|^..|&/|" ""'
135 test_expect_success 'verify same notes in no fanout and 2/38-fanout' 'verify_notes'
136
137 test_expect_success 'test same notes in no fanout and 2/2/36-fanout' 'test_same_notes "s|^\(..\)\(..\)|\1/\2/|" ""'
138 test_expect_success 'verify same notes in no fanout and 2/2/36-fanout' 'verify_notes'
139
140 test_expect_success 'test same notes in 2/38-fanout and 2/2/36-fanout' 'test_same_notes "s|^\(..\)\(..\)|\1/\2/|" "s|^..|&/|"'
141 test_expect_success 'verify same notes in 2/38-fanout and 2/2/36-fanout' 'verify_notes'
142
143 test_expect_success 'test same notes in 2/2/2/34-fanout and 2/2/36-fanout' 'test_same_notes "s|^\(..\)\(..\)|\1/\2/|" "s|^\(..\)\(..\)\(..\)|\1/\2/\3/|"'
144 test_expect_success 'verify same notes in 2/2/2/34-fanout and 2/2/36-fanout' 'verify_notes'
145
146 test_concatenated_notes () {
147         (
148                 start_note_commit &&
149                 nr=$number_of_commits &&
150                 git rev-list refs/heads/main |
151                 while read sha1; do
152                         first_note_path=$(echo "$sha1" | sed "$1")
153                         second_note_path=$(echo "$sha1" | sed "$2")
154                         cat <<INPUT_END &&
155 M 100644 inline $second_note_path
156 data <<EOF
157 second note for commit #$nr
158 EOF
159
160 M 100644 inline $first_note_path
161 data <<EOF
162 first note for commit #$nr
163 EOF
164
165 INPUT_END
166
167                         nr=$(($nr-1))
168                 done
169         ) |
170         git fast-import --quiet
171 }
172
173 verify_concatenated_notes () {
174         git log | grep "^    " > output &&
175         i=$number_of_commits &&
176         while [ $i -gt 0 ]; do
177                 echo "    commit #$i" &&
178                 echo "    first note for commit #$i" &&
179                 echo "    " &&
180                 echo "    second note for commit #$i" &&
181                 i=$(($i-1));
182         done > expect &&
183         test_cmp expect output
184 }
185
186 test_expect_success 'test notes in no fanout concatenated with 2/38-fanout' 'test_concatenated_notes "s|^..|&/|" ""'
187 test_expect_success 'verify notes in no fanout concatenated with 2/38-fanout' 'verify_concatenated_notes'
188
189 test_expect_success 'test notes in no fanout concatenated with 2/2/36-fanout' 'test_concatenated_notes "s|^\(..\)\(..\)|\1/\2/|" ""'
190 test_expect_success 'verify notes in no fanout concatenated with 2/2/36-fanout' 'verify_concatenated_notes'
191
192 test_expect_success 'test notes in 2/38-fanout concatenated with 2/2/36-fanout' 'test_concatenated_notes "s|^\(..\)\(..\)|\1/\2/|" "s|^..|&/|"'
193 test_expect_success 'verify notes in 2/38-fanout concatenated with 2/2/36-fanout' 'verify_concatenated_notes'
194
195 test_expect_success 'test notes in 2/2/36-fanout concatenated with 2/2/2/34-fanout' 'test_concatenated_notes "s|^\(..\)\(..\)\(..\)|\1/\2/\3/|" "s|^\(..\)\(..\)|\1/\2/|"'
196 test_expect_success 'verify notes in 2/2/36-fanout concatenated with 2/2/2/34-fanout' 'verify_concatenated_notes'
197
198 test_done