Derrick Stolee | 135a712 | 2019-06-18 11:14:28 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='split commit graph' |
Jeff King | da09e7a | 2023-10-03 16:31:30 -0400 | [diff] [blame] | 4 | |
| 5 | TEST_PASSES_SANITIZE_LEAK=true |
Derrick Stolee | 135a712 | 2019-06-18 11:14:28 -0700 | [diff] [blame] | 6 | . ./test-lib.sh |
Jeff King | 6cf61d0 | 2023-10-09 17:05:41 -0400 | [diff] [blame] | 7 | . "$TEST_DIRECTORY"/lib-chunk.sh |
Derrick Stolee | 135a712 | 2019-06-18 11:14:28 -0700 | [diff] [blame] | 8 | |
| 9 | GIT_TEST_COMMIT_GRAPH=0 |
Garima Singh | d5b873c | 2020-04-06 16:59:55 +0000 | [diff] [blame] | 10 | GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0 |
Derrick Stolee | 135a712 | 2019-06-18 11:14:28 -0700 | [diff] [blame] | 11 | |
| 12 | test_expect_success 'setup repo' ' |
| 13 | git init && |
| 14 | git config core.commitGraph true && |
Derrick Stolee | 31b1de6 | 2019-08-13 11:37:45 -0700 | [diff] [blame] | 15 | git config gc.writeCommitGraph false && |
Derrick Stolee | 135a712 | 2019-06-18 11:14:28 -0700 | [diff] [blame] | 16 | infodir=".git/objects/info" && |
| 17 | graphdir="$infodir/commit-graphs" && |
brian m. carlson | 82d5aeb | 2019-12-21 19:49:27 +0000 | [diff] [blame] | 18 | test_oid_cache <<-EOM |
Abhishek Kumar | e8b6300 | 2021-01-16 18:11:15 +0000 | [diff] [blame] | 19 | shallow sha1:2132 |
| 20 | shallow sha256:2436 |
brian m. carlson | 82d5aeb | 2019-12-21 19:49:27 +0000 | [diff] [blame] | 21 | |
Abhishek Kumar | e8b6300 | 2021-01-16 18:11:15 +0000 | [diff] [blame] | 22 | base sha1:1408 |
| 23 | base sha256:1528 |
Derrick Stolee | 665d70a | 2020-08-17 14:04:47 +0000 | [diff] [blame] | 24 | |
| 25 | oid_version sha1:1 |
| 26 | oid_version sha256:2 |
brian m. carlson | 82d5aeb | 2019-12-21 19:49:27 +0000 | [diff] [blame] | 27 | EOM |
Derrick Stolee | 135a712 | 2019-06-18 11:14:28 -0700 | [diff] [blame] | 28 | ' |
| 29 | |
| 30 | graph_read_expect() { |
| 31 | NUM_BASE=0 |
| 32 | if test ! -z $2 |
| 33 | then |
| 34 | NUM_BASE=$2 |
| 35 | fi |
Derrick Stolee | 3b0199d | 2022-03-01 19:48:31 +0000 | [diff] [blame] | 36 | OPTIONS= |
| 37 | if test -z "$3" |
| 38 | then |
| 39 | OPTIONS=" read_generation_data" |
| 40 | fi |
Derrick Stolee | 135a712 | 2019-06-18 11:14:28 -0700 | [diff] [blame] | 41 | cat >expect <<- EOF |
Abhishek Kumar | e8b6300 | 2021-01-16 18:11:15 +0000 | [diff] [blame] | 42 | header: 43475048 1 $(test_oid oid_version) 4 $NUM_BASE |
Derrick Stolee | 135a712 | 2019-06-18 11:14:28 -0700 | [diff] [blame] | 43 | num_commits: $1 |
Abhishek Kumar | e8b6300 | 2021-01-16 18:11:15 +0000 | [diff] [blame] | 44 | chunks: oid_fanout oid_lookup commit_metadata generation_data |
Derrick Stolee | 3b0199d | 2022-03-01 19:48:31 +0000 | [diff] [blame] | 45 | options:$OPTIONS |
Derrick Stolee | 135a712 | 2019-06-18 11:14:28 -0700 | [diff] [blame] | 46 | EOF |
Derrick Stolee | 4bd0593 | 2019-11-12 16:58:20 +0000 | [diff] [blame] | 47 | test-tool read-graph >output && |
Derrick Stolee | 135a712 | 2019-06-18 11:14:28 -0700 | [diff] [blame] | 48 | test_cmp expect output |
| 49 | } |
| 50 | |
Taylor Blau | f4d6284 | 2020-04-29 11:36:42 -0600 | [diff] [blame] | 51 | test_expect_success POSIXPERM 'tweak umask for modebit tests' ' |
| 52 | umask 022 |
| 53 | ' |
| 54 | |
Derrick Stolee | 135a712 | 2019-06-18 11:14:28 -0700 | [diff] [blame] | 55 | test_expect_success 'create commits and write commit-graph' ' |
| 56 | for i in $(test_seq 3) |
| 57 | do |
| 58 | test_commit $i && |
| 59 | git branch commits/$i || return 1 |
| 60 | done && |
| 61 | git commit-graph write --reachable && |
| 62 | test_path_is_file $infodir/commit-graph && |
| 63 | graph_read_expect 3 |
| 64 | ' |
| 65 | |
| 66 | graph_git_two_modes() { |
Ævar Arnfjörð Bjarmason | a046aa3 | 2021-10-15 01:37:15 +0200 | [diff] [blame] | 67 | git ${2:+ -C "$2"} -c core.commitGraph=true $1 >output && |
| 68 | git ${2:+ -C "$2"} -c core.commitGraph=false $1 >expect && |
Derrick Stolee | 135a712 | 2019-06-18 11:14:28 -0700 | [diff] [blame] | 69 | test_cmp expect output |
| 70 | } |
| 71 | |
| 72 | graph_git_behavior() { |
| 73 | MSG=$1 |
| 74 | BRANCH=$2 |
| 75 | COMPARE=$3 |
Ævar Arnfjörð Bjarmason | a046aa3 | 2021-10-15 01:37:15 +0200 | [diff] [blame] | 76 | DIR=$4 |
Derrick Stolee | 135a712 | 2019-06-18 11:14:28 -0700 | [diff] [blame] | 77 | test_expect_success "check normal git operations: $MSG" ' |
Ævar Arnfjörð Bjarmason | a046aa3 | 2021-10-15 01:37:15 +0200 | [diff] [blame] | 78 | graph_git_two_modes "log --oneline $BRANCH" "$DIR" && |
| 79 | graph_git_two_modes "log --topo-order $BRANCH" "$DIR" && |
| 80 | graph_git_two_modes "log --graph $COMPARE..$BRANCH" "$DIR" && |
| 81 | graph_git_two_modes "branch -vv" "$DIR" && |
| 82 | graph_git_two_modes "merge-base -a $BRANCH $COMPARE" "$DIR" |
Derrick Stolee | 135a712 | 2019-06-18 11:14:28 -0700 | [diff] [blame] | 83 | ' |
| 84 | } |
| 85 | |
| 86 | graph_git_behavior 'graph exists' commits/3 commits/1 |
| 87 | |
| 88 | verify_chain_files_exist() { |
| 89 | for hash in $(cat $1/commit-graph-chain) |
| 90 | do |
| 91 | test_path_is_file $1/graph-$hash.graph || return 1 |
| 92 | done |
| 93 | } |
| 94 | |
| 95 | test_expect_success 'add more commits, and write a new base graph' ' |
| 96 | git reset --hard commits/1 && |
| 97 | for i in $(test_seq 4 5) |
| 98 | do |
| 99 | test_commit $i && |
| 100 | git branch commits/$i || return 1 |
| 101 | done && |
| 102 | git reset --hard commits/2 && |
| 103 | for i in $(test_seq 6 10) |
| 104 | do |
| 105 | test_commit $i && |
| 106 | git branch commits/$i || return 1 |
| 107 | done && |
| 108 | git reset --hard commits/2 && |
| 109 | git merge commits/4 && |
| 110 | git branch merge/1 && |
| 111 | git reset --hard commits/4 && |
| 112 | git merge commits/6 && |
| 113 | git branch merge/2 && |
| 114 | git commit-graph write --reachable && |
| 115 | graph_read_expect 12 |
| 116 | ' |
| 117 | |
Derrick Stolee | c523035 | 2019-06-18 11:14:30 -0700 | [diff] [blame] | 118 | test_expect_success 'fork and fail to base a chain on a commit-graph file' ' |
| 119 | test_when_finished rm -rf fork && |
| 120 | git clone . fork && |
| 121 | ( |
| 122 | cd fork && |
| 123 | rm .git/objects/info/commit-graph && |
| 124 | echo "$(pwd)/../.git/objects" >.git/objects/info/alternates && |
| 125 | test_commit new-commit && |
| 126 | git commit-graph write --reachable --split && |
| 127 | test_path_is_file $graphdir/commit-graph-chain && |
| 128 | test_line_count = 1 $graphdir/commit-graph-chain && |
| 129 | verify_chain_files_exist $graphdir |
| 130 | ) |
| 131 | ' |
| 132 | |
Derrick Stolee | 135a712 | 2019-06-18 11:14:28 -0700 | [diff] [blame] | 133 | test_expect_success 'add three more commits, write a tip graph' ' |
| 134 | git reset --hard commits/3 && |
| 135 | git merge merge/1 && |
| 136 | git merge commits/5 && |
| 137 | git merge merge/2 && |
| 138 | git branch merge/3 && |
| 139 | git commit-graph write --reachable --split && |
| 140 | test_path_is_missing $infodir/commit-graph && |
| 141 | test_path_is_file $graphdir/commit-graph-chain && |
| 142 | ls $graphdir/graph-*.graph >graph-files && |
| 143 | test_line_count = 2 graph-files && |
| 144 | verify_chain_files_exist $graphdir |
| 145 | ' |
| 146 | |
| 147 | graph_git_behavior 'split commit-graph: merge 3 vs 2' merge/3 merge/2 |
| 148 | |
| 149 | test_expect_success 'add one commit, write a tip graph' ' |
| 150 | test_commit 11 && |
| 151 | git branch commits/11 && |
| 152 | git commit-graph write --reachable --split && |
| 153 | test_path_is_missing $infodir/commit-graph && |
| 154 | test_path_is_file $graphdir/commit-graph-chain && |
| 155 | ls $graphdir/graph-*.graph >graph-files && |
| 156 | test_line_count = 3 graph-files && |
| 157 | verify_chain_files_exist $graphdir |
| 158 | ' |
| 159 | |
| 160 | graph_git_behavior 'three-layer commit-graph: commit 11 vs 6' commits/11 commits/6 |
| 161 | |
Derrick Stolee | 1771be9 | 2019-06-18 11:14:29 -0700 | [diff] [blame] | 162 | test_expect_success 'add one commit, write a merged graph' ' |
| 163 | test_commit 12 && |
| 164 | git branch commits/12 && |
| 165 | git commit-graph write --reachable --split && |
| 166 | test_path_is_file $graphdir/commit-graph-chain && |
| 167 | test_line_count = 2 $graphdir/commit-graph-chain && |
| 168 | ls $graphdir/graph-*.graph >graph-files && |
Derrick Stolee | 8d84097 | 2019-06-18 11:14:31 -0700 | [diff] [blame] | 169 | test_line_count = 2 graph-files && |
Derrick Stolee | 1771be9 | 2019-06-18 11:14:29 -0700 | [diff] [blame] | 170 | verify_chain_files_exist $graphdir |
| 171 | ' |
| 172 | |
| 173 | graph_git_behavior 'merged commit-graph: commit 12 vs 6' commits/12 commits/6 |
| 174 | |
Derrick Stolee | c523035 | 2019-06-18 11:14:30 -0700 | [diff] [blame] | 175 | test_expect_success 'create fork and chain across alternate' ' |
| 176 | git clone . fork && |
| 177 | ( |
| 178 | cd fork && |
| 179 | git config core.commitGraph true && |
| 180 | rm -rf $graphdir && |
| 181 | echo "$(pwd)/../.git/objects" >.git/objects/info/alternates && |
| 182 | test_commit 13 && |
| 183 | git branch commits/13 && |
| 184 | git commit-graph write --reachable --split && |
| 185 | test_path_is_file $graphdir/commit-graph-chain && |
| 186 | test_line_count = 3 $graphdir/commit-graph-chain && |
| 187 | ls $graphdir/graph-*.graph >graph-files && |
| 188 | test_line_count = 1 graph-files && |
| 189 | git -c core.commitGraph=true rev-list HEAD >expect && |
| 190 | git -c core.commitGraph=false rev-list HEAD >actual && |
Derrick Stolee | 16110c9 | 2019-06-18 11:14:36 -0700 | [diff] [blame] | 191 | test_cmp expect actual && |
| 192 | test_commit 14 && |
| 193 | git commit-graph write --reachable --split --object-dir=.git/objects/ && |
| 194 | test_line_count = 3 $graphdir/commit-graph-chain && |
| 195 | ls $graphdir/graph-*.graph >graph-files && |
| 196 | test_line_count = 1 graph-files |
Derrick Stolee | c523035 | 2019-06-18 11:14:30 -0700 | [diff] [blame] | 197 | ) |
| 198 | ' |
| 199 | |
Ævar Arnfjörð Bjarmason | a046aa3 | 2021-10-15 01:37:15 +0200 | [diff] [blame] | 200 | if test -d fork |
| 201 | then |
| 202 | graph_git_behavior 'alternate: commit 13 vs 6' commits/13 origin/commits/6 "fork" |
| 203 | fi |
Derrick Stolee | c523035 | 2019-06-18 11:14:30 -0700 | [diff] [blame] | 204 | |
Derrick Stolee | c2bc6e6 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 205 | test_expect_success 'test merge stragety constants' ' |
| 206 | git clone . merge-2 && |
| 207 | ( |
| 208 | cd merge-2 && |
| 209 | git config core.commitGraph true && |
| 210 | test_line_count = 2 $graphdir/commit-graph-chain && |
| 211 | test_commit 14 && |
| 212 | git commit-graph write --reachable --split --size-multiple=2 && |
| 213 | test_line_count = 3 $graphdir/commit-graph-chain |
| 214 | |
| 215 | ) && |
| 216 | git clone . merge-10 && |
| 217 | ( |
| 218 | cd merge-10 && |
| 219 | git config core.commitGraph true && |
| 220 | test_line_count = 2 $graphdir/commit-graph-chain && |
| 221 | test_commit 14 && |
| 222 | git commit-graph write --reachable --split --size-multiple=10 && |
| 223 | test_line_count = 1 $graphdir/commit-graph-chain && |
| 224 | ls $graphdir/graph-*.graph >graph-files && |
| 225 | test_line_count = 1 graph-files |
| 226 | ) && |
| 227 | git clone . merge-10-expire && |
| 228 | ( |
| 229 | cd merge-10-expire && |
| 230 | git config core.commitGraph true && |
| 231 | test_line_count = 2 $graphdir/commit-graph-chain && |
| 232 | test_commit 15 && |
Derrick Stolee | b09b785 | 2020-04-01 21:00:44 +0000 | [diff] [blame] | 233 | touch $graphdir/to-delete.graph $graphdir/to-keep.graph && |
| 234 | test-tool chmtime =1546362000 $graphdir/to-delete.graph && |
| 235 | test-tool chmtime =1546362001 $graphdir/to-keep.graph && |
| 236 | git commit-graph write --reachable --split --size-multiple=10 \ |
| 237 | --expire-time="2019-01-01 12:00 -05:00" && |
Derrick Stolee | c2bc6e6 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 238 | test_line_count = 1 $graphdir/commit-graph-chain && |
Derrick Stolee | b09b785 | 2020-04-01 21:00:44 +0000 | [diff] [blame] | 239 | test_path_is_missing $graphdir/to-delete.graph && |
| 240 | test_path_is_file $graphdir/to-keep.graph && |
Derrick Stolee | c2bc6e6 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 241 | ls $graphdir/graph-*.graph >graph-files && |
| 242 | test_line_count = 3 graph-files |
| 243 | ) && |
| 244 | git clone --no-hardlinks . max-commits && |
| 245 | ( |
| 246 | cd max-commits && |
| 247 | git config core.commitGraph true && |
| 248 | test_line_count = 2 $graphdir/commit-graph-chain && |
| 249 | test_commit 16 && |
| 250 | test_commit 17 && |
| 251 | git commit-graph write --reachable --split --max-commits=1 && |
| 252 | test_line_count = 1 $graphdir/commit-graph-chain && |
| 253 | ls $graphdir/graph-*.graph >graph-files && |
| 254 | test_line_count = 1 graph-files |
| 255 | ) |
| 256 | ' |
| 257 | |
Derrick Stolee | ba41112 | 2019-06-18 11:14:33 -0700 | [diff] [blame] | 258 | test_expect_success 'remove commit-graph-chain file after flattening' ' |
| 259 | git clone . flatten && |
| 260 | ( |
| 261 | cd flatten && |
| 262 | test_line_count = 2 $graphdir/commit-graph-chain && |
| 263 | git commit-graph write --reachable && |
| 264 | test_path_is_missing $graphdir/commit-graph-chain && |
| 265 | ls $graphdir >graph-files && |
| 266 | test_line_count = 0 graph-files |
| 267 | ) |
| 268 | ' |
| 269 | |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 270 | corrupt_file() { |
| 271 | file=$1 |
| 272 | pos=$2 |
| 273 | data="${3:-\0}" |
Derrick Stolee | 5b15eb3 | 2019-06-18 11:14:36 -0700 | [diff] [blame] | 274 | chmod a+w "$file" && |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 275 | printf "$data" | dd of="$file" bs=1 seek="$pos" conv=notrunc |
| 276 | } |
| 277 | |
| 278 | test_expect_success 'verify hashes along chain, even in shallow' ' |
| 279 | git clone --no-hardlinks . verify && |
| 280 | ( |
| 281 | cd verify && |
| 282 | git commit-graph verify && |
| 283 | base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph && |
brian m. carlson | 82d5aeb | 2019-12-21 19:49:27 +0000 | [diff] [blame] | 284 | corrupt_file "$base_file" $(test_oid shallow) "\01" && |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 285 | test_must_fail git commit-graph verify --shallow 2>test_err && |
| 286 | grep -v "^+" test_err >err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 287 | test_grep "incorrect checksum" err |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 288 | ) |
| 289 | ' |
| 290 | |
Jeff King | 5f25919 | 2023-09-28 00:39:51 -0400 | [diff] [blame] | 291 | test_expect_success 'verify notices chain slice which is bogus (base)' ' |
| 292 | git clone --no-hardlinks . verify-chain-bogus-base && |
| 293 | ( |
| 294 | cd verify-chain-bogus-base && |
| 295 | git commit-graph verify && |
| 296 | base_file=$graphdir/graph-$(sed -n 1p $graphdir/commit-graph-chain).graph && |
| 297 | echo "garbage" >$base_file && |
| 298 | test_must_fail git commit-graph verify 2>test_err && |
| 299 | grep -v "^+" test_err >err && |
| 300 | grep "commit-graph file is too small" err |
| 301 | ) |
| 302 | ' |
| 303 | |
| 304 | test_expect_success 'verify notices chain slice which is bogus (tip)' ' |
| 305 | git clone --no-hardlinks . verify-chain-bogus-tip && |
| 306 | ( |
| 307 | cd verify-chain-bogus-tip && |
| 308 | git commit-graph verify && |
| 309 | tip_file=$graphdir/graph-$(sed -n 2p $graphdir/commit-graph-chain).graph && |
| 310 | echo "garbage" >$tip_file && |
| 311 | test_must_fail git commit-graph verify 2>test_err && |
| 312 | grep -v "^+" test_err >err && |
| 313 | grep "commit-graph file is too small" err |
| 314 | ) |
| 315 | ' |
| 316 | |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 317 | test_expect_success 'verify --shallow does not check base contents' ' |
| 318 | git clone --no-hardlinks . verify-shallow && |
| 319 | ( |
| 320 | cd verify-shallow && |
| 321 | git commit-graph verify && |
| 322 | base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph && |
Jeff King | 4169d89 | 2023-10-09 17:04:58 -0400 | [diff] [blame] | 323 | corrupt_file "$base_file" 1500 "\01" && |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 324 | git commit-graph verify --shallow && |
| 325 | test_must_fail git commit-graph verify 2>test_err && |
| 326 | grep -v "^+" test_err >err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 327 | test_grep "incorrect checksum" err |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 328 | ) |
| 329 | ' |
| 330 | |
| 331 | test_expect_success 'warn on base graph chunk incorrect' ' |
| 332 | git clone --no-hardlinks . base-chunk && |
| 333 | ( |
| 334 | cd base-chunk && |
| 335 | git commit-graph verify && |
| 336 | base_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph && |
brian m. carlson | 82d5aeb | 2019-12-21 19:49:27 +0000 | [diff] [blame] | 337 | corrupt_file "$base_file" $(test_oid base) "\01" && |
Jeff King | 5f25919 | 2023-09-28 00:39:51 -0400 | [diff] [blame] | 338 | test_must_fail git commit-graph verify --shallow 2>test_err && |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 339 | grep -v "^+" test_err >err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 340 | test_grep "commit-graph chain does not match" err |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 341 | ) |
| 342 | ' |
| 343 | |
Jeff King | 2d45710 | 2023-09-28 00:38:47 -0400 | [diff] [blame] | 344 | test_expect_success 'verify after commit-graph-chain corruption (base)' ' |
| 345 | git clone --no-hardlinks . verify-chain-base && |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 346 | ( |
Jeff King | 2d45710 | 2023-09-28 00:38:47 -0400 | [diff] [blame] | 347 | cd verify-chain-base && |
| 348 | corrupt_file "$graphdir/commit-graph-chain" 30 "G" && |
Jeff King | 47d06bb | 2023-09-28 00:38:59 -0400 | [diff] [blame] | 349 | test_must_fail git commit-graph verify 2>test_err && |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 350 | grep -v "^+" test_err >err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 351 | test_grep "invalid commit-graph chain" err && |
Jeff King | 2d45710 | 2023-09-28 00:38:47 -0400 | [diff] [blame] | 352 | corrupt_file "$graphdir/commit-graph-chain" 30 "A" && |
Jeff King | 47d06bb | 2023-09-28 00:38:59 -0400 | [diff] [blame] | 353 | test_must_fail git commit-graph verify 2>test_err && |
Jeff King | 2d45710 | 2023-09-28 00:38:47 -0400 | [diff] [blame] | 354 | grep -v "^+" test_err >err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 355 | test_grep "unable to find all commit-graph files" err |
Jeff King | 2d45710 | 2023-09-28 00:38:47 -0400 | [diff] [blame] | 356 | ) |
| 357 | ' |
| 358 | |
| 359 | test_expect_success 'verify after commit-graph-chain corruption (tip)' ' |
| 360 | git clone --no-hardlinks . verify-chain-tip && |
| 361 | ( |
| 362 | cd verify-chain-tip && |
| 363 | corrupt_file "$graphdir/commit-graph-chain" 70 "G" && |
Jeff King | 5f25919 | 2023-09-28 00:39:51 -0400 | [diff] [blame] | 364 | test_must_fail git commit-graph verify 2>test_err && |
Jeff King | 2d45710 | 2023-09-28 00:38:47 -0400 | [diff] [blame] | 365 | grep -v "^+" test_err >err && |
Junio C Hamano | a8e2394 | 2023-11-08 11:04:02 +0900 | [diff] [blame] | 366 | test_grep "invalid commit-graph chain" err && |
Jeff King | 2d45710 | 2023-09-28 00:38:47 -0400 | [diff] [blame] | 367 | corrupt_file "$graphdir/commit-graph-chain" 70 "A" && |
Jeff King | 5f25919 | 2023-09-28 00:39:51 -0400 | [diff] [blame] | 368 | test_must_fail git commit-graph verify 2>test_err && |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 369 | grep -v "^+" test_err >err && |
Junio C Hamano | a8e2394 | 2023-11-08 11:04:02 +0900 | [diff] [blame] | 370 | test_grep "unable to find all commit-graph files" err |
Derrick Stolee | 3da4b60 | 2019-06-18 11:14:32 -0700 | [diff] [blame] | 371 | ) |
| 372 | ' |
| 373 | |
Jeff King | 7754a56 | 2023-09-28 00:39:10 -0400 | [diff] [blame] | 374 | test_expect_success 'verify notices too-short chain file' ' |
| 375 | git clone --no-hardlinks . verify-chain-short && |
| 376 | ( |
| 377 | cd verify-chain-short && |
| 378 | git commit-graph verify && |
| 379 | echo "garbage" >$graphdir/commit-graph-chain && |
| 380 | test_must_fail git commit-graph verify 2>test_err && |
| 381 | grep -v "^+" test_err >err && |
| 382 | grep "commit-graph chain file too small" err |
| 383 | ) |
| 384 | ' |
| 385 | |
Derrick Stolee | 5b15eb3 | 2019-06-18 11:14:36 -0700 | [diff] [blame] | 386 | test_expect_success 'verify across alternates' ' |
| 387 | git clone --no-hardlinks . verify-alt && |
| 388 | ( |
| 389 | cd verify-alt && |
| 390 | rm -rf $graphdir && |
| 391 | altdir="$(pwd)/../.git/objects" && |
| 392 | echo "$altdir" >.git/objects/info/alternates && |
| 393 | git commit-graph verify --object-dir="$altdir/" && |
| 394 | test_commit extra && |
| 395 | git commit-graph write --reachable --split && |
| 396 | tip_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph && |
Jeff King | 4169d89 | 2023-10-09 17:04:58 -0400 | [diff] [blame] | 397 | corrupt_file "$tip_file" 1500 "\01" && |
Derrick Stolee | 5b15eb3 | 2019-06-18 11:14:36 -0700 | [diff] [blame] | 398 | test_must_fail git commit-graph verify --shallow 2>test_err && |
| 399 | grep -v "^+" test_err >err && |
Junio C Hamano | a8e2394 | 2023-11-08 11:04:02 +0900 | [diff] [blame] | 400 | test_grep "incorrect checksum" err |
Derrick Stolee | 5b15eb3 | 2019-06-18 11:14:36 -0700 | [diff] [blame] | 401 | ) |
| 402 | ' |
| 403 | |
Jeff King | 6cf61d0 | 2023-10-09 17:05:41 -0400 | [diff] [blame] | 404 | test_expect_success 'reader bounds-checks base-graph chunk' ' |
| 405 | git clone --no-hardlinks . corrupt-base-chunk && |
| 406 | ( |
| 407 | cd corrupt-base-chunk && |
| 408 | tip_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph && |
| 409 | corrupt_chunk_file "$tip_file" BASE clear 01020304 && |
| 410 | git -c core.commitGraph=false log >expect.out && |
| 411 | git -c core.commitGraph=true log >out 2>err && |
| 412 | test_cmp expect.out out && |
| 413 | grep "commit-graph base graphs chunk is too small" err |
Derrick Stolee | a09c130 | 2019-06-18 11:14:35 -0700 | [diff] [blame] | 414 | ) |
| 415 | ' |
| 416 | |
| 417 | test_expect_success 'add octopus merge' ' |
| 418 | git reset --hard commits/10 && |
| 419 | git merge commits/3 commits/4 && |
| 420 | git branch merge/octopus && |
| 421 | git commit-graph write --reachable --split && |
Garima Singh | 7371612 | 2019-08-26 09:29:58 -0700 | [diff] [blame] | 422 | git commit-graph verify --progress 2>err && |
Taylor Blau | 9281cd0 | 2023-07-07 20:31:45 -0400 | [diff] [blame] | 423 | test_line_count = 1 err && |
| 424 | grep "Verifying commits in commit graph: 100% (18/18)" err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 425 | test_grep ! warning err && |
Derrick Stolee | e2017c4 | 2019-06-18 11:14:34 -0700 | [diff] [blame] | 426 | test_line_count = 3 $graphdir/commit-graph-chain |
| 427 | ' |
| 428 | |
| 429 | graph_git_behavior 'graph exists' merge/octopus commits/12 |
| 430 | |
Derrick Stolee | a09c130 | 2019-06-18 11:14:35 -0700 | [diff] [blame] | 431 | test_expect_success 'split across alternate where alternate is not split' ' |
| 432 | git commit-graph write --reachable && |
| 433 | test_path_is_file .git/objects/info/commit-graph && |
| 434 | cp .git/objects/info/commit-graph . && |
| 435 | git clone --no-hardlinks . alt-split && |
| 436 | ( |
| 437 | cd alt-split && |
Derrick Stolee | 31b1de6 | 2019-08-13 11:37:45 -0700 | [diff] [blame] | 438 | rm -f .git/objects/info/commit-graph && |
Derrick Stolee | a09c130 | 2019-06-18 11:14:35 -0700 | [diff] [blame] | 439 | echo "$(pwd)"/../.git/objects >.git/objects/info/alternates && |
| 440 | test_commit 18 && |
| 441 | git commit-graph write --reachable --split && |
| 442 | test_line_count = 1 $graphdir/commit-graph-chain |
| 443 | ) && |
| 444 | test_cmp commit-graph .git/objects/info/commit-graph |
| 445 | ' |
| 446 | |
Taylor Blau | fdbde82 | 2020-04-13 22:04:12 -0600 | [diff] [blame] | 447 | test_expect_success '--split=no-merge always writes an incremental' ' |
| 448 | test_when_finished rm -rf a b && |
| 449 | rm -rf $graphdir $infodir/commit-graph && |
| 450 | git reset --hard commits/2 && |
| 451 | git rev-list HEAD~1 >a && |
| 452 | git rev-list HEAD >b && |
| 453 | git commit-graph write --split --stdin-commits <a && |
| 454 | git commit-graph write --split=no-merge --stdin-commits <b && |
| 455 | test_line_count = 2 $graphdir/commit-graph-chain |
| 456 | ' |
| 457 | |
Taylor Blau | 8a6ac28 | 2020-04-13 22:04:17 -0600 | [diff] [blame] | 458 | test_expect_success '--split=replace replaces the chain' ' |
| 459 | rm -rf $graphdir $infodir/commit-graph && |
| 460 | git reset --hard commits/3 && |
| 461 | git rev-list -1 HEAD~2 >a && |
| 462 | git rev-list -1 HEAD~1 >b && |
| 463 | git rev-list -1 HEAD >c && |
| 464 | git commit-graph write --split=no-merge --stdin-commits <a && |
| 465 | git commit-graph write --split=no-merge --stdin-commits <b && |
| 466 | git commit-graph write --split=no-merge --stdin-commits <c && |
| 467 | test_line_count = 3 $graphdir/commit-graph-chain && |
| 468 | git commit-graph write --stdin-commits --split=replace <b && |
| 469 | test_path_is_missing $infodir/commit-graph && |
| 470 | test_path_is_file $graphdir/commit-graph-chain && |
| 471 | ls $graphdir/graph-*.graph >graph-files && |
| 472 | test_line_count = 1 graph-files && |
| 473 | verify_chain_files_exist $graphdir && |
| 474 | graph_read_expect 2 |
| 475 | ' |
| 476 | |
Taylor Blau | b78a556 | 2020-04-23 15:41:09 -0600 | [diff] [blame] | 477 | test_expect_success ULIMIT_FILE_DESCRIPTORS 'handles file descriptor exhaustion' ' |
| 478 | git init ulimit && |
| 479 | ( |
| 480 | cd ulimit && |
| 481 | for i in $(test_seq 64) |
| 482 | do |
| 483 | test_commit $i && |
Denton Liu | 6861ac8 | 2020-07-07 02:04:35 -0400 | [diff] [blame] | 484 | run_with_limited_open_files test_might_fail git commit-graph write \ |
Taylor Blau | b78a556 | 2020-04-23 15:41:09 -0600 | [diff] [blame] | 485 | --split=no-merge --reachable || return 1 |
| 486 | done |
| 487 | ) |
| 488 | ' |
| 489 | |
Taylor Blau | f4d6284 | 2020-04-29 11:36:42 -0600 | [diff] [blame] | 490 | while read mode modebits |
| 491 | do |
| 492 | test_expect_success POSIXPERM "split commit-graph respects core.sharedrepository $mode" ' |
| 493 | rm -rf $graphdir $infodir/commit-graph && |
| 494 | git reset --hard commits/1 && |
| 495 | test_config core.sharedrepository "$mode" && |
| 496 | git commit-graph write --split --reachable && |
| 497 | ls $graphdir/graph-*.graph >graph-files && |
| 498 | test_line_count = 1 graph-files && |
| 499 | echo "$modebits" >expect && |
| 500 | test_modebits $graphdir/graph-*.graph >actual && |
Taylor Blau | 45a4365 | 2020-04-29 11:36:46 -0600 | [diff] [blame] | 501 | test_cmp expect actual && |
| 502 | test_modebits $graphdir/commit-graph-chain >actual && |
Taylor Blau | f4d6284 | 2020-04-29 11:36:42 -0600 | [diff] [blame] | 503 | test_cmp expect actual |
| 504 | ' |
| 505 | done <<\EOF |
| 506 | 0666 -r--r--r-- |
| 507 | 0600 -r-------- |
| 508 | EOF |
| 509 | |
Taylor Blau | 4f36440 | 2020-09-09 11:22:44 -0400 | [diff] [blame] | 510 | test_expect_success '--split=replace with partial Bloom data' ' |
| 511 | rm -rf $graphdir $infodir/commit-graph && |
| 512 | git reset --hard commits/3 && |
| 513 | git rev-list -1 HEAD~2 >a && |
| 514 | git rev-list -1 HEAD~1 >b && |
| 515 | git commit-graph write --split=no-merge --stdin-commits --changed-paths <a && |
| 516 | git commit-graph write --split=no-merge --stdin-commits <b && |
| 517 | git commit-graph write --split=replace --stdin-commits --changed-paths <c && |
| 518 | ls $graphdir/graph-*.graph >graph-files && |
| 519 | test_line_count = 1 graph-files && |
| 520 | verify_chain_files_exist $graphdir |
| 521 | ' |
| 522 | |
Derrick Stolee | 150f115 | 2020-10-09 20:53:51 +0000 | [diff] [blame] | 523 | test_expect_success 'prevent regression for duplicate commits across layers' ' |
| 524 | git init dup && |
Derrick Stolee | 150f115 | 2020-10-09 20:53:51 +0000 | [diff] [blame] | 525 | git -C dup commit --allow-empty -m one && |
Derrick Stolee | 85102ac | 2020-10-09 20:53:52 +0000 | [diff] [blame] | 526 | git -C dup -c core.commitGraph=false commit-graph write --split=no-merge --reachable 2>err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 527 | test_grep "attempting to write a commit-graph" err && |
Derrick Stolee | 150f115 | 2020-10-09 20:53:51 +0000 | [diff] [blame] | 528 | git -C dup commit-graph write --split=no-merge --reachable && |
| 529 | git -C dup commit --allow-empty -m two && |
| 530 | git -C dup commit-graph write --split=no-merge --reachable && |
| 531 | git -C dup commit --allow-empty -m three && |
| 532 | git -C dup commit-graph write --split --reachable && |
| 533 | git -C dup commit-graph verify |
| 534 | ' |
| 535 | |
Abhishek Kumar | 1fdc383 | 2021-01-16 18:11:16 +0000 | [diff] [blame] | 536 | NUM_FIRST_LAYER_COMMITS=64 |
| 537 | NUM_SECOND_LAYER_COMMITS=16 |
| 538 | NUM_THIRD_LAYER_COMMITS=7 |
| 539 | NUM_FOURTH_LAYER_COMMITS=8 |
| 540 | NUM_FIFTH_LAYER_COMMITS=16 |
| 541 | SECOND_LAYER_SEQUENCE_START=$(($NUM_FIRST_LAYER_COMMITS + 1)) |
| 542 | SECOND_LAYER_SEQUENCE_END=$(($SECOND_LAYER_SEQUENCE_START + $NUM_SECOND_LAYER_COMMITS - 1)) |
| 543 | THIRD_LAYER_SEQUENCE_START=$(($SECOND_LAYER_SEQUENCE_END + 1)) |
| 544 | THIRD_LAYER_SEQUENCE_END=$(($THIRD_LAYER_SEQUENCE_START + $NUM_THIRD_LAYER_COMMITS - 1)) |
| 545 | FOURTH_LAYER_SEQUENCE_START=$(($THIRD_LAYER_SEQUENCE_END + 1)) |
| 546 | FOURTH_LAYER_SEQUENCE_END=$(($FOURTH_LAYER_SEQUENCE_START + $NUM_FOURTH_LAYER_COMMITS - 1)) |
| 547 | FIFTH_LAYER_SEQUENCE_START=$(($FOURTH_LAYER_SEQUENCE_END + 1)) |
| 548 | FIFTH_LAYER_SEQUENCE_END=$(($FIFTH_LAYER_SEQUENCE_START + $NUM_FIFTH_LAYER_COMMITS - 1)) |
| 549 | |
| 550 | # Current split graph chain: |
| 551 | # |
| 552 | # 16 commits (No GDAT) |
| 553 | # ------------------------ |
| 554 | # 64 commits (GDAT) |
| 555 | # |
| 556 | test_expect_success 'setup repo for mixed generation commit-graph-chain' ' |
| 557 | graphdir=".git/objects/info/commit-graphs" && |
| 558 | test_oid_cache <<-EOF && |
| 559 | oid_version sha1:1 |
| 560 | oid_version sha256:2 |
| 561 | EOF |
| 562 | git init mixed && |
| 563 | ( |
| 564 | cd mixed && |
| 565 | git config core.commitGraph true && |
| 566 | git config gc.writeCommitGraph false && |
| 567 | for i in $(test_seq $NUM_FIRST_LAYER_COMMITS) |
| 568 | do |
| 569 | test_commit $i && |
| 570 | git branch commits/$i || return 1 |
| 571 | done && |
Derrick Stolee | 702110a | 2021-02-25 18:19:43 +0000 | [diff] [blame] | 572 | git -c commitGraph.generationVersion=2 commit-graph write --reachable --split && |
Abhishek Kumar | 1fdc383 | 2021-01-16 18:11:16 +0000 | [diff] [blame] | 573 | graph_read_expect $NUM_FIRST_LAYER_COMMITS && |
| 574 | test_line_count = 1 $graphdir/commit-graph-chain && |
| 575 | for i in $(test_seq $SECOND_LAYER_SEQUENCE_START $SECOND_LAYER_SEQUENCE_END) |
| 576 | do |
| 577 | test_commit $i && |
| 578 | git branch commits/$i || return 1 |
| 579 | done && |
Derrick Stolee | 702110a | 2021-02-25 18:19:43 +0000 | [diff] [blame] | 580 | git -c commitGraph.generationVersion=1 commit-graph write --reachable --split=no-merge && |
Abhishek Kumar | 1fdc383 | 2021-01-16 18:11:16 +0000 | [diff] [blame] | 581 | test_line_count = 2 $graphdir/commit-graph-chain && |
| 582 | test-tool read-graph >output && |
| 583 | cat >expect <<-EOF && |
| 584 | header: 43475048 1 $(test_oid oid_version) 4 1 |
| 585 | num_commits: $NUM_SECOND_LAYER_COMMITS |
| 586 | chunks: oid_fanout oid_lookup commit_metadata |
Derrick Stolee | c78c7a9 | 2022-03-01 19:48:28 +0000 | [diff] [blame] | 587 | options: |
Abhishek Kumar | 1fdc383 | 2021-01-16 18:11:16 +0000 | [diff] [blame] | 588 | EOF |
| 589 | test_cmp expect output && |
| 590 | git commit-graph verify && |
| 591 | cat $graphdir/commit-graph-chain |
| 592 | ) |
| 593 | ' |
| 594 | |
| 595 | # The new layer will be added without generation data chunk as it was not |
| 596 | # present on the layer underneath it. |
| 597 | # |
| 598 | # 7 commits (No GDAT) |
| 599 | # ------------------------ |
| 600 | # 16 commits (No GDAT) |
| 601 | # ------------------------ |
| 602 | # 64 commits (GDAT) |
| 603 | # |
| 604 | test_expect_success 'do not write generation data chunk if not present on existing tip' ' |
| 605 | git clone mixed mixed-no-gdat && |
| 606 | ( |
| 607 | cd mixed-no-gdat && |
| 608 | for i in $(test_seq $THIRD_LAYER_SEQUENCE_START $THIRD_LAYER_SEQUENCE_END) |
| 609 | do |
| 610 | test_commit $i && |
| 611 | git branch commits/$i || return 1 |
| 612 | done && |
| 613 | git commit-graph write --reachable --split=no-merge && |
| 614 | test_line_count = 3 $graphdir/commit-graph-chain && |
| 615 | test-tool read-graph >output && |
| 616 | cat >expect <<-EOF && |
| 617 | header: 43475048 1 $(test_oid oid_version) 4 2 |
| 618 | num_commits: $NUM_THIRD_LAYER_COMMITS |
| 619 | chunks: oid_fanout oid_lookup commit_metadata |
Derrick Stolee | c78c7a9 | 2022-03-01 19:48:28 +0000 | [diff] [blame] | 620 | options: |
Abhishek Kumar | 1fdc383 | 2021-01-16 18:11:16 +0000 | [diff] [blame] | 621 | EOF |
| 622 | test_cmp expect output && |
| 623 | git commit-graph verify |
| 624 | ) |
| 625 | ' |
| 626 | |
| 627 | # Number of commits in each layer of the split-commit graph before merge: |
| 628 | # |
| 629 | # 8 commits (No GDAT) |
| 630 | # ------------------------ |
| 631 | # 7 commits (No GDAT) |
| 632 | # ------------------------ |
| 633 | # 16 commits (No GDAT) |
| 634 | # ------------------------ |
| 635 | # 64 commits (GDAT) |
| 636 | # |
| 637 | # The top two layers are merged and do not have generation data chunk as layer below them does |
| 638 | # not have generation data chunk. |
| 639 | # |
| 640 | # 15 commits (No GDAT) |
| 641 | # ------------------------ |
| 642 | # 16 commits (No GDAT) |
| 643 | # ------------------------ |
| 644 | # 64 commits (GDAT) |
| 645 | # |
| 646 | test_expect_success 'do not write generation data chunk if the topmost remaining layer does not have generation data chunk' ' |
| 647 | git clone mixed-no-gdat mixed-merge-no-gdat && |
| 648 | ( |
| 649 | cd mixed-merge-no-gdat && |
| 650 | for i in $(test_seq $FOURTH_LAYER_SEQUENCE_START $FOURTH_LAYER_SEQUENCE_END) |
| 651 | do |
| 652 | test_commit $i && |
| 653 | git branch commits/$i || return 1 |
| 654 | done && |
| 655 | git commit-graph write --reachable --split --size-multiple 1 && |
| 656 | test_line_count = 3 $graphdir/commit-graph-chain && |
| 657 | test-tool read-graph >output && |
| 658 | cat >expect <<-EOF && |
| 659 | header: 43475048 1 $(test_oid oid_version) 4 2 |
| 660 | num_commits: $(($NUM_THIRD_LAYER_COMMITS + $NUM_FOURTH_LAYER_COMMITS)) |
| 661 | chunks: oid_fanout oid_lookup commit_metadata |
Derrick Stolee | c78c7a9 | 2022-03-01 19:48:28 +0000 | [diff] [blame] | 662 | options: |
Abhishek Kumar | 1fdc383 | 2021-01-16 18:11:16 +0000 | [diff] [blame] | 663 | EOF |
| 664 | test_cmp expect output && |
| 665 | git commit-graph verify |
| 666 | ) |
| 667 | ' |
| 668 | |
| 669 | # Number of commits in each layer of the split-commit graph before merge: |
| 670 | # |
| 671 | # 16 commits (No GDAT) |
| 672 | # ------------------------ |
| 673 | # 15 commits (No GDAT) |
| 674 | # ------------------------ |
| 675 | # 16 commits (No GDAT) |
| 676 | # ------------------------ |
| 677 | # 64 commits (GDAT) |
| 678 | # |
| 679 | # The top three layers are merged and has generation data chunk as the topmost remaining layer |
| 680 | # has generation data chunk. |
| 681 | # |
| 682 | # 47 commits (GDAT) |
| 683 | # ------------------------ |
| 684 | # 64 commits (GDAT) |
| 685 | # |
| 686 | test_expect_success 'write generation data chunk if topmost remaining layer has generation data chunk' ' |
| 687 | git clone mixed-merge-no-gdat mixed-merge-gdat && |
| 688 | ( |
| 689 | cd mixed-merge-gdat && |
| 690 | for i in $(test_seq $FIFTH_LAYER_SEQUENCE_START $FIFTH_LAYER_SEQUENCE_END) |
| 691 | do |
| 692 | test_commit $i && |
| 693 | git branch commits/$i || return 1 |
| 694 | done && |
| 695 | git commit-graph write --reachable --split --size-multiple 1 && |
| 696 | test_line_count = 2 $graphdir/commit-graph-chain && |
| 697 | test-tool read-graph >output && |
| 698 | cat >expect <<-EOF && |
| 699 | header: 43475048 1 $(test_oid oid_version) 5 1 |
| 700 | num_commits: $(($NUM_SECOND_LAYER_COMMITS + $NUM_THIRD_LAYER_COMMITS + $NUM_FOURTH_LAYER_COMMITS + $NUM_FIFTH_LAYER_COMMITS)) |
| 701 | chunks: oid_fanout oid_lookup commit_metadata generation_data |
Derrick Stolee | 3b0199d | 2022-03-01 19:48:31 +0000 | [diff] [blame] | 702 | options: read_generation_data |
Abhishek Kumar | 1fdc383 | 2021-01-16 18:11:16 +0000 | [diff] [blame] | 703 | EOF |
| 704 | test_cmp expect output |
| 705 | ) |
| 706 | ' |
| 707 | |
| 708 | test_expect_success 'write generation data chunk when commit-graph chain is replaced' ' |
| 709 | git clone mixed mixed-replace && |
| 710 | ( |
| 711 | cd mixed-replace && |
| 712 | git commit-graph write --reachable --split=replace && |
| 713 | test_path_is_file $graphdir/commit-graph-chain && |
| 714 | test_line_count = 1 $graphdir/commit-graph-chain && |
| 715 | verify_chain_files_exist $graphdir && |
| 716 | graph_read_expect $(($NUM_FIRST_LAYER_COMMITS + $NUM_SECOND_LAYER_COMMITS)) && |
| 717 | git commit-graph verify |
| 718 | ) |
| 719 | ' |
| 720 | |
Derrick Stolee | 135a712 | 2019-06-18 11:14:28 -0700 | [diff] [blame] | 721 | test_done |