utopia-ia/elffuss-braid public
Changesets · Branches · Tags · Compare
| Changeset | bd46a4a90e4efcfa7458f347f223be69de794fe4e0268773a4c21a7f75a16fea |
|---|---|
| Author | KikoCis <KikoCis@users.noreply.github.com> · 2026-10-15 21:52 +02:00 |
| Committer | KikoCis <KikoCis@users.noreply.github.com> · 2026-10-15 21:52 +02:00 |
| Parents | 35958d895e81, 7700d2921bbf |
22 files changed
modified .github/workflows/ci.yml +5 −1
| @@ -22,6 +22,10 @@ | ||
| 22 | 22 | runs-on: ${{ matrix.os }} |
| 23 | 23 | steps: |
| 24 | 24 | - uses: actions/checkout@v5 |
| 25 | + with: | |
| 26 | + # The git bridge round-trips this repository's own history, which a | |
| 27 | + # shallow checkout does not have. | |
| 28 | + fetch-depth: 0 | |
| 25 | 29 | - uses: dtolnay/rust-toolchain@stable |
| 26 | 30 | with: |
| 27 | 31 | components: rustfmt, clippy |
| @@ -87,6 +91,6 @@ | ||
| 87 | 91 | - name: run every target for one minute |
| 88 | 92 | working-directory: fuzz |
| 89 | 93 | run: | |
| 90 | - for target in decode_tree decode_changeset names; do | |
| 94 | + for target in decode_tree decode_changeset names git_map git_objects; do | |
| 91 | 95 | cargo fuzz run "$target" -- -max_total_time=60 |
| 92 | 96 | done |
modified Cargo.lock +1133 −7
| @@ -2,6 +2,12 @@ | ||
| 2 | 2 | # It is not intended for manual editing. |
| 3 | 3 | version = 4 |
| 4 | 4 | |
| 5 | +[[package]] | |
| 6 | +name = "allocator-api2" | |
| 7 | +version = "0.2.21" | |
| 8 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 9 | +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" | |
| 10 | + | |
| 5 | 11 | [[package]] |
| 6 | 12 | name = "anstream" |
| 7 | 13 | version = "1.0.0" |
| @@ -58,6 +64,15 @@ | ||
| 58 | 64 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 59 | 65 | checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" |
| 60 | 66 | |
| 67 | +[[package]] | |
| 68 | +name = "arc-swap" | |
| 69 | +version = "1.9.2" | |
| 70 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 71 | +checksum = "c049c0be4daef0b145cb3555416b3b8ef5b7888a38aea1a3a155801fe7b0810b" | |
| 72 | +dependencies = [ | |
| 73 | + "rustversion", | |
| 74 | +] | |
| 75 | + | |
| 61 | 76 | [[package]] |
| 62 | 77 | name = "arrayvec" |
| 63 | 78 | version = "0.7.8" |
| @@ -89,6 +104,12 @@ | ||
| 89 | 104 | "serde", |
| 90 | 105 | ] |
| 91 | 106 | |
| 107 | +[[package]] | |
| 108 | +name = "bitflags" | |
| 109 | +version = "1.3.2" | |
| 110 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 111 | +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" | |
| 112 | + | |
| 92 | 113 | [[package]] |
| 93 | 114 | name = "bitflags" |
| 94 | 115 | version = "2.13.2" |
| @@ -108,6 +129,15 @@ | ||
| 108 | 129 | "cpufeatures", |
| 109 | 130 | ] |
| 110 | 131 | |
| 132 | +[[package]] | |
| 133 | +name = "block-buffer" | |
| 134 | +version = "0.12.1" | |
| 135 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 136 | +checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa" | |
| 137 | +dependencies = [ | |
| 138 | + "hybrid-array", | |
| 139 | +] | |
| 140 | + | |
| 111 | 141 | [[package]] |
| 112 | 142 | name = "borsh" |
| 113 | 143 | version = "1.8.1" |
| @@ -129,9 +159,26 @@ | ||
| 129 | 159 | "proc-macro-crate", |
| 130 | 160 | "proc-macro2", |
| 131 | 161 | "quote", |
| 132 | - "syn", | |
| 162 | + "syn 3.0.9", | |
| 163 | +] | |
| 164 | + | |
| 165 | +[[package]] | |
| 166 | +name = "bstr" | |
| 167 | +version = "1.13.1" | |
| 168 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 169 | +checksum = "6bb31b46c14244e20ee9984b11bf5c992b91fb6939fea616e3512c8baecdbe5f" | |
| 170 | +dependencies = [ | |
| 171 | + "memchr", | |
| 172 | + "regex-automata", | |
| 173 | + "serde_core", | |
| 133 | 174 | ] |
| 134 | 175 | |
| 176 | +[[package]] | |
| 177 | +name = "byteorder" | |
| 178 | +version = "1.5.0" | |
| 179 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 180 | +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" | |
| 181 | + | |
| 135 | 182 | [[package]] |
| 136 | 183 | name = "bytes" |
| 137 | 184 | version = "1.12.1" |
| @@ -204,7 +251,7 @@ | ||
| 204 | 251 | "heck", |
| 205 | 252 | "proc-macro2", |
| 206 | 253 | "quote", |
| 207 | - "syn", | |
| 254 | + "syn 3.0.9", | |
| 208 | 255 | ] |
| 209 | 256 | |
| 210 | 257 | [[package]] |
| @@ -213,6 +260,15 @@ | ||
| 213 | 260 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 214 | 261 | checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486" |
| 215 | 262 | |
| 263 | +[[package]] | |
| 264 | +name = "clru" | |
| 265 | +version = "0.6.3" | |
| 266 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 267 | +checksum = "197fd99cb113a8d5d9b6376f3aa817f32c1078f2343b714fff7d2ca44fdf67d5" | |
| 268 | +dependencies = [ | |
| 269 | + "hashbrown 0.16.1", | |
| 270 | +] | |
| 271 | + | |
| 216 | 272 | [[package]] |
| 217 | 273 | name = "colorchoice" |
| 218 | 274 | version = "1.0.5" |
| @@ -249,6 +305,95 @@ | ||
| 249 | 305 | "rustc_version", |
| 250 | 306 | ] |
| 251 | 307 | |
| 308 | +[[package]] | |
| 309 | +name = "crc32fast" | |
| 310 | +version = "1.5.2" | |
| 311 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 312 | +checksum = "01a7799fd6b852db0e61728dde9a204c423b44d689dbd432522543614b490e78" | |
| 313 | +dependencies = [ | |
| 314 | + "cfg-if", | |
| 315 | +] | |
| 316 | + | |
| 317 | +[[package]] | |
| 318 | +name = "crossbeam-channel" | |
| 319 | +version = "0.5.17" | |
| 320 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 321 | +checksum = "98b0cc327b5bc766e7fda9c9260cc0fa81b43a8e240440422dff70788e3f9ef1" | |
| 322 | +dependencies = [ | |
| 323 | + "crossbeam-utils", | |
| 324 | +] | |
| 325 | + | |
| 326 | +[[package]] | |
| 327 | +name = "crossbeam-utils" | |
| 328 | +version = "0.8.23" | |
| 329 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 330 | +checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6" | |
| 331 | + | |
| 332 | +[[package]] | |
| 333 | +name = "crypto-common" | |
| 334 | +version = "0.2.2" | |
| 335 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 336 | +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" | |
| 337 | +dependencies = [ | |
| 338 | + "hybrid-array", | |
| 339 | +] | |
| 340 | + | |
| 341 | +[[package]] | |
| 342 | +name = "defmt" | |
| 343 | +version = "0.3.101" | |
| 344 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 345 | +checksum = "4deef977660e373c458df605a913d4ab121db0ccd18d1ad6976dff7d37cddb53" | |
| 346 | +dependencies = [ | |
| 347 | + "defmt 1.2.0", | |
| 348 | +] | |
| 349 | + | |
| 350 | +[[package]] | |
| 351 | +name = "defmt" | |
| 352 | +version = "1.2.0" | |
| 353 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 354 | +checksum = "e4a0795ac740cb54d7b3775c9c17345f6aaecf884c01733b39d6017738e0e3e1" | |
| 355 | +dependencies = [ | |
| 356 | + "bitflags 1.3.2", | |
| 357 | + "defmt-macros", | |
| 358 | +] | |
| 359 | + | |
| 360 | +[[package]] | |
| 361 | +name = "defmt-macros" | |
| 362 | +version = "1.2.0" | |
| 363 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 364 | +checksum = "840bb056bd99c495c9188198a258ab787c79f306d864db3e6e8451442d6d8366" | |
| 365 | +dependencies = [ | |
| 366 | + "defmt-parser", | |
| 367 | + "proc-macro2", | |
| 368 | + "quote", | |
| 369 | + "syn 3.0.9", | |
| 370 | +] | |
| 371 | + | |
| 372 | +[[package]] | |
| 373 | +name = "defmt-parser" | |
| 374 | +version = "1.1.0" | |
| 375 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 376 | +checksum = "71958f69fb2de856c5dd51ac9377e986ca1aa5919f931bf5395a807277f889a0" | |
| 377 | +dependencies = [ | |
| 378 | + "thiserror", | |
| 379 | +] | |
| 380 | + | |
| 381 | +[[package]] | |
| 382 | +name = "digest" | |
| 383 | +version = "0.11.3" | |
| 384 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 385 | +checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" | |
| 386 | +dependencies = [ | |
| 387 | + "block-buffer", | |
| 388 | + "crypto-common", | |
| 389 | +] | |
| 390 | + | |
| 391 | +[[package]] | |
| 392 | +name = "dunce" | |
| 393 | +version = "1.0.5" | |
| 394 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 395 | +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" | |
| 396 | + | |
| 252 | 397 | [[package]] |
| 253 | 398 | name = "elffuss-braid-cli" |
| 254 | 399 | version = "0.0.1" |
| @@ -271,6 +416,15 @@ | ||
| 271 | 416 | "unicode-normalization", |
| 272 | 417 | ] |
| 273 | 418 | |
| 419 | +[[package]] | |
| 420 | +name = "elffuss-braid-git" | |
| 421 | +version = "0.0.1" | |
| 422 | +dependencies = [ | |
| 423 | + "elffuss-braid-format", | |
| 424 | + "gix", | |
| 425 | + "tempfile", | |
| 426 | +] | |
| 427 | + | |
| 274 | 428 | [[package]] |
| 275 | 429 | name = "elffuss-braid-repo" |
| 276 | 430 | version = "0.0.1" |
| @@ -295,6 +449,20 @@ | ||
| 295 | 449 | "zstd", |
| 296 | 450 | ] |
| 297 | 451 | |
| 452 | +[[package]] | |
| 453 | +name = "encoding_rs" | |
| 454 | +version = "0.8.42" | |
| 455 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 456 | +checksum = "8e985e0451871ad22fb8d2b6b076e2028a502a0d3950998c2c5c0a4f9b5d9679" | |
| 457 | +dependencies = [ | |
| 458 | + "cfg-if", | |
| 459 | + "core_detect", | |
| 460 | + "multiversion_no_op", | |
| 461 | + "rustversion", | |
| 462 | + "scopeguard", | |
| 463 | + "simdutf8", | |
| 464 | +] | |
| 465 | + | |
| 298 | 466 | [[package]] |
| 299 | 467 | name = "equivalent" |
| 300 | 468 | version = "1.0.3" |
| @@ -311,6 +479,18 @@ | ||
| 311 | 479 | "windows-sys", |
| 312 | 480 | ] |
| 313 | 481 | |
| 482 | +[[package]] | |
| 483 | +name = "faster-hex" | |
| 484 | +version = "0.10.1" | |
| 485 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 486 | +checksum = "04839bdf9d8c10f66806fad16b852fc72aab80873aebc3cb69d85b4fa41543ed" | |
| 487 | +dependencies = [ | |
| 488 | + "autocfg", | |
| 489 | + "defmt 0.3.101", | |
| 490 | + "heapless", | |
| 491 | + "serde", | |
| 492 | +] | |
| 493 | + | |
| 314 | 494 | [[package]] |
| 315 | 495 | name = "fastrand" |
| 316 | 496 | version = "2.5.0" |
| @@ -329,6 +509,12 @@ | ||
| 329 | 509 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 330 | 510 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" |
| 331 | 511 | |
| 512 | +[[package]] | |
| 513 | +name = "foldhash" | |
| 514 | +version = "0.2.0" | |
| 515 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 516 | +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" | |
| 517 | + | |
| 332 | 518 | [[package]] |
| 333 | 519 | name = "getrandom" |
| 334 | 520 | version = "0.4.3" |
| @@ -341,18 +527,696 @@ | ||
| 341 | 527 | "rand_core", |
| 342 | 528 | ] |
| 343 | 529 | |
| 530 | +[[package]] | |
| 531 | +name = "gix" | |
| 532 | +version = "0.89.0" | |
| 533 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 534 | +checksum = "2156d2e07fc3afa7632a82bf3cb0db91f995645a2852f642105c9ac9b52e1cb2" | |
| 535 | +dependencies = [ | |
| 536 | + "gix-actor", | |
| 537 | + "gix-commitgraph", | |
| 538 | + "gix-config", | |
| 539 | + "gix-date", | |
| 540 | + "gix-diff", | |
| 541 | + "gix-discover", | |
| 542 | + "gix-error", | |
| 543 | + "gix-fs", | |
| 544 | + "gix-glob", | |
| 545 | + "gix-hash", | |
| 546 | + "gix-hashtable", | |
| 547 | + "gix-lock", | |
| 548 | + "gix-note", | |
| 549 | + "gix-object", | |
| 550 | + "gix-odb", | |
| 551 | + "gix-pack", | |
| 552 | + "gix-parallel", | |
| 553 | + "gix-path", | |
| 554 | + "gix-protocol", | |
| 555 | + "gix-quote", | |
| 556 | + "gix-ref", | |
| 557 | + "gix-refspec", | |
| 558 | + "gix-revision", | |
| 559 | + "gix-revwalk", | |
| 560 | + "gix-sec", | |
| 561 | + "gix-shallow", | |
| 562 | + "gix-tempfile", | |
| 563 | + "gix-trace", | |
| 564 | + "gix-traverse", | |
| 565 | + "gix-url", | |
| 566 | + "gix-utils", | |
| 567 | + "gix-validate", | |
| 568 | + "gix-worktree-stream", | |
| 569 | + "gix-zlib", | |
| 570 | + "nonempty", | |
| 571 | + "smallvec", | |
| 572 | +] | |
| 573 | + | |
| 574 | +[[package]] | |
| 575 | +name = "gix-actor" | |
| 576 | +version = "0.44.0" | |
| 577 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 578 | +checksum = "2127da41042965ed205568a52443465806944f71c8acd73f48ec94b8cd8e798e" | |
| 579 | +dependencies = [ | |
| 580 | + "bstr", | |
| 581 | + "gix-date", | |
| 582 | + "gix-error", | |
| 583 | +] | |
| 584 | + | |
| 585 | +[[package]] | |
| 586 | +name = "gix-attributes" | |
| 587 | +version = "0.37.0" | |
| 588 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 589 | +checksum = "0feca0b8919aba9f123b75de54062dd61eb37d2a2130f34be520da6ed8b8ef72" | |
| 590 | +dependencies = [ | |
| 591 | + "bstr", | |
| 592 | + "gix-error", | |
| 593 | + "gix-glob", | |
| 594 | + "gix-parallel", | |
| 595 | + "gix-path", | |
| 596 | + "gix-quote", | |
| 597 | + "gix-trace", | |
| 598 | + "smallvec", | |
| 599 | + "unicode-bom", | |
| 600 | +] | |
| 601 | + | |
| 602 | +[[package]] | |
| 603 | +name = "gix-chunk" | |
| 604 | +version = "0.10.0" | |
| 605 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 606 | +checksum = "626335faf30ed235744642c2309aa370683b8bb2757f1c22a807e274dff60074" | |
| 607 | +dependencies = [ | |
| 608 | + "gix-error", | |
| 609 | +] | |
| 610 | + | |
| 611 | +[[package]] | |
| 612 | +name = "gix-command" | |
| 613 | +version = "0.12.0" | |
| 614 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 615 | +checksum = "ac560c05e19455016a4a94b33a77debe59aaed8783da32a73d31c9975947152e" | |
| 616 | +dependencies = [ | |
| 617 | + "bstr", | |
| 618 | + "gix-error", | |
| 619 | + "gix-path", | |
| 620 | + "gix-quote", | |
| 621 | + "gix-trace", | |
| 622 | +] | |
| 623 | + | |
| 624 | +[[package]] | |
| 625 | +name = "gix-commitgraph" | |
| 626 | +version = "0.41.0" | |
| 627 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 628 | +checksum = "dfede9936d4b789867c09722576aea4ceb0e3aacf962eef035ebab0686b41a80" | |
| 629 | +dependencies = [ | |
| 630 | + "bstr", | |
| 631 | + "gix-chunk", | |
| 632 | + "gix-error", | |
| 633 | + "gix-hash", | |
| 634 | + "memmap2", | |
| 635 | + "nonempty", | |
| 636 | +] | |
| 637 | + | |
| 638 | +[[package]] | |
| 639 | +name = "gix-config" | |
| 640 | +version = "0.62.0" | |
| 641 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 642 | +checksum = "65a9c000fa9a9154f22ffc8f8d74426e9300d759c2029e8701e2ba39d5d464ea" | |
| 643 | +dependencies = [ | |
| 644 | + "bstr", | |
| 645 | + "gix-config-value", | |
| 646 | + "gix-error", | |
| 647 | + "gix-glob", | |
| 648 | + "gix-parallel", | |
| 649 | + "gix-path", | |
| 650 | + "gix-ref", | |
| 651 | + "gix-sec", | |
| 652 | + "gix-trace", | |
| 653 | + "gix-utils", | |
| 654 | + "smallvec", | |
| 655 | + "unicode-bom", | |
| 656 | +] | |
| 657 | + | |
| 658 | +[[package]] | |
| 659 | +name = "gix-config-value" | |
| 660 | +version = "0.21.0" | |
| 661 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 662 | +checksum = "ab206c2fccfd35e0de7fb1b424997cfd42912062c66dae024e08a06e22d46674" | |
| 663 | +dependencies = [ | |
| 664 | + "bitflags 2.13.2", | |
| 665 | + "bstr", | |
| 666 | + "gix-error", | |
| 667 | + "gix-path", | |
| 668 | + "gix-utils", | |
| 669 | + "libc", | |
| 670 | +] | |
| 671 | + | |
| 672 | +[[package]] | |
| 673 | +name = "gix-date" | |
| 674 | +version = "0.18.0" | |
| 675 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 676 | +checksum = "0f7eeeecc599082f32b5ea6a8c4c734e38be9730e2c09e3fe2851bb4692393e9" | |
| 677 | +dependencies = [ | |
| 678 | + "bstr", | |
| 679 | + "gix-error", | |
| 680 | + "itoa", | |
| 681 | + "jiff", | |
| 682 | +] | |
| 683 | + | |
| 684 | +[[package]] | |
| 685 | +name = "gix-diff" | |
| 686 | +version = "0.69.0" | |
| 687 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 688 | +checksum = "aa640963fdcbc6b4718e48593c3917f5ae764b59fb5a96313cb5a757246d041d" | |
| 689 | +dependencies = [ | |
| 690 | + "bstr", | |
| 691 | + "gix-error", | |
| 692 | + "gix-hash", | |
| 693 | + "gix-object", | |
| 694 | +] | |
| 695 | + | |
| 696 | +[[package]] | |
| 697 | +name = "gix-discover" | |
| 698 | +version = "0.57.0" | |
| 699 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 700 | +checksum = "a7d0f8fd2c7e4b458eb3081362d49b54bd0131d23ecd49be802085a11f0d3cee" | |
| 701 | +dependencies = [ | |
| 702 | + "bstr", | |
| 703 | + "dunce", | |
| 704 | + "gix-error", | |
| 705 | + "gix-fs", | |
| 706 | + "gix-path", | |
| 707 | + "gix-ref", | |
| 708 | + "gix-sec", | |
| 709 | +] | |
| 710 | + | |
| 711 | +[[package]] | |
| 712 | +name = "gix-error" | |
| 713 | +version = "0.5.1" | |
| 714 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 715 | +checksum = "bb3308a948a01b94ef13d9ee7a9b28c1303d8d9a9dc33b401ff40c2184d9e04a" | |
| 716 | +dependencies = [ | |
| 717 | + "bstr", | |
| 718 | +] | |
| 719 | + | |
| 720 | +[[package]] | |
| 721 | +name = "gix-filter" | |
| 722 | +version = "0.36.0" | |
| 723 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 724 | +checksum = "9d8d932ee4043f7d77d15ee58d2be2bc95accea5dd1d77fd145de1b7c504551b" | |
| 725 | +dependencies = [ | |
| 726 | + "bstr", | |
| 727 | + "encoding_rs", | |
| 728 | + "gix-attributes", | |
| 729 | + "gix-command", | |
| 730 | + "gix-error", | |
| 731 | + "gix-hash", | |
| 732 | + "gix-object", | |
| 733 | + "gix-packetline", | |
| 734 | + "gix-path", | |
| 735 | + "gix-quote", | |
| 736 | + "gix-trace", | |
| 737 | + "gix-utils", | |
| 738 | + "smallvec", | |
| 739 | +] | |
| 740 | + | |
| 741 | +[[package]] | |
| 742 | +name = "gix-fs" | |
| 743 | +version = "0.24.0" | |
| 744 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 745 | +checksum = "44a05d043e670c055cd8b53d078562dc0bc1e322bff6b0376b407d37cf72dcc5" | |
| 746 | +dependencies = [ | |
| 747 | + "bstr", | |
| 748 | + "gix-error", | |
| 749 | + "gix-parallel", | |
| 750 | + "gix-path", | |
| 751 | + "gix-utils", | |
| 752 | + "libc", | |
| 753 | + "walkdir", | |
| 754 | +] | |
| 755 | + | |
| 756 | +[[package]] | |
| 757 | +name = "gix-glob" | |
| 758 | +version = "0.29.0" | |
| 759 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 760 | +checksum = "7b0d03ab50fa841621031960679caf7fe94940968d9a0736d12a580f2c03e525" | |
| 761 | +dependencies = [ | |
| 762 | + "bitflags 2.13.2", | |
| 763 | + "bstr", | |
| 764 | + "gix-fs", | |
| 765 | + "gix-path", | |
| 766 | + "gix-trace", | |
| 767 | + "gix-utils", | |
| 768 | +] | |
| 769 | + | |
| 770 | +[[package]] | |
| 771 | +name = "gix-hash" | |
| 772 | +version = "0.28.0" | |
| 773 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 774 | +checksum = "40ca156064e378d8c657084365846cedb8dc498c6ea4500965a64d74f12af2be" | |
| 775 | +dependencies = [ | |
| 776 | + "faster-hex", | |
| 777 | + "gix-error", | |
| 778 | + "gix-utils", | |
| 779 | + "sha1dc", | |
| 780 | + "sha2", | |
| 781 | +] | |
| 782 | + | |
| 783 | +[[package]] | |
| 784 | +name = "gix-hashtable" | |
| 785 | +version = "0.18.0" | |
| 786 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 787 | +checksum = "916cb6b2ec42ffaca624e7867bb382a4673015cb4ffcd7330b48085d02e4c615" | |
| 788 | +dependencies = [ | |
| 789 | + "gix-hash", | |
| 790 | + "hashbrown 0.17.1", | |
| 791 | + "parking_lot", | |
| 792 | +] | |
| 793 | + | |
| 794 | +[[package]] | |
| 795 | +name = "gix-lock" | |
| 796 | +version = "26.0.0" | |
| 797 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 798 | +checksum = "4b2f7f5bd6b9fcd0b0dc58b0e6a708f3a47c3313876571dfe800c926c069aa5c" | |
| 799 | +dependencies = [ | |
| 800 | + "gix-error", | |
| 801 | + "gix-fs", | |
| 802 | + "gix-tempfile", | |
| 803 | + "gix-utils", | |
| 804 | +] | |
| 805 | + | |
| 806 | +[[package]] | |
| 807 | +name = "gix-macros" | |
| 808 | +version = "0.2.0" | |
| 809 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 810 | +checksum = "f11f5429ca73cc3758c9f53af56a9fba100a8701c5b4bc30e29b8b0b15288991" | |
| 811 | +dependencies = [ | |
| 812 | + "proc-macro2", | |
| 813 | + "quote", | |
| 814 | + "syn 2.0.119", | |
| 815 | +] | |
| 816 | + | |
| 817 | +[[package]] | |
| 818 | +name = "gix-note" | |
| 819 | +version = "0.3.0" | |
| 820 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 821 | +checksum = "bd364f8bdceaed9e7f3ae40f324b16e39f20e9c7e6a6a058f7c6ec66c3e6205c" | |
| 822 | +dependencies = [ | |
| 823 | + "gix-error", | |
| 824 | + "gix-hash", | |
| 825 | + "gix-object", | |
| 826 | +] | |
| 827 | + | |
| 828 | +[[package]] | |
| 829 | +name = "gix-object" | |
| 830 | +version = "0.66.0" | |
| 831 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 832 | +checksum = "f0e38f50177e211642af154f9a7f710b7a3a637e635f9b6adb9d51973b0f9209" | |
| 833 | +dependencies = [ | |
| 834 | + "bstr", | |
| 835 | + "gix-actor", | |
| 836 | + "gix-date", | |
| 837 | + "gix-error", | |
| 838 | + "gix-hash", | |
| 839 | + "gix-hashtable", | |
| 840 | + "gix-utils", | |
| 841 | + "gix-validate", | |
| 842 | + "itoa", | |
| 843 | + "smallvec", | |
| 844 | +] | |
| 845 | + | |
| 846 | +[[package]] | |
| 847 | +name = "gix-odb" | |
| 848 | +version = "0.86.0" | |
| 849 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 850 | +checksum = "ca444f33f2140876ed6b5313c2b550b4af699008193c96f3bff5023afa9ef4ea" | |
| 851 | +dependencies = [ | |
| 852 | + "arc-swap", | |
| 853 | + "crc32fast", | |
| 854 | + "gix-error", | |
| 855 | + "gix-fs", | |
| 856 | + "gix-hash", | |
| 857 | + "gix-hashtable", | |
| 858 | + "gix-object", | |
| 859 | + "gix-pack", | |
| 860 | + "gix-parallel", | |
| 861 | + "gix-path", | |
| 862 | + "gix-quote", | |
| 863 | + "gix-trace", | |
| 864 | + "gix-utils", | |
| 865 | + "gix-zlib", | |
| 866 | + "memmap2", | |
| 867 | + "parking_lot", | |
| 868 | + "tempfile", | |
| 869 | +] | |
| 870 | + | |
| 871 | +[[package]] | |
| 872 | +name = "gix-pack" | |
| 873 | +version = "0.76.0" | |
| 874 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 875 | +checksum = "bc5024cc503cd29461a705ae90b9eae772fa8f0e6fafc1c48513877dc374de05" | |
| 876 | +dependencies = [ | |
| 877 | + "clru", | |
| 878 | + "crc32fast", | |
| 879 | + "gix-chunk", | |
| 880 | + "gix-error", | |
| 881 | + "gix-hash", | |
| 882 | + "gix-hashtable", | |
| 883 | + "gix-object", | |
| 884 | + "gix-parallel", | |
| 885 | + "gix-path", | |
| 886 | + "gix-trace", | |
| 887 | + "gix-utils", | |
| 888 | + "gix-zlib", | |
| 889 | + "memmap2", | |
| 890 | + "smallvec", | |
| 891 | +] | |
| 892 | + | |
| 893 | +[[package]] | |
| 894 | +name = "gix-packetline" | |
| 895 | +version = "0.24.0" | |
| 896 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 897 | +checksum = "830e51b227f6a925fe9308858ac91170dd00fa2880f5480fc81e8a4594fe2c35" | |
| 898 | +dependencies = [ | |
| 899 | + "bstr", | |
| 900 | + "faster-hex", | |
| 901 | + "gix-error", | |
| 902 | + "gix-trace", | |
| 903 | +] | |
| 904 | + | |
| 905 | +[[package]] | |
| 906 | +name = "gix-parallel" | |
| 907 | +version = "0.50.0" | |
| 908 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 909 | +checksum = "e994cf1eec247ba4be7f9e7c0d58cc73f83eecb5fcb9feb595df5ba3d2078546" | |
| 910 | +dependencies = [ | |
| 911 | + "crossbeam-channel", | |
| 912 | + "gix-trace", | |
| 913 | + "once_cell", | |
| 914 | + "parking_lot", | |
| 915 | +] | |
| 916 | + | |
| 917 | +[[package]] | |
| 918 | +name = "gix-path" | |
| 919 | +version = "0.14.0" | |
| 920 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 921 | +checksum = "a6d563d4d0c975ed0df4e853f9ec962a2ba46633b1d324e1a5582541fcae0c6b" | |
| 922 | +dependencies = [ | |
| 923 | + "bstr", | |
| 924 | + "gix-error", | |
| 925 | + "gix-trace", | |
| 926 | + "gix-validate", | |
| 927 | +] | |
| 928 | + | |
| 929 | +[[package]] | |
| 930 | +name = "gix-protocol" | |
| 931 | +version = "0.67.0" | |
| 932 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 933 | +checksum = "832b5dc46a3c0a6f6fa8f8e571c11074add4b545c6789799ae6d6c36ae1a294e" | |
| 934 | +dependencies = [ | |
| 935 | + "bstr", | |
| 936 | + "gix-date", | |
| 937 | + "gix-error", | |
| 938 | + "gix-hash", | |
| 939 | + "gix-macros", | |
| 940 | + "gix-ref", | |
| 941 | + "gix-shallow", | |
| 942 | + "gix-transport", | |
| 943 | + "gix-utils", | |
| 944 | + "nonempty", | |
| 945 | +] | |
| 946 | + | |
| 947 | +[[package]] | |
| 948 | +name = "gix-quote" | |
| 949 | +version = "0.10.0" | |
| 950 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 951 | +checksum = "c7f92bc1b13c09e88388578e8aa1e987ec35f28fca158c13b1baa7ab1a85b124" | |
| 952 | +dependencies = [ | |
| 953 | + "bstr", | |
| 954 | + "gix-error", | |
| 955 | + "gix-utils", | |
| 956 | +] | |
| 957 | + | |
| 958 | +[[package]] | |
| 959 | +name = "gix-ref" | |
| 960 | +version = "0.69.0" | |
| 961 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 962 | +checksum = "073bc0928e1f747823b1eaed94918119dacef4c616532bc3d17e5b7457863471" | |
| 963 | +dependencies = [ | |
| 964 | + "gix-actor", | |
| 965 | + "gix-error", | |
| 966 | + "gix-fs", | |
| 967 | + "gix-hash", | |
| 968 | + "gix-lock", | |
| 969 | + "gix-object", | |
| 970 | + "gix-parallel", | |
| 971 | + "gix-path", | |
| 972 | + "gix-tempfile", | |
| 973 | + "gix-utils", | |
| 974 | + "gix-validate", | |
| 975 | + "memmap2", | |
| 976 | +] | |
| 977 | + | |
| 978 | +[[package]] | |
| 979 | +name = "gix-refspec" | |
| 980 | +version = "0.47.0" | |
| 981 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 982 | +checksum = "ccc7010dae0df2900aa77cc67f8aca042cd80e35938ccc179010d863b1d42a0c" | |
| 983 | +dependencies = [ | |
| 984 | + "bstr", | |
| 985 | + "gix-error", | |
| 986 | + "gix-hash", | |
| 987 | + "gix-validate", | |
| 988 | + "smallvec", | |
| 989 | +] | |
| 990 | + | |
| 991 | +[[package]] | |
| 992 | +name = "gix-revision" | |
| 993 | +version = "0.51.0" | |
| 994 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 995 | +checksum = "63210c1943b67fa700806c3c3486fc16a92b3ea871f5cf092340b8eec10a0ca1" | |
| 996 | +dependencies = [ | |
| 997 | + "bstr", | |
| 998 | + "gix-commitgraph", | |
| 999 | + "gix-date", | |
| 1000 | + "gix-error", | |
| 1001 | + "gix-hash", | |
| 1002 | + "gix-object", | |
| 1003 | + "gix-revwalk", | |
| 1004 | + "nonempty", | |
| 1005 | +] | |
| 1006 | + | |
| 1007 | +[[package]] | |
| 1008 | +name = "gix-revwalk" | |
| 1009 | +version = "0.37.0" | |
| 1010 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1011 | +checksum = "800479fbbf1e7f94f663e07943a91add5499343e7aac611a81e6a0460fd44af6" | |
| 1012 | +dependencies = [ | |
| 1013 | + "gix-commitgraph", | |
| 1014 | + "gix-date", | |
| 1015 | + "gix-error", | |
| 1016 | + "gix-hash", | |
| 1017 | + "gix-hashtable", | |
| 1018 | + "gix-object", | |
| 1019 | + "smallvec", | |
| 1020 | +] | |
| 1021 | + | |
| 1022 | +[[package]] | |
| 1023 | +name = "gix-sec" | |
| 1024 | +version = "0.16.0" | |
| 1025 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1026 | +checksum = "5640f642a1b471616d48230b1def7ca743cb30903441ff84800cafbab3c0fddf" | |
| 1027 | +dependencies = [ | |
| 1028 | + "bitflags 2.13.2", | |
| 1029 | + "gix-path", | |
| 1030 | + "libc", | |
| 1031 | + "windows-sys", | |
| 1032 | +] | |
| 1033 | + | |
| 1034 | +[[package]] | |
| 1035 | +name = "gix-shallow" | |
| 1036 | +version = "0.15.0" | |
| 1037 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1038 | +checksum = "94bc0720a3d6b10f18e3ac382a7780bcfc4c6bee94a8b5857b8e4ec94c50d754" | |
| 1039 | +dependencies = [ | |
| 1040 | + "bstr", | |
| 1041 | + "gix-error", | |
| 1042 | + "gix-hash", | |
| 1043 | + "gix-lock", | |
| 1044 | + "nonempty", | |
| 1045 | +] | |
| 1046 | + | |
| 1047 | +[[package]] | |
| 1048 | +name = "gix-tempfile" | |
| 1049 | +version = "26.0.0" | |
| 1050 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1051 | +checksum = "e9275c8ae0646d840ae0156d3f90d39b7beea6e31a398afb9ee72feb293a269c" | |
| 1052 | +dependencies = [ | |
| 1053 | + "gix-fs", | |
| 1054 | + "libc", | |
| 1055 | + "parking_lot", | |
| 1056 | + "tempfile", | |
| 1057 | + "windows-sys", | |
| 1058 | +] | |
| 1059 | + | |
| 1060 | +[[package]] | |
| 1061 | +name = "gix-trace" | |
| 1062 | +version = "0.3.0" | |
| 1063 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1064 | +checksum = "133f2de116104d637541831b6acb157898556d5eeec363ab2eb1c583adc6bb56" | |
| 1065 | + | |
| 1066 | +[[package]] | |
| 1067 | +name = "gix-transport" | |
| 1068 | +version = "0.61.0" | |
| 1069 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1070 | +checksum = "2e43d6b0097ea9f2f266d5d6c43b8f615ed3da7c686ec8771cd17c1cb33cb0de" | |
| 1071 | +dependencies = [ | |
| 1072 | + "bstr", | |
| 1073 | + "gix-command", | |
| 1074 | + "gix-error", | |
| 1075 | + "gix-packetline", | |
| 1076 | + "gix-path", | |
| 1077 | + "gix-quote", | |
| 1078 | + "gix-sec", | |
| 1079 | + "gix-trace", | |
| 1080 | + "gix-url", | |
| 1081 | + "gix-utils", | |
| 1082 | +] | |
| 1083 | + | |
| 1084 | +[[package]] | |
| 1085 | +name = "gix-traverse" | |
| 1086 | +version = "0.63.0" | |
| 1087 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1088 | +checksum = "a668a6e7f7688e5a43eaf161f1471ffc559de1a5fd8471e861c64d59d1699e1e" | |
| 1089 | +dependencies = [ | |
| 1090 | + "bitflags 2.13.2", | |
| 1091 | + "gix-commitgraph", | |
| 1092 | + "gix-date", | |
| 1093 | + "gix-error", | |
| 1094 | + "gix-hash", | |
| 1095 | + "gix-hashtable", | |
| 1096 | + "gix-object", | |
| 1097 | + "gix-revwalk", | |
| 1098 | + "smallvec", | |
| 1099 | +] | |
| 1100 | + | |
| 1101 | +[[package]] | |
| 1102 | +name = "gix-url" | |
| 1103 | +version = "0.40.0" | |
| 1104 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1105 | +checksum = "04317dea7a5dd5253bbcab060c230f3de6a57d17cc9600c6cd7030bf4795b414" | |
| 1106 | +dependencies = [ | |
| 1107 | + "bstr", | |
| 1108 | + "gix-error", | |
| 1109 | + "gix-path", | |
| 1110 | + "gix-utils", | |
| 1111 | + "percent-encoding", | |
| 1112 | +] | |
| 1113 | + | |
| 1114 | +[[package]] | |
| 1115 | +name = "gix-utils" | |
| 1116 | +version = "0.5.1" | |
| 1117 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1118 | +checksum = "f8e770b8c34311044d1addc7b18957db0ac27183707e1140dc90e6f674a6354e" | |
| 1119 | +dependencies = [ | |
| 1120 | + "bstr", | |
| 1121 | + "bytes", | |
| 1122 | + "fastrand", | |
| 1123 | + "getrandom", | |
| 1124 | + "gix-error", | |
| 1125 | + "prodash", | |
| 1126 | + "unicode-normalization", | |
| 1127 | +] | |
| 1128 | + | |
| 1129 | +[[package]] | |
| 1130 | +name = "gix-validate" | |
| 1131 | +version = "0.13.0" | |
| 1132 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1133 | +checksum = "cbcd59cc52742468bc5c8a0e7123390d154f45e6cbd37461b0dcecdc681f2179" | |
| 1134 | +dependencies = [ | |
| 1135 | + "bstr", | |
| 1136 | + "gix-error", | |
| 1137 | +] | |
| 1138 | + | |
| 1139 | +[[package]] | |
| 1140 | +name = "gix-worktree-stream" | |
| 1141 | +version = "0.38.0" | |
| 1142 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1143 | +checksum = "28d2789610e8179d4e0e8e51170a52a66483c103a8ad3c7db4d075b571856cb6" | |
| 1144 | +dependencies = [ | |
| 1145 | + "gix-attributes", | |
| 1146 | + "gix-error", | |
| 1147 | + "gix-filter", | |
| 1148 | + "gix-fs", | |
| 1149 | + "gix-hash", | |
| 1150 | + "gix-object", | |
| 1151 | + "gix-parallel", | |
| 1152 | + "gix-path", | |
| 1153 | + "gix-trace", | |
| 1154 | + "gix-traverse", | |
| 1155 | + "gix-utils", | |
| 1156 | + "parking_lot", | |
| 1157 | +] | |
| 1158 | + | |
| 1159 | +[[package]] | |
| 1160 | +name = "gix-zlib" | |
| 1161 | +version = "0.3.0" | |
| 1162 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1163 | +checksum = "8c2edb206bf06f3c801f4f6789c696396171558ab9b4c7f1fe3ba4d39b00b0f4" | |
| 1164 | +dependencies = [ | |
| 1165 | + "gix-error", | |
| 1166 | + "zlib-rs", | |
| 1167 | +] | |
| 1168 | + | |
| 1169 | +[[package]] | |
| 1170 | +name = "hash32" | |
| 1171 | +version = "0.3.1" | |
| 1172 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1173 | +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" | |
| 1174 | +dependencies = [ | |
| 1175 | + "byteorder", | |
| 1176 | +] | |
| 1177 | + | |
| 1178 | +[[package]] | |
| 1179 | +name = "hashbrown" | |
| 1180 | +version = "0.16.1" | |
| 1181 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1182 | +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" | |
| 1183 | +dependencies = [ | |
| 1184 | + "allocator-api2", | |
| 1185 | + "equivalent", | |
| 1186 | + "foldhash", | |
| 1187 | +] | |
| 1188 | + | |
| 344 | 1189 | [[package]] |
| 345 | 1190 | name = "hashbrown" |
| 346 | 1191 | version = "0.17.1" |
| 347 | 1192 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 348 | 1193 | checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" |
| 349 | 1194 | |
| 1195 | +[[package]] | |
| 1196 | +name = "heapless" | |
| 1197 | +version = "0.8.0" | |
| 1198 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1199 | +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" | |
| 1200 | +dependencies = [ | |
| 1201 | + "hash32", | |
| 1202 | + "stable_deref_trait", | |
| 1203 | +] | |
| 1204 | + | |
| 350 | 1205 | [[package]] |
| 351 | 1206 | name = "heck" |
| 352 | 1207 | version = "0.5.0" |
| 353 | 1208 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 354 | 1209 | checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" |
| 355 | 1210 | |
| 1211 | +[[package]] | |
| 1212 | +name = "hybrid-array" | |
| 1213 | +version = "0.4.15" | |
| 1214 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1215 | +checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17" | |
| 1216 | +dependencies = [ | |
| 1217 | + "typenum", | |
| 1218 | +] | |
| 1219 | + | |
| 356 | 1220 | [[package]] |
| 357 | 1221 | name = "indexmap" |
| 358 | 1222 | version = "2.14.2" |
| @@ -360,7 +1224,7 @@ | ||
| 360 | 1224 | checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" |
| 361 | 1225 | dependencies = [ |
| 362 | 1226 | "equivalent", |
| 363 | - "hashbrown", | |
| 1227 | + "hashbrown 0.17.1", | |
| 364 | 1228 | ] |
| 365 | 1229 | |
| 366 | 1230 | [[package]] |
| @@ -375,6 +1239,60 @@ | ||
| 375 | 1239 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 376 | 1240 | checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" |
| 377 | 1241 | |
| 1242 | +[[package]] | |
| 1243 | +name = "jiff" | |
| 1244 | +version = "0.2.38" | |
| 1245 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1246 | +checksum = "b2b005715dcbeb0089a3c0dab99f2ff1cc3b2525323552703d648585d342a383" | |
| 1247 | +dependencies = [ | |
| 1248 | + "defmt 1.2.0", | |
| 1249 | + "jiff-core", | |
| 1250 | + "jiff-static", | |
| 1251 | + "jiff-tzdb-platform", | |
| 1252 | + "log", | |
| 1253 | + "portable-atomic", | |
| 1254 | + "portable-atomic-util", | |
| 1255 | + "serde_core", | |
| 1256 | + "windows-link", | |
| 1257 | +] | |
| 1258 | + | |
| 1259 | +[[package]] | |
| 1260 | +name = "jiff-core" | |
| 1261 | +version = "0.1.1" | |
| 1262 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1263 | +checksum = "5e52fe76043ccecc9005d2305ebaadf7d7fc0cc89ca6baa10a94d6bc68c7128c" | |
| 1264 | +dependencies = [ | |
| 1265 | + "defmt 1.2.0", | |
| 1266 | + "log", | |
| 1267 | +] | |
| 1268 | + | |
| 1269 | +[[package]] | |
| 1270 | +name = "jiff-static" | |
| 1271 | +version = "0.2.38" | |
| 1272 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1273 | +checksum = "2cc9817253cf7c7ee4684451bd327e88d6f3658014e54a29198625590650695c" | |
| 1274 | +dependencies = [ | |
| 1275 | + "jiff-core", | |
| 1276 | + "proc-macro2", | |
| 1277 | + "quote", | |
| 1278 | + "syn 2.0.119", | |
| 1279 | +] | |
| 1280 | + | |
| 1281 | +[[package]] | |
| 1282 | +name = "jiff-tzdb" | |
| 1283 | +version = "0.1.9" | |
| 1284 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1285 | +checksum = "fa8377070c6bae868759445e5a77f66d84f0b72f3a054bfb00e6d038b8282da7" | |
| 1286 | + | |
| 1287 | +[[package]] | |
| 1288 | +name = "jiff-tzdb-platform" | |
| 1289 | +version = "0.1.3" | |
| 1290 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1291 | +checksum = "875a5a69ac2bab1a891711cf5eccbec1ce0341ea805560dcd90b7a2e925132e8" | |
| 1292 | +dependencies = [ | |
| 1293 | + "jiff-tzdb", | |
| 1294 | +] | |
| 1295 | + | |
| 378 | 1296 | [[package]] |
| 379 | 1297 | name = "jobserver" |
| 380 | 1298 | version = "0.1.35" |
| @@ -397,12 +1315,48 @@ | ||
| 397 | 1315 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 398 | 1316 | checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" |
| 399 | 1317 | |
| 1318 | +[[package]] | |
| 1319 | +name = "lock_api" | |
| 1320 | +version = "0.4.14" | |
| 1321 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1322 | +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" | |
| 1323 | +dependencies = [ | |
| 1324 | + "scopeguard", | |
| 1325 | +] | |
| 1326 | + | |
| 1327 | +[[package]] | |
| 1328 | +name = "log" | |
| 1329 | +version = "0.4.34" | |
| 1330 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1331 | +checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" | |
| 1332 | + | |
| 400 | 1333 | [[package]] |
| 401 | 1334 | name = "memchr" |
| 402 | 1335 | version = "2.8.3" |
| 403 | 1336 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 404 | 1337 | checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" |
| 405 | 1338 | |
| 1339 | +[[package]] | |
| 1340 | +name = "memmap2" | |
| 1341 | +version = "0.9.11" | |
| 1342 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1343 | +checksum = "d1219ed1b7f229ee7104d281dd01d6802fe28bb6e95d292942c4daacdeb798c0" | |
| 1344 | +dependencies = [ | |
| 1345 | + "libc", | |
| 1346 | +] | |
| 1347 | + | |
| 1348 | +[[package]] | |
| 1349 | +name = "multiversion_no_op" | |
| 1350 | +version = "1.0.0" | |
| 1351 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1352 | +checksum = "743fb55ba31b18fb1ecef6bdc9aa2743314978ac084044301a7eee33fb99a20d" | |
| 1353 | + | |
| 1354 | +[[package]] | |
| 1355 | +name = "nonempty" | |
| 1356 | +version = "0.12.0" | |
| 1357 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1358 | +checksum = "9737e026353e5cd0736f98eddae28665118eb6f6600902a7f50db585621fecb6" | |
| 1359 | + | |
| 406 | 1360 | [[package]] |
| 407 | 1361 | name = "num-traits" |
| 408 | 1362 | version = "0.2.19" |
| @@ -424,12 +1378,56 @@ | ||
| 424 | 1378 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 425 | 1379 | checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" |
| 426 | 1380 | |
| 1381 | +[[package]] | |
| 1382 | +name = "parking_lot" | |
| 1383 | +version = "0.12.5" | |
| 1384 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1385 | +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" | |
| 1386 | +dependencies = [ | |
| 1387 | + "lock_api", | |
| 1388 | + "parking_lot_core", | |
| 1389 | +] | |
| 1390 | + | |
| 1391 | +[[package]] | |
| 1392 | +name = "parking_lot_core" | |
| 1393 | +version = "0.9.12" | |
| 1394 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1395 | +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" | |
| 1396 | +dependencies = [ | |
| 1397 | + "cfg-if", | |
| 1398 | + "libc", | |
| 1399 | + "redox_syscall", | |
| 1400 | + "smallvec", | |
| 1401 | + "windows-link", | |
| 1402 | +] | |
| 1403 | + | |
| 1404 | +[[package]] | |
| 1405 | +name = "percent-encoding" | |
| 1406 | +version = "2.3.2" | |
| 1407 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1408 | +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" | |
| 1409 | + | |
| 427 | 1410 | [[package]] |
| 428 | 1411 | name = "pkg-config" |
| 429 | 1412 | version = "0.3.34" |
| 430 | 1413 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 431 | 1414 | checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" |
| 432 | 1415 | |
| 1416 | +[[package]] | |
| 1417 | +name = "portable-atomic" | |
| 1418 | +version = "1.15.0" | |
| 1419 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1420 | +checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85" | |
| 1421 | + | |
| 1422 | +[[package]] | |
| 1423 | +name = "portable-atomic-util" | |
| 1424 | +version = "0.2.8" | |
| 1425 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1426 | +checksum = "10ab3eb7f3becc3a1cbc4f2c6f20267996cfc1a6467a873763411b136a122715" | |
| 1427 | +dependencies = [ | |
| 1428 | + "portable-atomic", | |
| 1429 | +] | |
| 1430 | + | |
| 433 | 1431 | [[package]] |
| 434 | 1432 | name = "proc-macro-crate" |
| 435 | 1433 | version = "3.5.0" |
| @@ -448,6 +1446,15 @@ | ||
| 448 | 1446 | "unicode-ident", |
| 449 | 1447 | ] |
| 450 | 1448 | |
| 1449 | +[[package]] | |
| 1450 | +name = "prodash" | |
| 1451 | +version = "31.0.1" | |
| 1452 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1453 | +checksum = "cf52d87428247c5aa3760ac8e7d8b13ec7b3579b955a8c3f311668b6860acba5" | |
| 1454 | +dependencies = [ | |
| 1455 | + "parking_lot", | |
| 1456 | +] | |
| 1457 | + | |
| 451 | 1458 | [[package]] |
| 452 | 1459 | name = "proptest" |
| 453 | 1460 | version = "1.12.0" |
| @@ -456,7 +1463,7 @@ | ||
| 456 | 1463 | dependencies = [ |
| 457 | 1464 | "bit-set", |
| 458 | 1465 | "bit-vec", |
| 459 | - "bitflags", | |
| 1466 | + "bitflags 2.13.2", | |
| 460 | 1467 | "chacha20", |
| 461 | 1468 | "core_detect", |
| 462 | 1469 | "num-traits", |
| @@ -514,6 +1521,21 @@ | ||
| 514 | 1521 | "rand_core", |
| 515 | 1522 | ] |
| 516 | 1523 | |
| 1524 | +[[package]] | |
| 1525 | +name = "redox_syscall" | |
| 1526 | +version = "0.5.18" | |
| 1527 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1528 | +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" | |
| 1529 | +dependencies = [ | |
| 1530 | + "bitflags 2.13.2", | |
| 1531 | +] | |
| 1532 | + | |
| 1533 | +[[package]] | |
| 1534 | +name = "regex-automata" | |
| 1535 | +version = "0.4.18" | |
| 1536 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1537 | +checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2" | |
| 1538 | + | |
| 517 | 1539 | [[package]] |
| 518 | 1540 | name = "regex-syntax" |
| 519 | 1541 | version = "0.8.11" |
| @@ -535,13 +1557,19 @@ | ||
| 535 | 1557 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 536 | 1558 | checksum = "891efababe418670775f199f0d233d84843c227a0949a883ce15b37c78d6629d" |
| 537 | 1559 | dependencies = [ |
| 538 | - "bitflags", | |
| 1560 | + "bitflags 2.13.2", | |
| 539 | 1561 | "errno", |
| 540 | 1562 | "libc", |
| 541 | 1563 | "linux-raw-sys", |
| 542 | 1564 | "windows-sys", |
| 543 | 1565 | ] |
| 544 | 1566 | |
| 1567 | +[[package]] | |
| 1568 | +name = "rustversion" | |
| 1569 | +version = "1.0.23" | |
| 1570 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1571 | +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" | |
| 1572 | + | |
| 545 | 1573 | [[package]] |
| 546 | 1574 | name = "rusty-fork" |
| 547 | 1575 | version = "0.3.1" |
| @@ -554,6 +1582,21 @@ | ||
| 554 | 1582 | "wait-timeout", |
| 555 | 1583 | ] |
| 556 | 1584 | |
| 1585 | +[[package]] | |
| 1586 | +name = "same-file" | |
| 1587 | +version = "1.0.6" | |
| 1588 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1589 | +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" | |
| 1590 | +dependencies = [ | |
| 1591 | + "winapi-util", | |
| 1592 | +] | |
| 1593 | + | |
| 1594 | +[[package]] | |
| 1595 | +name = "scopeguard" | |
| 1596 | +version = "1.2.0" | |
| 1597 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1598 | +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" | |
| 1599 | + | |
| 557 | 1600 | [[package]] |
| 558 | 1601 | name = "semver" |
| 559 | 1602 | version = "1.0.28" |
| @@ -587,7 +1630,7 @@ | ||
| 587 | 1630 | dependencies = [ |
| 588 | 1631 | "proc-macro2", |
| 589 | 1632 | "quote", |
| 590 | - "syn", | |
| 1633 | + "syn 3.0.9", | |
| 591 | 1634 | ] |
| 592 | 1635 | |
| 593 | 1636 | [[package]] |
| @@ -603,18 +1646,64 @@ | ||
| 603 | 1646 | "zmij", |
| 604 | 1647 | ] |
| 605 | 1648 | |
| 1649 | +[[package]] | |
| 1650 | +name = "sha1dc" | |
| 1651 | +version = "0.1.5" | |
| 1652 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1653 | +checksum = "c5b0ebf6537e3e8db8bb7d21ecb6d7399738c953c757945c6b95e46c4e95df7b" | |
| 1654 | + | |
| 1655 | +[[package]] | |
| 1656 | +name = "sha2" | |
| 1657 | +version = "0.11.1" | |
| 1658 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1659 | +checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19" | |
| 1660 | +dependencies = [ | |
| 1661 | + "cfg-if", | |
| 1662 | + "cpufeatures", | |
| 1663 | + "digest", | |
| 1664 | +] | |
| 1665 | + | |
| 606 | 1666 | [[package]] |
| 607 | 1667 | name = "shlex" |
| 608 | 1668 | version = "2.0.1" |
| 609 | 1669 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 610 | 1670 | checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" |
| 611 | 1671 | |
| 1672 | +[[package]] | |
| 1673 | +name = "simdutf8" | |
| 1674 | +version = "0.1.5" | |
| 1675 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1676 | +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" | |
| 1677 | + | |
| 1678 | +[[package]] | |
| 1679 | +name = "smallvec" | |
| 1680 | +version = "1.16.3" | |
| 1681 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1682 | +checksum = "5b3dc8af474f516a851ff4bd12db780f948b9250ad37211e4eec0bccea54e01b" | |
| 1683 | + | |
| 1684 | +[[package]] | |
| 1685 | +name = "stable_deref_trait" | |
| 1686 | +version = "1.2.1" | |
| 1687 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1688 | +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" | |
| 1689 | + | |
| 612 | 1690 | [[package]] |
| 613 | 1691 | name = "strsim" |
| 614 | 1692 | version = "0.11.1" |
| 615 | 1693 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 616 | 1694 | checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" |
| 617 | 1695 | |
| 1696 | +[[package]] | |
| 1697 | +name = "syn" | |
| 1698 | +version = "2.0.119" | |
| 1699 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1700 | +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" | |
| 1701 | +dependencies = [ | |
| 1702 | + "proc-macro2", | |
| 1703 | + "quote", | |
| 1704 | + "unicode-ident", | |
| 1705 | +] | |
| 1706 | + | |
| 618 | 1707 | [[package]] |
| 619 | 1708 | name = "syn" |
| 620 | 1709 | version = "3.0.9" |
| @@ -656,7 +1745,7 @@ | ||
| 656 | 1745 | dependencies = [ |
| 657 | 1746 | "proc-macro2", |
| 658 | 1747 | "quote", |
| 659 | - "syn", | |
| 1748 | + "syn 3.0.9", | |
| 660 | 1749 | ] |
| 661 | 1750 | |
| 662 | 1751 | [[package]] |
| @@ -695,12 +1784,24 @@ | ||
| 695 | 1784 | "winnow", |
| 696 | 1785 | ] |
| 697 | 1786 | |
| 1787 | +[[package]] | |
| 1788 | +name = "typenum" | |
| 1789 | +version = "1.20.1" | |
| 1790 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1791 | +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" | |
| 1792 | + | |
| 698 | 1793 | [[package]] |
| 699 | 1794 | name = "unarray" |
| 700 | 1795 | version = "0.1.4" |
| 701 | 1796 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 702 | 1797 | checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" |
| 703 | 1798 | |
| 1799 | +[[package]] | |
| 1800 | +name = "unicode-bom" | |
| 1801 | +version = "2.0.3" | |
| 1802 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1803 | +checksum = "7eec5d1121208364f6793f7d2e222bf75a915c19557537745b195b253dd64217" | |
| 1804 | + | |
| 704 | 1805 | [[package]] |
| 705 | 1806 | name = "unicode-ident" |
| 706 | 1807 | version = "1.0.27" |
| @@ -731,6 +1832,25 @@ | ||
| 731 | 1832 | "libc", |
| 732 | 1833 | ] |
| 733 | 1834 | |
| 1835 | +[[package]] | |
| 1836 | +name = "walkdir" | |
| 1837 | +version = "2.5.0" | |
| 1838 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1839 | +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" | |
| 1840 | +dependencies = [ | |
| 1841 | + "same-file", | |
| 1842 | + "winapi-util", | |
| 1843 | +] | |
| 1844 | + | |
| 1845 | +[[package]] | |
| 1846 | +name = "winapi-util" | |
| 1847 | +version = "0.1.11" | |
| 1848 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1849 | +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" | |
| 1850 | +dependencies = [ | |
| 1851 | + "windows-sys", | |
| 1852 | +] | |
| 1853 | + | |
| 734 | 1854 | [[package]] |
| 735 | 1855 | name = "windows-link" |
| 736 | 1856 | version = "0.2.1" |
| @@ -755,6 +1875,12 @@ | ||
| 755 | 1875 | "memchr", |
| 756 | 1876 | ] |
| 757 | 1877 | |
| 1878 | +[[package]] | |
| 1879 | +name = "zlib-rs" | |
| 1880 | +version = "0.6.8" | |
| 1881 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1882 | +checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112" | |
| 1883 | + | |
| 758 | 1884 | [[package]] |
| 759 | 1885 | name = "zmij" |
| 760 | 1886 | version = "1.0.23" |
added crates/git/Cargo.toml +34 −0
| @@ -0,0 +1,34 @@ | ||
| 1 | +[package] | |
| 2 | +name = "elffuss-braid-git" | |
| 3 | +description = "Git bridge of elffuss-braid: bit-for-bit import and export of git history through gitoxide." | |
| 4 | +version.workspace = true | |
| 5 | +edition.workspace = true | |
| 6 | +rust-version.workspace = true | |
| 7 | +license.workspace = true | |
| 8 | +repository.workspace = true | |
| 9 | +homepage.workspace = true | |
| 10 | +publish.workspace = true | |
| 11 | + | |
| 12 | +[lib] | |
| 13 | +name = "braid_git" | |
| 14 | + | |
| 15 | +[dependencies] | |
| 16 | +braid-format.workspace = true | |
| 17 | +# Local repositories only: no network, no TLS. `sha256` is there so that a | |
| 18 | +# SHA-256 repository opens and can be refused with a clear error. | |
| 19 | +gix = { version = "0.89", default-features = false, features = [ | |
| 20 | + "sha1", | |
| 21 | + "sha256", | |
| 22 | + "pack-cache-lru-dynamic", | |
| 23 | +] } | |
| 24 | + | |
| 25 | +[features] | |
| 26 | +# Exposes the git object parsers to the fuzz targets in `fuzz/`; not a stable | |
| 27 | +# API. | |
| 28 | +fuzzing = [] | |
| 29 | + | |
| 30 | +[dev-dependencies] | |
| 31 | +tempfile = "3" | |
| 32 | + | |
| 33 | +[lints] | |
| 34 | +workspace = true |
added crates/git/src/diff.rs +244 −0
| @@ -0,0 +1,244 @@ | ||
| 1 | +// SPDX-License-Identifier: Apache-2.0 | |
| 2 | +// Copyright (c) 2026 UtopiaIA | |
| 3 | + | |
| 4 | +//! The change list of a changeset: every file whose entry differs between two | |
| 5 | +//! braid trees. | |
| 6 | + | |
| 7 | +use braid_format::{Change, ChangeOp, Entry, EntryKind, ObjectId, Objects}; | |
| 8 | + | |
| 9 | +use crate::error::Error; | |
| 10 | +use crate::fetch; | |
| 11 | + | |
| 12 | +/// The per-file changes from `old` to `new`, in no particular order. `None` | |
| 13 | +/// stands for the empty tree. Subtrees with equal ids are skipped without | |
| 14 | +/// being read, so the cost follows what changed. A directory replaced by a | |
| 15 | +/// file is a delete for every file below it and one set for the file. | |
| 16 | +pub(crate) fn changes<O: Objects>( | |
| 17 | + objects: &O, | |
| 18 | + old: Option<ObjectId>, | |
| 19 | + new: ObjectId, | |
| 20 | +) -> Result<Vec<Change>, Error> { | |
| 21 | + let mut changes = Vec::new(); | |
| 22 | + // Directories still to compare: path prefix, old side, new side. | |
| 23 | + let mut pending: Vec<(Vec<u8>, Option<ObjectId>, Option<ObjectId>)> = | |
| 24 | + vec![(Vec::new(), old, Some(new))]; | |
| 25 | + while let Some((prefix, old, new)) = pending.pop() { | |
| 26 | + if old == new { | |
| 27 | + continue; | |
| 28 | + } | |
| 29 | + let old_entries = match old { | |
| 30 | + Some(id) => fetch::tree_entries(objects, id)?, | |
| 31 | + None => Vec::new(), | |
| 32 | + }; | |
| 33 | + let new_entries = match new { | |
| 34 | + Some(id) => fetch::tree_entries(objects, id)?, | |
| 35 | + None => Vec::new(), | |
| 36 | + }; | |
| 37 | + let mut olds = old_entries.into_iter().peekable(); | |
| 38 | + let mut news = new_entries.into_iter().peekable(); | |
| 39 | + loop { | |
| 40 | + // Both sides are sorted by name bytes. | |
| 41 | + let (before, after) = match (olds.peek(), news.peek()) { | |
| 42 | + (None, None) => break, | |
| 43 | + (Some(_), None) => (olds.next(), None), | |
| 44 | + (None, Some(_)) => (None, news.next()), | |
| 45 | + (Some(o), Some(n)) => match o.name.cmp(&n.name) { | |
| 46 | + core::cmp::Ordering::Less => (olds.next(), None), | |
| 47 | + core::cmp::Ordering::Greater => (None, news.next()), | |
| 48 | + core::cmp::Ordering::Equal => (olds.next(), news.next()), | |
| 49 | + }, | |
| 50 | + }; | |
| 51 | + let name = match (&before, &after) { | |
| 52 | + (Some(entry), _) | (None, Some(entry)) => entry.name.clone(), | |
| 53 | + (None, None) => unreachable!("one side always has an entry"), | |
| 54 | + }; | |
| 55 | + let path = join(&prefix, &name); | |
| 56 | + compare( | |
| 57 | + path, | |
| 58 | + before.map(|e: Entry| e.kind), | |
| 59 | + after.map(|e: Entry| e.kind), | |
| 60 | + &mut changes, | |
| 61 | + &mut pending, | |
| 62 | + ); | |
| 63 | + } | |
| 64 | + } | |
| 65 | + Ok(changes) | |
| 66 | +} | |
| 67 | + | |
| 68 | +/// Records the changes for one name, queueing directories to compare. | |
| 69 | +fn compare( | |
| 70 | + path: Vec<u8>, | |
| 71 | + before: Option<EntryKind>, | |
| 72 | + after: Option<EntryKind>, | |
| 73 | + changes: &mut Vec<Change>, | |
| 74 | + pending: &mut Vec<(Vec<u8>, Option<ObjectId>, Option<ObjectId>)>, | |
| 75 | +) { | |
| 76 | + let tree_of = |kind: &Option<EntryKind>| match kind { | |
| 77 | + Some(EntryKind::Tree { tree }) => Some(*tree), | |
| 78 | + _ => None, | |
| 79 | + }; | |
| 80 | + let (old_tree, new_tree) = (tree_of(&before), tree_of(&after)); | |
| 81 | + if old_tree != new_tree { | |
| 82 | + pending.push((path.clone(), old_tree, new_tree)); | |
| 83 | + } | |
| 84 | + let old_file = before.filter(|kind| !matches!(kind, EntryKind::Tree { .. })); | |
| 85 | + let new_file = after.and_then(|kind| ChangeOp::from_entry(&kind)); | |
| 86 | + match (old_file, new_file) { | |
| 87 | + (None, None) => {} | |
| 88 | + (Some(_), None) => changes.push(Change { | |
| 89 | + path, | |
| 90 | + op: ChangeOp::Delete, | |
| 91 | + }), | |
| 92 | + (old, Some(op)) => { | |
| 93 | + if old.and_then(|kind| ChangeOp::from_entry(&kind)).as_ref() != Some(&op) { | |
| 94 | + changes.push(Change { path, op }); | |
| 95 | + } | |
| 96 | + } | |
| 97 | + } | |
| 98 | +} | |
| 99 | + | |
| 100 | +fn join(prefix: &[u8], name: &[u8]) -> Vec<u8> { | |
| 101 | + if prefix.is_empty() { | |
| 102 | + return name.to_vec(); | |
| 103 | + } | |
| 104 | + let mut path = Vec::with_capacity(prefix.len() + 1 + name.len()); | |
| 105 | + path.extend_from_slice(prefix); | |
| 106 | + path.push(b'/'); | |
| 107 | + path.extend_from_slice(name); | |
| 108 | + path | |
| 109 | +} | |
| 110 | + | |
| 111 | +#[cfg(test)] | |
| 112 | +mod tests { | |
| 113 | + use super::*; | |
| 114 | + use braid_format::{GitId, Kind, MemoryObjects, build_directory}; | |
| 115 | + | |
| 116 | + fn put_tree(objects: &MemoryObjects, entries: Vec<Entry>) -> ObjectId { | |
| 117 | + let dir = build_directory(entries).unwrap(); | |
| 118 | + for (_, bytes) in &dir.nodes { | |
| 119 | + objects.put(Kind::Tree, bytes).unwrap(); | |
| 120 | + } | |
| 121 | + dir.root() | |
| 122 | + } | |
| 123 | + | |
| 124 | + fn file(name: &str, text: &str) -> Entry { | |
| 125 | + Entry { | |
| 126 | + name: name.as_bytes().to_vec(), | |
| 127 | + kind: EntryKind::File { | |
| 128 | + blob: ObjectId::hash(Kind::Blob, text.as_bytes()), | |
| 129 | + size: text.len() as u64, | |
| 130 | + }, | |
| 131 | + } | |
| 132 | + } | |
| 133 | + | |
| 134 | + fn dir(name: &str, tree: ObjectId) -> Entry { | |
| 135 | + Entry { | |
| 136 | + name: name.as_bytes().to_vec(), | |
| 137 | + kind: EntryKind::Tree { tree }, | |
| 138 | + } | |
| 139 | + } | |
| 140 | + | |
| 141 | + fn summary(mut changes: Vec<Change>) -> Vec<(String, &'static str)> { | |
| 142 | + changes.sort_by(|a, b| a.path.cmp(&b.path)); | |
| 143 | + changes | |
| 144 | + .into_iter() | |
| 145 | + .map(|change| { | |
| 146 | + let op = match change.op { | |
| 147 | + ChangeOp::Delete => "delete", | |
| 148 | + ChangeOp::File { .. } => "file", | |
| 149 | + ChangeOp::Executable { .. } => "exec", | |
| 150 | + ChangeOp::Symlink { .. } => "symlink", | |
| 151 | + ChangeOp::Gitlink { .. } => "gitlink", | |
| 152 | + }; | |
| 153 | + (String::from_utf8(change.path).unwrap(), op) | |
| 154 | + }) | |
| 155 | + .collect() | |
| 156 | + } | |
| 157 | + | |
| 158 | + #[test] | |
| 159 | + fn from_nothing_lists_every_file() { | |
| 160 | + let objects = MemoryObjects::new(); | |
| 161 | + let sub = put_tree(&objects, vec![file("b", "2"), file("c", "3")]); | |
| 162 | + let root = put_tree(&objects, vec![file("a", "1"), dir("sub", sub)]); | |
| 163 | + assert_eq!( | |
| 164 | + summary(changes(&objects, None, root).unwrap()), | |
| 165 | + [ | |
| 166 | + ("a".into(), "file"), | |
| 167 | + ("sub/b".into(), "file"), | |
| 168 | + ("sub/c".into(), "file") | |
| 169 | + ] | |
| 170 | + ); | |
| 171 | + assert!(changes(&objects, Some(root), root).unwrap().is_empty()); | |
| 172 | + } | |
| 173 | + | |
| 174 | + #[test] | |
| 175 | + fn edits_kinds_and_directory_swaps() { | |
| 176 | + let objects = MemoryObjects::new(); | |
| 177 | + let empty = put_tree(&objects, Vec::new()); | |
| 178 | + let inner = put_tree(&objects, vec![file("x", "1"), file("y", "2")]); | |
| 179 | + let shared = put_tree(&objects, vec![file("s", "same")]); | |
| 180 | + let old = put_tree( | |
| 181 | + &objects, | |
| 182 | + vec![ | |
| 183 | + file("edit", "old"), | |
| 184 | + file("mode", "m"), | |
| 185 | + dir("gone", inner), | |
| 186 | + file("becomes-dir", "f"), | |
| 187 | + dir("same", shared), | |
| 188 | + dir("empty", empty), | |
| 189 | + Entry { | |
| 190 | + name: b"sub".to_vec(), | |
| 191 | + kind: EntryKind::Gitlink { | |
| 192 | + commit: GitId::Sha1([1; 20]), | |
| 193 | + }, | |
| 194 | + }, | |
| 195 | + ], | |
| 196 | + ); | |
| 197 | + let new = put_tree( | |
| 198 | + &objects, | |
| 199 | + vec![ | |
| 200 | + file("edit", "new"), | |
| 201 | + Entry { | |
| 202 | + name: b"mode".to_vec(), | |
| 203 | + kind: EntryKind::Executable { | |
| 204 | + blob: ObjectId::hash(Kind::Blob, b"m"), | |
| 205 | + size: 1, | |
| 206 | + }, | |
| 207 | + }, | |
| 208 | + file("gone", "now a file"), | |
| 209 | + dir("becomes-dir", inner), | |
| 210 | + dir("same", shared), | |
| 211 | + Entry { | |
| 212 | + name: b"sub".to_vec(), | |
| 213 | + kind: EntryKind::Gitlink { | |
| 214 | + commit: GitId::Sha1([2; 20]), | |
| 215 | + }, | |
| 216 | + }, | |
| 217 | + ], | |
| 218 | + ); | |
| 219 | + assert_eq!( | |
| 220 | + summary(changes(&objects, Some(old), new).unwrap()), | |
| 221 | + [ | |
| 222 | + ("becomes-dir".into(), "delete"), | |
| 223 | + ("becomes-dir/x".into(), "file"), | |
| 224 | + ("becomes-dir/y".into(), "file"), | |
| 225 | + ("edit".into(), "file"), | |
| 226 | + ("gone".into(), "file"), | |
| 227 | + ("gone/x".into(), "delete"), | |
| 228 | + ("gone/y".into(), "delete"), | |
| 229 | + ("mode".into(), "exec"), | |
| 230 | + ("sub".into(), "gitlink"), | |
| 231 | + ] | |
| 232 | + ); | |
| 233 | + } | |
| 234 | + | |
| 235 | + #[test] | |
| 236 | + fn missing_trees_are_errors() { | |
| 237 | + let objects = MemoryObjects::new(); | |
| 238 | + let missing = ObjectId::hash(Kind::Tree, b"nowhere"); | |
| 239 | + assert!(matches!( | |
| 240 | + changes(&objects, None, missing), | |
| 241 | + Err(Error::MissingBraidObject { .. }) | |
| 242 | + )); | |
| 243 | + } | |
| 244 | +} |
added crates/git/src/error.rs +225 −0
| @@ -0,0 +1,225 @@ | ||
| 1 | +// SPDX-License-Identifier: Apache-2.0 | |
| 2 | +// Copyright (c) 2026 UtopiaIA | |
| 3 | + | |
| 4 | +//! Errors of the git bridge. | |
| 5 | + | |
| 6 | +use core::fmt; | |
| 7 | + | |
| 8 | +use braid_format::{Kind, ObjectId}; | |
| 9 | + | |
| 10 | +use crate::oid::{GitKind, GitOid}; | |
| 11 | + | |
| 12 | +/// An error from a lower layer: gitoxide or an object store. | |
| 13 | +pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>; | |
| 14 | + | |
| 15 | +/// Why an import, an export or a round trip failed. | |
| 16 | +#[derive(Debug)] | |
| 17 | +#[non_exhaustive] | |
| 18 | +pub enum Error { | |
| 19 | + /// gitoxide could not open, read or write a repository. | |
| 20 | + Git { | |
| 21 | + /// What was being done. | |
| 22 | + context: String, | |
| 23 | + /// The underlying error. | |
| 24 | + source: BoxError, | |
| 25 | + }, | |
| 26 | + /// The braid object store failed. | |
| 27 | + Objects(BoxError), | |
| 28 | + /// The repository is a shallow clone, so part of its history is missing. | |
| 29 | + Shallow, | |
| 30 | + /// The repository uses SHA-256 object ids, which the bridge does not | |
| 31 | + /// support yet. | |
| 32 | + Sha256, | |
| 33 | + /// A ref that was asked for does not exist. | |
| 34 | + MissingRef(Vec<u8>), | |
| 35 | + /// A git object is not in the repository. | |
| 36 | + MissingObject(GitOid), | |
| 37 | + /// A git object is of another kind than the object naming it says. | |
| 38 | + WrongKind { | |
| 39 | + /// The object. | |
| 40 | + oid: GitOid, | |
| 41 | + /// The kind it should have. | |
| 42 | + expected: GitKind, | |
| 43 | + /// The kind it has. | |
| 44 | + found: GitKind, | |
| 45 | + }, | |
| 46 | + /// A git object's bytes do not hash to its id. | |
| 47 | + CorruptObject(GitOid), | |
| 48 | + /// SHA-1 collision detection found a known attack in an object. | |
| 49 | + Collision { | |
| 50 | + /// The kind of the object. | |
| 51 | + kind: GitKind, | |
| 52 | + }, | |
| 53 | + /// A git object cannot be parsed. | |
| 54 | + Malformed { | |
| 55 | + /// The object. | |
| 56 | + oid: GitOid, | |
| 57 | + /// Its kind. | |
| 58 | + kind: GitKind, | |
| 59 | + /// What is wrong with it. | |
| 60 | + reason: &'static str, | |
| 61 | + }, | |
| 62 | + /// A tree holds a name that braid refuses, such as an alias of `.git`. | |
| 63 | + /// These rules protect every checkout made from the repository. | |
| 64 | + RefusedPath { | |
| 65 | + /// The commit whose tree holds the path, or the object a ref points | |
| 66 | + /// to when no commit is involved. | |
| 67 | + commit: GitOid, | |
| 68 | + /// The full path from the root of that tree. | |
| 69 | + path: Vec<u8>, | |
| 70 | + /// Why the name is refused. | |
| 71 | + reason: String, | |
| 72 | + }, | |
| 73 | + /// A tree entry has a mode that is not a file, an executable, a symlink, | |
| 74 | + /// a directory or a submodule. | |
| 75 | + UnsupportedMode { | |
| 76 | + /// The commit whose tree holds the entry, or the object a ref points | |
| 77 | + /// to when no commit is involved. | |
| 78 | + commit: GitOid, | |
| 79 | + /// The full path of the entry. | |
| 80 | + path: Vec<u8>, | |
| 81 | + /// The mode as written in the tree. | |
| 82 | + mode: Vec<u8>, | |
| 83 | + }, | |
| 84 | + /// An imported object, exported again, did not give back its id. | |
| 85 | + Verification { | |
| 86 | + /// The object. | |
| 87 | + oid: GitOid, | |
| 88 | + /// Its kind. | |
| 89 | + kind: GitKind, | |
| 90 | + /// What differed. | |
| 91 | + detail: String, | |
| 92 | + }, | |
| 93 | + /// A braid object is missing from the store. | |
| 94 | + MissingBraidObject { | |
| 95 | + /// The object. | |
| 96 | + id: ObjectId, | |
| 97 | + /// The kind it should have. | |
| 98 | + expected: Kind, | |
| 99 | + }, | |
| 100 | + /// A braid object is not what the object naming it expects, or cannot be | |
| 101 | + /// decoded. | |
| 102 | + BadBraidObject { | |
| 103 | + /// The object. | |
| 104 | + id: ObjectId, | |
| 105 | + /// What is wrong with it. | |
| 106 | + detail: String, | |
| 107 | + }, | |
| 108 | + /// The map does not know an object that an export needs. | |
| 109 | + NotMapped { | |
| 110 | + /// What kind of object. | |
| 111 | + what: &'static str, | |
| 112 | + /// Its id, as text. | |
| 113 | + id: String, | |
| 114 | + }, | |
| 115 | + /// The git commit a changeset was imported from disagrees with the | |
| 116 | + /// changeset or with the map. | |
| 117 | + OriginMismatch { | |
| 118 | + /// The changeset. | |
| 119 | + changeset: ObjectId, | |
| 120 | + /// What disagrees. | |
| 121 | + detail: String, | |
| 122 | + }, | |
| 123 | + /// A changeset cannot be written as a git commit. | |
| 124 | + Unrepresentable { | |
| 125 | + /// The changeset. | |
| 126 | + changeset: ObjectId, | |
| 127 | + /// Why. | |
| 128 | + detail: String, | |
| 129 | + }, | |
| 130 | + /// A round trip found a difference between the source and the copy. | |
| 131 | + RoundTrip(String), | |
| 132 | +} | |
| 133 | + | |
| 134 | +/// Shows a path or a name, which are bytes, as text. | |
| 135 | +pub(crate) struct ShowBytes<'a>(pub &'a [u8]); | |
| 136 | + | |
| 137 | +impl fmt::Display for ShowBytes<'_> { | |
| 138 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
| 139 | + write!(f, "{:?}", String::from_utf8_lossy(self.0)) | |
| 140 | + } | |
| 141 | +} | |
| 142 | + | |
| 143 | +impl fmt::Display for Error { | |
| 144 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
| 145 | + match self { | |
| 146 | + Error::Git { context, source } => write!(f, "{context}: {source}"), | |
| 147 | + Error::Objects(source) => write!(f, "object store: {source}"), | |
| 148 | + Error::Shallow => { | |
| 149 | + f.write_str("the repository is a shallow clone; importing needs its whole history") | |
| 150 | + } | |
| 151 | + Error::Sha256 => f.write_str( | |
| 152 | + "the repository uses SHA-256 object ids, which the git bridge does not support yet", | |
| 153 | + ), | |
| 154 | + Error::MissingRef(name) => write!(f, "ref {} does not exist", ShowBytes(name)), | |
| 155 | + Error::MissingObject(oid) => write!(f, "git object {oid} is missing"), | |
| 156 | + Error::WrongKind { | |
| 157 | + oid, | |
| 158 | + expected, | |
| 159 | + found, | |
| 160 | + } => write!(f, "git object {oid} is a {found}, expected a {expected}"), | |
| 161 | + Error::CorruptObject(oid) => write!(f, "git object {oid} does not hash to its id"), | |
| 162 | + Error::Collision { kind } => { | |
| 163 | + write!(f, "SHA-1 collision attack detected in a git {kind}") | |
| 164 | + } | |
| 165 | + Error::Malformed { oid, kind, reason } => { | |
| 166 | + write!(f, "malformed git {kind} {oid}: {reason}") | |
| 167 | + } | |
| 168 | + Error::RefusedPath { | |
| 169 | + commit, | |
| 170 | + path, | |
| 171 | + reason, | |
| 172 | + } => write!( | |
| 173 | + f, | |
| 174 | + "commit {commit}: path {} is refused: {reason}", | |
| 175 | + ShowBytes(path) | |
| 176 | + ), | |
| 177 | + Error::UnsupportedMode { commit, path, mode } => write!( | |
| 178 | + f, | |
| 179 | + "commit {commit}: path {} has the unsupported mode {}", | |
| 180 | + ShowBytes(path), | |
| 181 | + ShowBytes(mode) | |
| 182 | + ), | |
| 183 | + Error::Verification { oid, kind, detail } => { | |
| 184 | + write!(f, "{kind} {oid} does not survive export: {detail}") | |
| 185 | + } | |
| 186 | + Error::MissingBraidObject { id, expected } => { | |
| 187 | + write!(f, "braid {expected} {id} is missing") | |
| 188 | + } | |
| 189 | + Error::BadBraidObject { id, detail } => write!(f, "braid object {id}: {detail}"), | |
| 190 | + Error::NotMapped { what, id } => write!(f, "the git map does not know {what} {id}"), | |
| 191 | + Error::OriginMismatch { changeset, detail } => { | |
| 192 | + write!(f, "changeset {changeset}: {detail}") | |
| 193 | + } | |
| 194 | + Error::Unrepresentable { changeset, detail } => write!( | |
| 195 | + f, | |
| 196 | + "changeset {changeset} cannot be written as a git commit: {detail}" | |
| 197 | + ), | |
| 198 | + Error::RoundTrip(detail) => write!(f, "round trip: {detail}"), | |
| 199 | + } | |
| 200 | + } | |
| 201 | +} | |
| 202 | + | |
| 203 | +impl std::error::Error for Error { | |
| 204 | + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { | |
| 205 | + match self { | |
| 206 | + Error::Git { source, .. } | Error::Objects(source) => Some(source.as_ref()), | |
| 207 | + _ => None, | |
| 208 | + } | |
| 209 | + } | |
| 210 | +} | |
| 211 | + | |
| 212 | +impl Error { | |
| 213 | + /// Wraps a gitoxide error with what was being done. | |
| 214 | + pub(crate) fn git(context: impl Into<String>, source: impl Into<BoxError>) -> Self { | |
| 215 | + Error::Git { | |
| 216 | + context: context.into(), | |
| 217 | + source: source.into(), | |
| 218 | + } | |
| 219 | + } | |
| 220 | + | |
| 221 | + /// Wraps an object store error. | |
| 222 | + pub(crate) fn objects(source: impl std::error::Error + Send + Sync + 'static) -> Self { | |
| 223 | + Error::Objects(Box::new(source)) | |
| 224 | + } | |
| 225 | +} |
added crates/git/src/export.rs +605 −0
| @@ -0,0 +1,605 @@ | ||
| 1 | +// SPDX-License-Identifier: Apache-2.0 | |
| 2 | +// Copyright (c) 2026 UtopiaIA | |
| 3 | + | |
| 4 | +//! Export: braid objects back to git objects, and into a git repository. | |
| 5 | + | |
| 6 | +use std::collections::{HashMap, HashSet}; | |
| 7 | +use std::fmt; | |
| 8 | +use std::path::Path; | |
| 9 | + | |
| 10 | +use braid_format::{Changeset, Entry, EntryKind, GitId, Kind, ObjectId, Objects}; | |
| 11 | + | |
| 12 | +use crate::error::Error; | |
| 13 | +use crate::fetch; | |
| 14 | +use crate::map::GitMap; | |
| 15 | +use crate::oid::{GitKind, GitOid}; | |
| 16 | +use crate::raw::{self, EntryType, TreeItem}; | |
| 17 | +use crate::repo::GitRepo; | |
| 18 | + | |
| 19 | +/// Produces git objects from braid objects. | |
| 20 | +/// | |
| 21 | +/// What came from git goes back byte for byte: a changeset with a git origin | |
| 22 | +/// is exported as its original commit, after checking that the tree and the | |
| 23 | +/// parents the commit names are the ones the map links to the changeset; a | |
| 24 | +/// git tree that is not canonical as its raw bytes; a tag as its raw bytes. | |
| 25 | +/// | |
| 26 | +/// Everything else is generated deterministically from braid content alone: | |
| 27 | +/// a tree with canonical modes and git's entry order, a commit with `tree`, | |
| 28 | +/// `parent`, `author` and `committer` headers, one header per extra, and the | |
| 29 | +/// message unchanged. | |
| 30 | +/// | |
| 31 | +/// An exporter caches the git ids it computes, so exporting many related | |
| 32 | +/// objects through one exporter does each piece of work once. Nothing is | |
| 33 | +/// recursive: deep histories and deep directories are walked with explicit | |
| 34 | +/// stacks. | |
| 35 | +pub struct Exporter<'a, O: Objects> { | |
| 36 | + objects: &'a O, | |
| 37 | + map: &'a GitMap, | |
| 38 | + /// Canonical git trees computed here, for braid trees the map does not | |
| 39 | + /// link to one, and back. | |
| 40 | + trees: HashMap<ObjectId, GitOid>, | |
| 41 | + tree_sources: HashMap<GitOid, ObjectId>, | |
| 42 | + /// Git blobs computed here, and back. | |
| 43 | + blobs: HashMap<ObjectId, GitOid>, | |
| 44 | + blob_sources: HashMap<GitOid, ObjectId>, | |
| 45 | + /// Commits exported here, and back. | |
| 46 | + commits: HashMap<ObjectId, GitOid>, | |
| 47 | + commit_sources: HashMap<GitOid, ObjectId>, | |
| 48 | +} | |
| 49 | + | |
| 50 | +impl<O: Objects> fmt::Debug for Exporter<'_, O> { | |
| 51 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
| 52 | + f.debug_struct("Exporter") | |
| 53 | + .field("computed_trees", &self.trees.len()) | |
| 54 | + .field("computed_blobs", &self.blobs.len()) | |
| 55 | + .field("computed_commits", &self.commits.len()) | |
| 56 | + .finish_non_exhaustive() | |
| 57 | + } | |
| 58 | +} | |
| 59 | + | |
| 60 | +impl<'a, O: Objects> Exporter<'a, O> { | |
| 61 | + /// An exporter reading braid objects from `objects`, with what `map` | |
| 62 | + /// knows about imported git objects. | |
| 63 | + pub fn new(objects: &'a O, map: &'a GitMap) -> Self { | |
| 64 | + Self { | |
| 65 | + objects, | |
| 66 | + map, | |
| 67 | + trees: HashMap::new(), | |
| 68 | + tree_sources: HashMap::new(), | |
| 69 | + blobs: HashMap::new(), | |
| 70 | + blob_sources: HashMap::new(), | |
| 71 | + commits: HashMap::new(), | |
| 72 | + commit_sources: HashMap::new(), | |
| 73 | + } | |
| 74 | + } | |
| 75 | + | |
| 76 | + /// The git commit of a changeset: its id and its bytes. | |
| 77 | + pub fn commit(&mut self, changeset: &ObjectId) -> Result<(GitOid, Vec<u8>), Error> { | |
| 78 | + let decoded = fetch::changeset(self.objects, changeset)?; | |
| 79 | + self.commit_of(changeset, &decoded) | |
| 80 | + } | |
| 81 | + | |
| 82 | + /// The git id of a changeset's commit. Ancestors that were not imported | |
| 83 | + /// from git are exported first, parents before children. | |
| 84 | + pub fn commit_id(&mut self, changeset: &ObjectId) -> Result<GitOid, Error> { | |
| 85 | + if let Some(oid) = self.known_commit(changeset) { | |
| 86 | + return Ok(oid); | |
| 87 | + } | |
| 88 | + let mut stack = vec![(*changeset, fetch::changeset(self.objects, changeset)?)]; | |
| 89 | + while let Some((id, decoded)) = stack.pop() { | |
| 90 | + if self.known_commit(&id).is_some() { | |
| 91 | + continue; | |
| 92 | + } | |
| 93 | + // A commit from git names its parents itself; a generated one | |
| 94 | + // needs theirs first. | |
| 95 | + let waiting = match decoded.git_origin { | |
| 96 | + Some(_) => None, | |
| 97 | + None => decoded | |
| 98 | + .parents | |
| 99 | + .iter() | |
| 100 | + .find(|parent| self.known_commit(parent).is_none()) | |
| 101 | + .copied(), | |
| 102 | + }; | |
| 103 | + match waiting { | |
| 104 | + Some(parent) => { | |
| 105 | + let parent_changeset = fetch::changeset(self.objects, &parent)?; | |
| 106 | + stack.push((id, decoded)); | |
| 107 | + stack.push((parent, parent_changeset)); | |
| 108 | + } | |
| 109 | + None => { | |
| 110 | + self.commit_of(&id, &decoded)?; | |
| 111 | + } | |
| 112 | + } | |
| 113 | + } | |
| 114 | + self.known_commit(changeset) | |
| 115 | + .ok_or_else(|| Error::NotMapped { | |
| 116 | + what: "changeset", | |
| 117 | + id: changeset.to_hex(), | |
| 118 | + }) | |
| 119 | + } | |
| 120 | + | |
| 121 | + fn known_commit(&self, changeset: &ObjectId) -> Option<GitOid> { | |
| 122 | + self.map | |
| 123 | + .commit(changeset) | |
| 124 | + .or_else(|| self.commits.get(changeset).copied()) | |
| 125 | + } | |
| 126 | + | |
| 127 | + fn commit_of( | |
| 128 | + &mut self, | |
| 129 | + id: &ObjectId, | |
| 130 | + changeset: &Changeset, | |
| 131 | + ) -> Result<(GitOid, Vec<u8>), Error> { | |
| 132 | + let (oid, bytes) = match &changeset.git_origin { | |
| 133 | + Some(origin) => self.origin_commit(id, changeset, origin)?, | |
| 134 | + None => { | |
| 135 | + let mut parents = Vec::with_capacity(changeset.parents.len()); | |
| 136 | + for parent in &changeset.parents { | |
| 137 | + parents.push(self.commit_id(parent)?); | |
| 138 | + } | |
| 139 | + let tree = self.tree_id(&changeset.root)?; | |
| 140 | + let bytes = raw::encode_commit( | |
| 141 | + tree, | |
| 142 | + &parents, | |
| 143 | + &changeset.author, | |
| 144 | + &changeset.committer, | |
| 145 | + &changeset.extras, | |
| 146 | + &changeset.message, | |
| 147 | + ) | |
| 148 | + .map_err(|detail| Error::Unrepresentable { | |
| 149 | + changeset: *id, | |
| 150 | + detail, | |
| 151 | + })?; | |
| 152 | + (GitOid::for_object(GitKind::Commit, &bytes)?, bytes) | |
| 153 | + } | |
| 154 | + }; | |
| 155 | + self.commits.insert(*id, oid); | |
| 156 | + self.commit_sources.insert(oid, *id); | |
| 157 | + Ok((oid, bytes)) | |
| 158 | + } | |
| 159 | + | |
| 160 | + /// The original commit of a changeset imported from git, after checking | |
| 161 | + /// that what it names agrees with the changeset and the map. | |
| 162 | + fn origin_commit( | |
| 163 | + &self, | |
| 164 | + id: &ObjectId, | |
| 165 | + changeset: &Changeset, | |
| 166 | + origin: &ObjectId, | |
| 167 | + ) -> Result<(GitOid, Vec<u8>), Error> { | |
| 168 | + let mismatch = |detail: String| Error::OriginMismatch { | |
| 169 | + changeset: *id, | |
| 170 | + detail, | |
| 171 | + }; | |
| 172 | + let bytes = fetch::get(self.objects, origin, Kind::Blob)?; | |
| 173 | + let fields = raw::parse_commit(&bytes) | |
| 174 | + .map_err(|reason| mismatch(format!("its git origin is not a commit: {reason}")))?; | |
| 175 | + match self.map.tree(&fields.tree) { | |
| 176 | + Some(root) if root == changeset.root => {} | |
| 177 | + Some(root) => { | |
| 178 | + return Err(mismatch(format!( | |
| 179 | + "its commit names tree {}, which the map links to {root}, not to its root {}", | |
| 180 | + fields.tree, changeset.root | |
| 181 | + ))); | |
| 182 | + } | |
| 183 | + None => { | |
| 184 | + return Err(mismatch(format!( | |
| 185 | + "its commit names tree {}, which the map does not know", | |
| 186 | + fields.tree | |
| 187 | + ))); | |
| 188 | + } | |
| 189 | + } | |
| 190 | + if fields.parents.len() != changeset.parents.len() { | |
| 191 | + return Err(mismatch(format!( | |
| 192 | + "its commit names {} parents, the changeset has {}", | |
| 193 | + fields.parents.len(), | |
| 194 | + changeset.parents.len() | |
| 195 | + ))); | |
| 196 | + } | |
| 197 | + for (index, (git, braid)) in fields.parents.iter().zip(&changeset.parents).enumerate() { | |
| 198 | + if self.map.changeset(git) != Some(*braid) { | |
| 199 | + return Err(mismatch(format!( | |
| 200 | + "parent {index} of its commit is {git}, which the map does not link to {braid}" | |
| 201 | + ))); | |
| 202 | + } | |
| 203 | + } | |
| 204 | + let oid = GitOid::for_object(GitKind::Commit, &bytes)?; | |
| 205 | + if let Some(known) = self.map.commit(id) | |
| 206 | + && known != oid | |
| 207 | + { | |
| 208 | + return Err(mismatch(format!( | |
| 209 | + "the map links it to commit {known}, but its git origin is commit {oid}" | |
| 210 | + ))); | |
| 211 | + } | |
| 212 | + Ok((oid, bytes)) | |
| 213 | + } | |
| 214 | + | |
| 215 | + /// The canonical git tree of a braid tree: its id and its bytes. | |
| 216 | + pub fn tree(&mut self, tree: &ObjectId) -> Result<(GitOid, Vec<u8>), Error> { | |
| 217 | + let entries = fetch::tree_entries(self.objects, *tree)?; | |
| 218 | + let bytes = self.encode_entries(tree, &entries)?; | |
| 219 | + let oid = GitOid::for_object(GitKind::Tree, &bytes)?; | |
| 220 | + match self.known_tree(tree) { | |
| 221 | + Some(known) if known != oid => Err(Error::BadBraidObject { | |
| 222 | + id: *tree, | |
| 223 | + detail: format!("the map links it to git tree {known}, but it exports as {oid}"), | |
| 224 | + }), | |
| 225 | + Some(_) => Ok((oid, bytes)), | |
| 226 | + None => { | |
| 227 | + self.trees.insert(*tree, oid); | |
| 228 | + self.tree_sources.insert(oid, *tree); | |
| 229 | + Ok((oid, bytes)) | |
| 230 | + } | |
| 231 | + } | |
| 232 | + } | |
| 233 | + | |
| 234 | + /// The id of the canonical git tree of a braid tree. | |
| 235 | + pub fn tree_id(&mut self, tree: &ObjectId) -> Result<GitOid, Error> { | |
| 236 | + if let Some(oid) = self.known_tree(tree) { | |
| 237 | + return Ok(oid); | |
| 238 | + } | |
| 239 | + // Directories waiting for their subdirectories: id, entries, and the | |
| 240 | + // index of the next entry to look at. | |
| 241 | + let mut stack = vec![(*tree, fetch::tree_entries(self.objects, *tree)?, 0usize)]; | |
| 242 | + while let Some((_, entries, next)) = stack.last_mut() { | |
| 243 | + let mut child = None; | |
| 244 | + while child.is_none() && *next < entries.len() { | |
| 245 | + if let EntryKind::Tree { tree } = &entries[*next].kind | |
| 246 | + && self.known_tree(tree).is_none() | |
| 247 | + { | |
| 248 | + child = Some(*tree); | |
| 249 | + } | |
| 250 | + *next += 1; | |
| 251 | + } | |
| 252 | + if let Some(child) = child { | |
| 253 | + let entries = fetch::tree_entries(self.objects, child)?; | |
| 254 | + stack.push((child, entries, 0)); | |
| 255 | + continue; | |
| 256 | + } | |
| 257 | + let (id, entries, _) = stack.pop().expect("the loop runs on a non-empty stack"); | |
| 258 | + if self.known_tree(&id).is_some() { | |
| 259 | + continue; | |
| 260 | + } | |
| 261 | + let bytes = self.encode_entries(&id, &entries)?; | |
| 262 | + let oid = GitOid::for_object(GitKind::Tree, &bytes)?; | |
| 263 | + self.trees.insert(id, oid); | |
| 264 | + self.tree_sources.insert(oid, id); | |
| 265 | + } | |
| 266 | + self.known_tree(tree).ok_or_else(|| Error::NotMapped { | |
| 267 | + what: "tree", | |
| 268 | + id: tree.to_hex(), | |
| 269 | + }) | |
| 270 | + } | |
| 271 | + | |
| 272 | + fn known_tree(&self, tree: &ObjectId) -> Option<GitOid> { | |
| 273 | + self.map | |
| 274 | + .git_tree(tree) | |
| 275 | + .or_else(|| self.trees.get(tree).copied()) | |
| 276 | + } | |
| 277 | + | |
| 278 | + /// The canonical bytes of a directory. Its subdirectories normally have | |
| 279 | + /// git ids already, so this does not recurse far. | |
| 280 | + fn encode_entries(&mut self, tree: &ObjectId, entries: &[Entry]) -> Result<Vec<u8>, Error> { | |
| 281 | + let mut items = Vec::with_capacity(entries.len()); | |
| 282 | + for entry in entries { | |
| 283 | + let (kind, oid) = match &entry.kind { | |
| 284 | + EntryKind::File { blob, .. } => (EntryType::File, self.blob_id(blob)?), | |
| 285 | + EntryKind::Executable { blob, .. } => (EntryType::Executable, self.blob_id(blob)?), | |
| 286 | + EntryKind::Symlink { blob, .. } => (EntryType::Symlink, self.blob_id(blob)?), | |
| 287 | + EntryKind::Tree { tree } => (EntryType::Tree, self.tree_id(tree)?), | |
| 288 | + EntryKind::Gitlink { | |
| 289 | + commit: GitId::Sha1(bytes), | |
| 290 | + } => (EntryType::Gitlink, GitOid::from_bytes(*bytes)), | |
| 291 | + EntryKind::Gitlink { | |
| 292 | + commit: GitId::Sha256(_), | |
| 293 | + } => { | |
| 294 | + return Err(Error::BadBraidObject { | |
| 295 | + id: *tree, | |
| 296 | + detail: "a SHA-256 submodule cannot be written in a SHA-1 tree".into(), | |
| 297 | + }); | |
| 298 | + } | |
| 299 | + }; | |
| 300 | + items.push(TreeItem { | |
| 301 | + kind, | |
| 302 | + name: &entry.name, | |
| 303 | + oid, | |
| 304 | + }); | |
| 305 | + } | |
| 306 | + Ok(raw::encode_tree(&mut items)) | |
| 307 | + } | |
| 308 | + | |
| 309 | + /// The git blob of a braid blob: its id and its content. | |
| 310 | + pub fn blob(&mut self, blob: &ObjectId) -> Result<(GitOid, Vec<u8>), Error> { | |
| 311 | + let bytes = fetch::get(self.objects, blob, Kind::Blob)?; | |
| 312 | + let oid = GitOid::for_object(GitKind::Blob, &bytes)?; | |
| 313 | + if let Some(known) = self.map.git_blob(blob) | |
| 314 | + && known != oid | |
| 315 | + { | |
| 316 | + return Err(Error::BadBraidObject { | |
| 317 | + id: *blob, | |
| 318 | + detail: format!("the map links it to git blob {known}, but its content is {oid}"), | |
| 319 | + }); | |
| 320 | + } | |
| 321 | + self.blobs.insert(*blob, oid); | |
| 322 | + self.blob_sources.insert(oid, *blob); | |
| 323 | + Ok((oid, bytes)) | |
| 324 | + } | |
| 325 | + | |
| 326 | + /// The id of the git blob of a braid blob. | |
| 327 | + pub fn blob_id(&mut self, blob: &ObjectId) -> Result<GitOid, Error> { | |
| 328 | + match self | |
| 329 | + .map | |
| 330 | + .git_blob(blob) | |
| 331 | + .or_else(|| self.blobs.get(blob).copied()) | |
| 332 | + { | |
| 333 | + Some(oid) => Ok(oid), | |
| 334 | + None => Ok(self.blob(blob)?.0), | |
| 335 | + } | |
| 336 | + } | |
| 337 | + | |
| 338 | + /// Any git object the map or this exporter knows, by its git id: a commit, | |
| 339 | + /// a tree (raw or regenerated), a blob or an annotated tag. The bytes are | |
| 340 | + /// checked to hash to `oid`. | |
| 341 | + pub fn object(&mut self, oid: &GitOid) -> Result<(GitKind, Vec<u8>), Error> { | |
| 342 | + let (kind, bytes) = self.object_bytes(oid)?; | |
| 343 | + let found = GitOid::for_object(kind, &bytes)?; | |
| 344 | + if found != *oid { | |
| 345 | + return Err(Error::Verification { | |
| 346 | + oid: *oid, | |
| 347 | + kind, | |
| 348 | + detail: format!("exported as {found}"), | |
| 349 | + }); | |
| 350 | + } | |
| 351 | + Ok((kind, bytes)) | |
| 352 | + } | |
| 353 | + | |
| 354 | + fn object_bytes(&mut self, oid: &GitOid) -> Result<(GitKind, Vec<u8>), Error> { | |
| 355 | + if let Some(changeset) = self | |
| 356 | + .map | |
| 357 | + .changeset(oid) | |
| 358 | + .or_else(|| self.commit_sources.get(oid).copied()) | |
| 359 | + { | |
| 360 | + return Ok((GitKind::Commit, self.commit(&changeset)?.1)); | |
| 361 | + } | |
| 362 | + if let Some(raw) = self.map.raw_tree(oid) { | |
| 363 | + return Ok((GitKind::Tree, fetch::get(self.objects, &raw, Kind::Blob)?)); | |
| 364 | + } | |
| 365 | + if let Some(tree) = self | |
| 366 | + .map | |
| 367 | + .tree(oid) | |
| 368 | + .or_else(|| self.tree_sources.get(oid).copied()) | |
| 369 | + { | |
| 370 | + return Ok((GitKind::Tree, self.tree(&tree)?.1)); | |
| 371 | + } | |
| 372 | + if let Some(blob) = self | |
| 373 | + .map | |
| 374 | + .blob(oid) | |
| 375 | + .map(|(id, _)| id) | |
| 376 | + .or_else(|| self.blob_sources.get(oid).copied()) | |
| 377 | + { | |
| 378 | + return Ok((GitKind::Blob, fetch::get(self.objects, &blob, Kind::Blob)?)); | |
| 379 | + } | |
| 380 | + if let Some(entry) = self.map.tag(oid) { | |
| 381 | + let bytes = fetch::get(self.objects, &entry.raw, Kind::Blob)?; | |
| 382 | + if raw::parse_tag(&bytes).ok() != Some(entry.target) { | |
| 383 | + return Err(Error::Verification { | |
| 384 | + oid: *oid, | |
| 385 | + kind: GitKind::Tag, | |
| 386 | + detail: format!("its raw bytes do not point to {}", entry.target), | |
| 387 | + }); | |
| 388 | + } | |
| 389 | + return Ok((GitKind::Tag, bytes)); | |
| 390 | + } | |
| 391 | + Err(Error::NotMapped { | |
| 392 | + what: "git object", | |
| 393 | + id: oid.to_hex(), | |
| 394 | + }) | |
| 395 | + } | |
| 396 | +} | |
| 397 | + | |
| 398 | +/// The git commit of a changeset: its id and its bytes. See [`Exporter`]. | |
| 399 | +pub fn export_commit<O: Objects>( | |
| 400 | + objects: &O, | |
| 401 | + map: &GitMap, | |
| 402 | + changeset: &ObjectId, | |
| 403 | +) -> Result<(GitOid, Vec<u8>), Error> { | |
| 404 | + Exporter::new(objects, map).commit(changeset) | |
| 405 | +} | |
| 406 | + | |
| 407 | +/// The canonical git tree of a braid tree: its id and its bytes. | |
| 408 | +pub fn export_tree<O: Objects>( | |
| 409 | + objects: &O, | |
| 410 | + map: &GitMap, | |
| 411 | + tree: &ObjectId, | |
| 412 | +) -> Result<(GitOid, Vec<u8>), Error> { | |
| 413 | + Exporter::new(objects, map).tree(tree) | |
| 414 | +} | |
| 415 | + | |
| 416 | +/// The git blob of a braid blob: its id and its content. | |
| 417 | +pub fn export_blob<O: Objects>( | |
| 418 | + objects: &O, | |
| 419 | + map: &GitMap, | |
| 420 | + blob: &ObjectId, | |
| 421 | +) -> Result<(GitOid, Vec<u8>), Error> { | |
| 422 | + Exporter::new(objects, map).blob(blob) | |
| 423 | +} | |
| 424 | + | |
| 425 | +/// An imported git object, by its git id: its kind and its exact bytes. | |
| 426 | +pub fn export_object<O: Objects>( | |
| 427 | + objects: &O, | |
| 428 | + map: &GitMap, | |
| 429 | + oid: &GitOid, | |
| 430 | +) -> Result<(GitKind, Vec<u8>), Error> { | |
| 431 | + Exporter::new(objects, map).object(oid) | |
| 432 | +} | |
| 433 | + | |
| 434 | +/// What a ref written by [`write_to_repo`] points to. | |
| 435 | +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | |
| 436 | +pub enum RefTarget { | |
| 437 | + /// A changeset, written as a commit. | |
| 438 | + Changeset(ObjectId), | |
| 439 | + /// A git object the map knows: a commit, an annotated tag, a tree or a | |
| 440 | + /// blob. | |
| 441 | + Git(GitOid), | |
| 442 | +} | |
| 443 | + | |
| 444 | +/// A ref to set in [`write_to_repo`], which overwrites it without a lease. | |
| 445 | +#[derive(Clone, Debug, PartialEq, Eq, Hash)] | |
| 446 | +pub struct RefUpdate { | |
| 447 | + /// The full ref name, such as `refs/heads/main`. | |
| 448 | + pub name: Vec<u8>, | |
| 449 | + /// What it points to. | |
| 450 | + pub target: RefTarget, | |
| 451 | +} | |
| 452 | + | |
| 453 | +/// What [`write_to_repo`] did. | |
| 454 | +#[derive(Clone, Debug, Default, PartialEq, Eq)] | |
| 455 | +pub struct WriteReport { | |
| 456 | + /// Commits written. | |
| 457 | + pub commits: usize, | |
| 458 | + /// Trees written. | |
| 459 | + pub trees: usize, | |
| 460 | + /// Blobs written. | |
| 461 | + pub blobs: usize, | |
| 462 | + /// Annotated tags written. | |
| 463 | + pub tags: usize, | |
| 464 | + /// Each ref and the object it points to now. | |
| 465 | + pub refs: Vec<(Vec<u8>, GitOid)>, | |
| 466 | +} | |
| 467 | + | |
| 468 | +/// Writes into the git repository at `git_repo` every object the refs need, | |
| 469 | +/// then points the refs at them in one transaction. | |
| 470 | +/// | |
| 471 | +/// Refs are overwritten, whatever they pointed to before: there is no lease | |
| 472 | +/// and no fast-forward check here. That is meant for local exports; updating | |
| 473 | +/// a shared repository with a lease, as a fast-forward, is the job of | |
| 474 | +/// `git sync`, which comes later. | |
| 475 | +/// | |
| 476 | +/// Objects the repository already has are not written again, and neither is | |
| 477 | +/// anything they reach. Objects are written after everything they reach, so an | |
| 478 | +/// interrupted write never leaves an object whose closure is missing. | |
| 479 | +pub fn write_to_repo<O: Objects>( | |
| 480 | + git_repo: &Path, | |
| 481 | + objects: &O, | |
| 482 | + map: &GitMap, | |
| 483 | + refs: &[RefUpdate], | |
| 484 | +) -> Result<WriteReport, Error> { | |
| 485 | + let mut repo = GitRepo::open(git_repo)?; | |
| 486 | + let mut writer = Writer { | |
| 487 | + exporter: Exporter::new(objects, map), | |
| 488 | + repo: &repo, | |
| 489 | + written: HashSet::new(), | |
| 490 | + report: WriteReport::default(), | |
| 491 | + }; | |
| 492 | + let mut targets = Vec::with_capacity(refs.len()); | |
| 493 | + for update in refs { | |
| 494 | + let oid = match update.target { | |
| 495 | + RefTarget::Changeset(changeset) => writer.exporter.commit_id(&changeset)?, | |
| 496 | + RefTarget::Git(oid) => oid, | |
| 497 | + }; | |
| 498 | + writer.write_closure(oid)?; | |
| 499 | + targets.push((update.name.clone(), oid)); | |
| 500 | + } | |
| 501 | + let mut report = writer.report; | |
| 502 | + repo.set_refs(&targets, "braid: export")?; | |
| 503 | + report.refs = targets; | |
| 504 | + Ok(report) | |
| 505 | +} | |
| 506 | + | |
| 507 | +struct Writer<'r, 'a, O: Objects> { | |
| 508 | + exporter: Exporter<'a, O>, | |
| 509 | + repo: &'r GitRepo, | |
| 510 | + written: HashSet<GitOid>, | |
| 511 | + report: WriteReport, | |
| 512 | +} | |
| 513 | + | |
| 514 | +/// An object waiting for what it reaches to be written. | |
| 515 | +struct Pending { | |
| 516 | + oid: GitOid, | |
| 517 | + kind: GitKind, | |
| 518 | + bytes: Vec<u8>, | |
| 519 | + children: Vec<GitOid>, | |
| 520 | + next: usize, | |
| 521 | +} | |
| 522 | + | |
| 523 | +impl<O: Objects> Writer<'_, '_, O> { | |
| 524 | + fn present(&self, oid: &GitOid) -> bool { | |
| 525 | + self.written.contains(oid) || self.repo.contains(oid) | |
| 526 | + } | |
| 527 | + | |
| 528 | + fn pending(&mut self, oid: GitOid) -> Result<Pending, Error> { | |
| 529 | + let (kind, bytes) = self.exporter.object(&oid)?; | |
| 530 | + let children = reached(oid, kind, &bytes)?; | |
| 531 | + Ok(Pending { | |
| 532 | + oid, | |
| 533 | + kind, | |
| 534 | + bytes, | |
| 535 | + children, | |
| 536 | + next: 0, | |
| 537 | + }) | |
| 538 | + } | |
| 539 | + | |
| 540 | + fn write_closure(&mut self, root: GitOid) -> Result<(), Error> { | |
| 541 | + if self.present(&root) { | |
| 542 | + return Ok(()); | |
| 543 | + } | |
| 544 | + let mut stack = vec![self.pending(root)?]; | |
| 545 | + while let Some(top) = stack.last_mut() { | |
| 546 | + if top.next < top.children.len() { | |
| 547 | + let child = top.children[top.next]; | |
| 548 | + top.next += 1; | |
| 549 | + if !self.present(&child) { | |
| 550 | + let pending = self.pending(child)?; | |
| 551 | + stack.push(pending); | |
| 552 | + } | |
| 553 | + continue; | |
| 554 | + } | |
| 555 | + let done = stack.pop().expect("the loop runs on a non-empty stack"); | |
| 556 | + if self.present(&done.oid) { | |
| 557 | + continue; | |
| 558 | + } | |
| 559 | + let stored = self.repo.write(done.kind, &done.bytes)?; | |
| 560 | + if stored != done.oid { | |
| 561 | + return Err(Error::Verification { | |
| 562 | + oid: done.oid, | |
| 563 | + kind: done.kind, | |
| 564 | + detail: format!("the repository stored it as {stored}"), | |
| 565 | + }); | |
| 566 | + } | |
| 567 | + self.written.insert(done.oid); | |
| 568 | + match done.kind { | |
| 569 | + GitKind::Commit => self.report.commits += 1, | |
| 570 | + GitKind::Tree => self.report.trees += 1, | |
| 571 | + GitKind::Blob => self.report.blobs += 1, | |
| 572 | + GitKind::Tag => self.report.tags += 1, | |
| 573 | + } | |
| 574 | + } | |
| 575 | + Ok(()) | |
| 576 | + } | |
| 577 | +} | |
| 578 | + | |
| 579 | +/// The objects a git object names: a commit's tree and parents, a tree's | |
| 580 | +/// entries except submodules, a tag's target. | |
| 581 | +pub(crate) fn reached(oid: GitOid, kind: GitKind, bytes: &[u8]) -> Result<Vec<GitOid>, Error> { | |
| 582 | + let malformed = |reason| Error::Malformed { oid, kind, reason }; | |
| 583 | + Ok(match kind { | |
| 584 | + GitKind::Commit => { | |
| 585 | + let fields = raw::parse_commit(bytes).map_err(malformed)?; | |
| 586 | + let mut out = Vec::with_capacity(1 + fields.parents.len()); | |
| 587 | + out.push(fields.tree); | |
| 588 | + out.extend(fields.parents); | |
| 589 | + out | |
| 590 | + } | |
| 591 | + GitKind::Tree => { | |
| 592 | + let mut out = Vec::new(); | |
| 593 | + for entry in raw::parse_tree(bytes).map_err(malformed)? { | |
| 594 | + match EntryType::from_mode(entry.mode) { | |
| 595 | + Some(EntryType::Gitlink) => {} | |
| 596 | + Some(_) => out.push(entry.oid), | |
| 597 | + None => return Err(malformed("an entry has an unsupported mode")), | |
| 598 | + } | |
| 599 | + } | |
| 600 | + out | |
| 601 | + } | |
| 602 | + GitKind::Tag => vec![raw::parse_tag(bytes).map_err(malformed)?], | |
| 603 | + GitKind::Blob => Vec::new(), | |
| 604 | + }) | |
| 605 | +} |
added crates/git/src/fetch.rs +64 −0
| @@ -0,0 +1,64 @@ | ||
| 1 | +// SPDX-License-Identifier: Apache-2.0 | |
| 2 | +// Copyright (c) 2026 UtopiaIA | |
| 3 | + | |
| 4 | +//! Reading and writing braid objects, with kinds checked and errors converted. | |
| 5 | + | |
| 6 | +use braid_format::{Changeset, Entry, Kind, ObjectId, Objects, read_directory}; | |
| 7 | + | |
| 8 | +use crate::error::Error; | |
| 9 | + | |
| 10 | +/// Fetches an object that must be of `kind`. | |
| 11 | +pub(crate) fn get<O: Objects>(objects: &O, id: &ObjectId, kind: Kind) -> Result<Vec<u8>, Error> { | |
| 12 | + match objects.get(id).map_err(Error::objects)? { | |
| 13 | + Some((found, payload)) if found == kind => Ok(payload), | |
| 14 | + Some((found, _)) => Err(Error::BadBraidObject { | |
| 15 | + id: *id, | |
| 16 | + detail: format!("is a {found}, expected a {kind}"), | |
| 17 | + }), | |
| 18 | + None => Err(Error::MissingBraidObject { | |
| 19 | + id: *id, | |
| 20 | + expected: kind, | |
| 21 | + }), | |
| 22 | + } | |
| 23 | +} | |
| 24 | + | |
| 25 | +/// Stores an object and checks the id the store gives back. | |
| 26 | +pub(crate) fn put<O: Objects>(objects: &O, kind: Kind, payload: &[u8]) -> Result<ObjectId, Error> { | |
| 27 | + let id = objects.put(kind, payload).map_err(Error::objects)?; | |
| 28 | + let expected = ObjectId::hash(kind, payload); | |
| 29 | + if id != expected { | |
| 30 | + return Err(Error::BadBraidObject { | |
| 31 | + id, | |
| 32 | + detail: format!("the store gave this id to the {kind} {expected}"), | |
| 33 | + }); | |
| 34 | + } | |
| 35 | + Ok(id) | |
| 36 | +} | |
| 37 | + | |
| 38 | +/// Every entry of a directory, whether it is one flat node or split. | |
| 39 | +pub(crate) fn tree_entries<O: Objects>(objects: &O, root: ObjectId) -> Result<Vec<Entry>, Error> { | |
| 40 | + let mut failure = None; | |
| 41 | + let entries = read_directory(root, |id| match get(objects, id, Kind::Tree) { | |
| 42 | + Ok(bytes) => Some(bytes), | |
| 43 | + Err(err) => { | |
| 44 | + failure.get_or_insert(err); | |
| 45 | + None | |
| 46 | + } | |
| 47 | + }); | |
| 48 | + if let Some(err) = failure { | |
| 49 | + return Err(err); | |
| 50 | + } | |
| 51 | + entries.map_err(|err| Error::BadBraidObject { | |
| 52 | + id: root, | |
| 53 | + detail: err.to_string(), | |
| 54 | + }) | |
| 55 | +} | |
| 56 | + | |
| 57 | +/// A decoded changeset. | |
| 58 | +pub(crate) fn changeset<O: Objects>(objects: &O, id: &ObjectId) -> Result<Changeset, Error> { | |
| 59 | + let bytes = get(objects, id, Kind::Changeset)?; | |
| 60 | + Changeset::decode(&bytes).map_err(|err| Error::BadBraidObject { | |
| 61 | + id: *id, | |
| 62 | + detail: err.to_string(), | |
| 63 | + }) | |
| 64 | +} |
added crates/git/src/import.rs +616 −0
| @@ -0,0 +1,616 @@ | ||
| 1 | +// SPDX-License-Identifier: Apache-2.0 | |
| 2 | +// Copyright (c) 2026 UtopiaIA | |
| 3 | + | |
| 4 | +//! Import: git history into braid objects. | |
| 5 | + | |
| 6 | +use std::collections::{HashMap, HashSet}; | |
| 7 | +use std::path::Path; | |
| 8 | + | |
| 9 | +use braid_format::name::forbidden_as_symlink; | |
| 10 | +use braid_format::tree::validate_entry; | |
| 11 | +use braid_format::{ | |
| 12 | + ChangesetParts, Entry, EntryKind, GitId, Kind, ObjectId, Objects, Signature, build_directory, | |
| 13 | + validate_name, | |
| 14 | +}; | |
| 15 | + | |
| 16 | +use crate::diff; | |
| 17 | +use crate::error::Error; | |
| 18 | +use crate::export::Exporter; | |
| 19 | +use crate::fetch; | |
| 20 | +use crate::map::{GitMap, TagEntry}; | |
| 21 | +use crate::oid::{GitKind, GitOid}; | |
| 22 | +use crate::raw::{self, EntryType}; | |
| 23 | +use crate::repo::GitRepo; | |
| 24 | + | |
| 25 | +/// What to import. | |
| 26 | +#[derive(Clone, Debug, Default, PartialEq, Eq)] | |
| 27 | +pub struct ImportOptions { | |
| 28 | + /// The refs to import, by full name such as `refs/heads/main` (a short | |
| 29 | + /// name is looked up the way git does). Empty means every branch and | |
| 30 | + /// every tag. | |
| 31 | + pub refs: Vec<Vec<u8>>, | |
| 32 | +} | |
| 33 | + | |
| 34 | +/// A ref that was imported. | |
| 35 | +#[derive(Clone, Debug, PartialEq, Eq, Hash)] | |
| 36 | +pub struct ImportedRef { | |
| 37 | + /// Its full name. | |
| 38 | + pub name: Vec<u8>, | |
| 39 | + /// The git object it points to. | |
| 40 | + pub oid: GitOid, | |
| 41 | + /// The kind of that object. | |
| 42 | + pub kind: GitKind, | |
| 43 | + /// The braid object for it: the changeset of a commit, the blob with the | |
| 44 | + /// raw bytes of an annotated tag, the braid tree of a tree, the braid blob | |
| 45 | + /// of a blob. | |
| 46 | + pub braid: ObjectId, | |
| 47 | +} | |
| 48 | + | |
| 49 | +/// What an import did. Counts are of objects new to the map. | |
| 50 | +#[derive(Clone, Debug, Default, PartialEq, Eq)] | |
| 51 | +pub struct ImportReport { | |
| 52 | + /// Commits imported. | |
| 53 | + pub commits: usize, | |
| 54 | + /// Git trees converted. | |
| 55 | + pub trees: usize, | |
| 56 | + /// Of those trees, the ones kept as raw bytes because they are not | |
| 57 | + /// canonical. | |
| 58 | + pub raw_trees: usize, | |
| 59 | + /// Blobs imported. | |
| 60 | + pub blobs: usize, | |
| 61 | + /// Annotated tags imported. | |
| 62 | + pub tags: usize, | |
| 63 | + /// Every ref that was asked for, sorted by name, new or not. | |
| 64 | + pub refs: Vec<ImportedRef>, | |
| 65 | +} | |
| 66 | + | |
| 67 | +/// Imports the history of the git repository at `git_repo` into `objects`, | |
| 68 | +/// recording every mapping in `map`. | |
| 69 | +/// | |
| 70 | +/// Every commit reachable from the refs is imported, parents before | |
| 71 | +/// children; commits already in `map` are skipped together with their | |
| 72 | +/// history, so an import can be repeated to bring in new commits, or resumed | |
| 73 | +/// after a failure. For each commit: | |
| 74 | +/// | |
| 75 | +/// - its tree is converted, each git tree once: blobs keep their exact bytes, | |
| 76 | +/// modes become file, executable, symlink, directory or submodule entries, | |
| 77 | +/// and a git tree that the export cannot regenerate exactly keeps its raw | |
| 78 | +/// bytes. Braid trees never hold an empty subdirectory, so empty | |
| 79 | +/// directories, and directories holding only empty ones, are left out; a | |
| 80 | +/// git tree that loses entries this way keeps its raw bytes too; | |
| 81 | +/// - its raw bytes are stored and become the changeset's git origin, with the | |
| 82 | +/// change list against its first parent, the parents, and the author, | |
| 83 | +/// committer and message read from it; | |
| 84 | +/// - it is exported again from what was stored, and the import stops with an | |
| 85 | +/// error naming the commit unless the id is the same. | |
| 86 | +/// | |
| 87 | +/// Annotated tags keep their raw bytes too, and are checked the same way. | |
| 88 | +/// | |
| 89 | +/// Shallow clones and SHA-256 repositories are refused. Replacement objects | |
| 90 | +/// and grafts are ignored, and objects are read raw: no filters, no | |
| 91 | +/// line-ending conversion, no LFS. A tree holding a name that braid refuses, | |
| 92 | +/// such as an alias of `.git`, stops the import with an error naming the | |
| 93 | +/// commit and the path. | |
| 94 | +pub fn import<O: Objects>( | |
| 95 | + git_repo: &Path, | |
| 96 | + objects: &O, | |
| 97 | + map: &mut GitMap, | |
| 98 | + options: &ImportOptions, | |
| 99 | +) -> Result<ImportReport, Error> { | |
| 100 | + let repo = GitRepo::open(git_repo)?; | |
| 101 | + if repo.is_shallow()? { | |
| 102 | + return Err(Error::Shallow); | |
| 103 | + } | |
| 104 | + let refs = repo.refs(&options.refs)?; | |
| 105 | + let mut importer = Importer { | |
| 106 | + repo: &repo, | |
| 107 | + objects, | |
| 108 | + map, | |
| 109 | + report: ImportReport::default(), | |
| 110 | + roots: HashMap::new(), | |
| 111 | + empty_tree: build_directory(Vec::new()) | |
| 112 | + .expect("the empty directory is valid") | |
| 113 | + .root(), | |
| 114 | + }; | |
| 115 | + | |
| 116 | + // What the refs point to: commits to walk from, trees and blobs that tags | |
| 117 | + // point to directly, and annotated tags, each after its target. | |
| 118 | + let mut plan = Plan::default(); | |
| 119 | + for (_, oid) in &refs { | |
| 120 | + importer.plan_ref(*oid, &mut plan)?; | |
| 121 | + } | |
| 122 | + for commit in importer.commit_order(&plan.tips)? { | |
| 123 | + importer.import_commit(commit)?; | |
| 124 | + } | |
| 125 | + for (oid, kind) in &plan.loose { | |
| 126 | + match kind { | |
| 127 | + GitKind::Tree => { | |
| 128 | + importer.convert_tree(*oid, *oid)?; | |
| 129 | + } | |
| 130 | + _ => { | |
| 131 | + importer.import_blob(*oid)?; | |
| 132 | + } | |
| 133 | + } | |
| 134 | + } | |
| 135 | + for tag in &plan.tags { | |
| 136 | + importer.import_tag(*tag)?; | |
| 137 | + } | |
| 138 | + | |
| 139 | + for (name, oid) in refs { | |
| 140 | + let kind = repo.kind(&oid)?; | |
| 141 | + let map = &mut *importer.map; | |
| 142 | + let braid = match kind { | |
| 143 | + GitKind::Commit => map.changeset(&oid), | |
| 144 | + GitKind::Tag => map.tag(&oid).map(|entry| entry.raw), | |
| 145 | + GitKind::Tree => map.tree(&oid), | |
| 146 | + GitKind::Blob => map.blob(&oid).map(|(id, _)| id), | |
| 147 | + } | |
| 148 | + .ok_or_else(|| Error::NotMapped { | |
| 149 | + what: kind.name(), | |
| 150 | + id: oid.to_hex(), | |
| 151 | + })?; | |
| 152 | + if name.starts_with(b"refs/tags/") { | |
| 153 | + match kind { | |
| 154 | + GitKind::Tag => map.set_tag_name(name.clone(), oid), | |
| 155 | + // The name may have pointed to an annotated tag before. | |
| 156 | + _ => map.remove_tag_name(&name), | |
| 157 | + } | |
| 158 | + } | |
| 159 | + importer.report.refs.push(ImportedRef { | |
| 160 | + name, | |
| 161 | + oid, | |
| 162 | + kind, | |
| 163 | + braid, | |
| 164 | + }); | |
| 165 | + } | |
| 166 | + Ok(importer.report) | |
| 167 | +} | |
| 168 | + | |
| 169 | +#[derive(Default)] | |
| 170 | +struct Plan { | |
| 171 | + /// Commits to walk from. | |
| 172 | + tips: Vec<GitOid>, | |
| 173 | + /// Trees and blobs that refs or tags point to. | |
| 174 | + loose: Vec<(GitOid, GitKind)>, | |
| 175 | + /// Annotated tags to import, each after the tags it points to. | |
| 176 | + tags: Vec<GitOid>, | |
| 177 | + planned_tags: HashSet<GitOid>, | |
| 178 | +} | |
| 179 | + | |
| 180 | +struct Importer<'r, 'o, 'm, O: Objects> { | |
| 181 | + repo: &'r GitRepo, | |
| 182 | + objects: &'o O, | |
| 183 | + map: &'m mut GitMap, | |
| 184 | + report: ImportReport, | |
| 185 | + /// Root trees of the changesets seen in this import. | |
| 186 | + roots: HashMap<ObjectId, ObjectId>, | |
| 187 | + /// The braid id of the empty directory. | |
| 188 | + empty_tree: ObjectId, | |
| 189 | +} | |
| 190 | + | |
| 191 | +/// A git tree being converted, waiting for its subtrees. | |
| 192 | +struct Frame { | |
| 193 | + oid: GitOid, | |
| 194 | + raw: Vec<u8>, | |
| 195 | + /// Path from the root of the commit's tree; empty for the root. | |
| 196 | + path: Vec<u8>, | |
| 197 | + /// The entries as written, with their types. | |
| 198 | + entries: Vec<(EntryType, Vec<u8>, GitOid)>, | |
| 199 | + next: usize, | |
| 200 | + /// Braid entries for the entries converted so far, in the same order. | |
| 201 | + done: Vec<Entry>, | |
| 202 | + /// Whether every subtree so far is canonical. | |
| 203 | + canonical_subtrees: bool, | |
| 204 | + /// Whether an empty directory was left out. | |
| 205 | + dropped_empty: bool, | |
| 206 | +} | |
| 207 | + | |
| 208 | +impl<O: Objects> Importer<'_, '_, '_, O> { | |
| 209 | + /// Follows a ref through annotated tags to a commit, a tree or a blob. | |
| 210 | + fn plan_ref(&mut self, oid: GitOid, plan: &mut Plan) -> Result<(), Error> { | |
| 211 | + let mut chain = Vec::new(); | |
| 212 | + let mut current = oid; | |
| 213 | + loop { | |
| 214 | + match self.repo.kind(¤t)? { | |
| 215 | + GitKind::Commit => { | |
| 216 | + plan.tips.push(current); | |
| 217 | + break; | |
| 218 | + } | |
| 219 | + kind @ (GitKind::Tree | GitKind::Blob) => { | |
| 220 | + plan.loose.push((current, kind)); | |
| 221 | + break; | |
| 222 | + } | |
| 223 | + GitKind::Tag => { | |
| 224 | + // A tag already imported or planned has its target taken | |
| 225 | + // care of. | |
| 226 | + if self.map.tag(¤t).is_some() | |
| 227 | + || plan.planned_tags.contains(¤t) | |
| 228 | + || chain.contains(¤t) | |
| 229 | + { | |
| 230 | + break; | |
| 231 | + } | |
| 232 | + chain.push(current); | |
| 233 | + let bytes = self.repo.read_kind(¤t, GitKind::Tag)?; | |
| 234 | + current = raw::parse_tag(&bytes).map_err(|reason| Error::Malformed { | |
| 235 | + oid: current, | |
| 236 | + kind: GitKind::Tag, | |
| 237 | + reason, | |
| 238 | + })?; | |
| 239 | + } | |
| 240 | + } | |
| 241 | + } | |
| 242 | + for tag in chain.into_iter().rev() { | |
| 243 | + plan.planned_tags.insert(tag); | |
| 244 | + plan.tags.push(tag); | |
| 245 | + } | |
| 246 | + Ok(()) | |
| 247 | + } | |
| 248 | + | |
| 249 | + /// Every commit reachable from `tips` and not yet in the map, parents | |
| 250 | + /// before children. The walk is depth first along first parents, without | |
| 251 | + /// recursion. | |
| 252 | + fn commit_order(&self, tips: &[GitOid]) -> Result<Vec<GitOid>, Error> { | |
| 253 | + let mut order = Vec::new(); | |
| 254 | + let mut seen = HashSet::new(); | |
| 255 | + for tip in tips { | |
| 256 | + if self.map.changeset(tip).is_some() || !seen.insert(*tip) { | |
| 257 | + continue; | |
| 258 | + } | |
| 259 | + let mut stack = vec![(*tip, self.parents(tip)?, 0usize)]; | |
| 260 | + while let Some((oid, parents, next)) = stack.last_mut() { | |
| 261 | + if let Some(parent) = parents.get(*next).copied() { | |
| 262 | + *next += 1; | |
| 263 | + if self.map.changeset(&parent).is_none() && seen.insert(parent) { | |
| 264 | + let grandparents = self.parents(&parent)?; | |
| 265 | + stack.push((parent, grandparents, 0)); | |
| 266 | + } | |
| 267 | + continue; | |
| 268 | + } | |
| 269 | + order.push(*oid); | |
| 270 | + stack.pop(); | |
| 271 | + } | |
| 272 | + } | |
| 273 | + Ok(order) | |
| 274 | + } | |
| 275 | + | |
| 276 | + fn parents(&self, commit: &GitOid) -> Result<Vec<GitOid>, Error> { | |
| 277 | + let bytes = self.repo.read_kind(commit, GitKind::Commit)?; | |
| 278 | + let fields = raw::parse_commit(&bytes).map_err(|reason| Error::Malformed { | |
| 279 | + oid: *commit, | |
| 280 | + kind: GitKind::Commit, | |
| 281 | + reason, | |
| 282 | + })?; | |
| 283 | + Ok(fields.parents) | |
| 284 | + } | |
| 285 | + | |
| 286 | + fn import_commit(&mut self, oid: GitOid) -> Result<(), Error> { | |
| 287 | + let bytes = self.repo.read_kind(&oid, GitKind::Commit)?; | |
| 288 | + let fields = raw::parse_commit(&bytes).map_err(|reason| Error::Malformed { | |
| 289 | + oid, | |
| 290 | + kind: GitKind::Commit, | |
| 291 | + reason, | |
| 292 | + })?; | |
| 293 | + let root = self.convert_tree(fields.tree, oid)?; | |
| 294 | + let mut parents = Vec::with_capacity(fields.parents.len()); | |
| 295 | + for parent in &fields.parents { | |
| 296 | + parents.push(self.map.changeset(parent).ok_or_else(|| Error::NotMapped { | |
| 297 | + what: "commit", | |
| 298 | + id: parent.to_hex(), | |
| 299 | + })?); | |
| 300 | + } | |
| 301 | + let base = match parents.first() { | |
| 302 | + Some(parent) => Some(self.root_of(parent)?), | |
| 303 | + None => None, | |
| 304 | + }; | |
| 305 | + let changes = diff::changes(self.objects, base, root)?; | |
| 306 | + let origin = fetch::put(self.objects, Kind::Blob, &bytes)?; | |
| 307 | + let unknown = || Signature { | |
| 308 | + name: Vec::new(), | |
| 309 | + email: Vec::new(), | |
| 310 | + seconds: 0, | |
| 311 | + offset_minutes: 0, | |
| 312 | + }; | |
| 313 | + let assembled = ChangesetParts { | |
| 314 | + parents, | |
| 315 | + root, | |
| 316 | + changes, | |
| 317 | + author: fields.author.map_or_else(unknown, raw::parse_signature), | |
| 318 | + committer: fields.committer.map_or_else(unknown, raw::parse_signature), | |
| 319 | + message: fields.message.to_vec(), | |
| 320 | + extras: Vec::new(), | |
| 321 | + git_origin: Some(origin), | |
| 322 | + } | |
| 323 | + .assemble() | |
| 324 | + .map_err(|err| Error::Verification { | |
| 325 | + oid, | |
| 326 | + kind: GitKind::Commit, | |
| 327 | + detail: format!("its changeset cannot be assembled: {err}"), | |
| 328 | + })?; | |
| 329 | + if let Some((_, list)) = &assembled.external_list { | |
| 330 | + fetch::put(self.objects, Kind::Blob, list)?; | |
| 331 | + } | |
| 332 | + let changeset = fetch::put(self.objects, Kind::Changeset, &assembled.encoded)?; | |
| 333 | + | |
| 334 | + // Export what was stored and compare. The commit enters the map only | |
| 335 | + // once it has passed, so a resumed import checks it again. | |
| 336 | + let verification = |detail: String| Error::Verification { | |
| 337 | + oid, | |
| 338 | + kind: GitKind::Commit, | |
| 339 | + detail, | |
| 340 | + }; | |
| 341 | + let mut exporter = Exporter::new(self.objects, &*self.map); | |
| 342 | + let (exported, _) = exporter | |
| 343 | + .commit(&changeset) | |
| 344 | + .map_err(|err| verification(err.to_string()))?; | |
| 345 | + if exported != oid { | |
| 346 | + return Err(verification(format!("exported again as {exported}"))); | |
| 347 | + } | |
| 348 | + exporter | |
| 349 | + .object(&fields.tree) | |
| 350 | + .map_err(|err| verification(format!("its tree: {err}")))?; | |
| 351 | + | |
| 352 | + self.map.insert_commit(oid, changeset); | |
| 353 | + self.roots.insert(changeset, root); | |
| 354 | + self.report.commits += 1; | |
| 355 | + Ok(()) | |
| 356 | + } | |
| 357 | + | |
| 358 | + fn root_of(&mut self, changeset: &ObjectId) -> Result<ObjectId, Error> { | |
| 359 | + if let Some(root) = self.roots.get(changeset) { | |
| 360 | + return Ok(*root); | |
| 361 | + } | |
| 362 | + let root = fetch::changeset(self.objects, changeset)?.root; | |
| 363 | + self.roots.insert(*changeset, root); | |
| 364 | + Ok(root) | |
| 365 | + } | |
| 366 | + | |
| 367 | + /// Converts a git tree and everything below it, and returns its braid | |
| 368 | + /// tree. `commit` names the commit (or the object a ref points to) in | |
| 369 | + /// errors. Subtrees are converted before their parents, without recursion. | |
| 370 | + fn convert_tree(&mut self, root: GitOid, commit: GitOid) -> Result<ObjectId, Error> { | |
| 371 | + if let Some(tree) = self.map.tree(&root) { | |
| 372 | + return Ok(tree); | |
| 373 | + } | |
| 374 | + let mut stack = vec![self.open_tree(root, Vec::new(), commit)?]; | |
| 375 | + loop { | |
| 376 | + let top = stack | |
| 377 | + .last_mut() | |
| 378 | + .expect("the stack holds the root until it returns"); | |
| 379 | + if let Some((kind, name, oid)) = top.entries.get(top.next).cloned() { | |
| 380 | + let kind = match kind { | |
| 381 | + EntryType::Tree => match self.map.tree(&oid) { | |
| 382 | + Some(tree) => { | |
| 383 | + top.canonical_subtrees &= self.map.raw_tree(&oid).is_none(); | |
| 384 | + if tree == self.empty_tree { | |
| 385 | + top.dropped_empty = true; | |
| 386 | + top.next += 1; | |
| 387 | + continue; | |
| 388 | + } | |
| 389 | + EntryKind::Tree { tree } | |
| 390 | + } | |
| 391 | + None => { | |
| 392 | + let path = join(&top.path, &name); | |
| 393 | + let child = self.open_tree(oid, path, commit)?; | |
| 394 | + stack.push(child); | |
| 395 | + continue; | |
| 396 | + } | |
| 397 | + }, | |
| 398 | + EntryType::Gitlink => EntryKind::Gitlink { | |
| 399 | + commit: GitId::from(oid), | |
| 400 | + }, | |
| 401 | + EntryType::File | EntryType::Executable | EntryType::Symlink => { | |
| 402 | + let (blob, size) = self.import_blob(oid)?; | |
| 403 | + match kind { | |
| 404 | + EntryType::File => EntryKind::File { blob, size }, | |
| 405 | + EntryType::Executable => EntryKind::Executable { blob, size }, | |
| 406 | + _ => EntryKind::Symlink { blob, size }, | |
| 407 | + } | |
| 408 | + } | |
| 409 | + }; | |
| 410 | + top.done.push(Entry { name, kind }); | |
| 411 | + top.next += 1; | |
| 412 | + continue; | |
| 413 | + } | |
| 414 | + let finished = stack | |
| 415 | + .pop() | |
| 416 | + .expect("the stack holds the root until it returns"); | |
| 417 | + let tree = self.finish_tree(finished, commit)?; | |
| 418 | + match stack.last_mut() { | |
| 419 | + Some(parent) => { | |
| 420 | + let (_, name, oid) = parent.entries[parent.next].clone(); | |
| 421 | + parent.canonical_subtrees &= self.map.raw_tree(&oid).is_none(); | |
| 422 | + if tree == self.empty_tree { | |
| 423 | + // An empty directory, or one holding only empty | |
| 424 | + // ones: braid trees leave it out. | |
| 425 | + parent.dropped_empty = true; | |
| 426 | + } else { | |
| 427 | + parent.done.push(Entry { | |
| 428 | + name, | |
| 429 | + kind: EntryKind::Tree { tree }, | |
| 430 | + }); | |
| 431 | + } | |
| 432 | + parent.next += 1; | |
| 433 | + } | |
| 434 | + // A root may be empty. | |
| 435 | + None => return Ok(tree), | |
| 436 | + } | |
| 437 | + } | |
| 438 | + } | |
| 439 | + | |
| 440 | + /// Reads a git tree and checks every entry's mode and name before any of | |
| 441 | + /// its content is read. | |
| 442 | + fn open_tree(&self, oid: GitOid, path: Vec<u8>, commit: GitOid) -> Result<Frame, Error> { | |
| 443 | + let raw = self.repo.read_kind(&oid, GitKind::Tree)?; | |
| 444 | + let parsed = raw::parse_tree(&raw).map_err(|reason| Error::Malformed { | |
| 445 | + oid, | |
| 446 | + kind: GitKind::Tree, | |
| 447 | + reason, | |
| 448 | + })?; | |
| 449 | + let mut entries = Vec::with_capacity(parsed.len()); | |
| 450 | + for entry in &parsed { | |
| 451 | + let kind = EntryType::from_mode(entry.mode).ok_or_else(|| Error::UnsupportedMode { | |
| 452 | + commit, | |
| 453 | + path: join(&path, entry.name), | |
| 454 | + mode: entry.mode.to_vec(), | |
| 455 | + })?; | |
| 456 | + let refused = |reason: String| Error::RefusedPath { | |
| 457 | + commit, | |
| 458 | + path: join(&path, entry.name), | |
| 459 | + reason, | |
| 460 | + }; | |
| 461 | + validate_name(entry.name).map_err(|err| refused(err.to_string()))?; | |
| 462 | + if kind == EntryType::Symlink && forbidden_as_symlink(entry.name) { | |
| 463 | + return Err(refused("this name must not be a symlink".into())); | |
| 464 | + } | |
| 465 | + entries.push((kind, entry.name.to_vec(), entry.oid)); | |
| 466 | + } | |
| 467 | + let count = entries.len(); | |
| 468 | + Ok(Frame { | |
| 469 | + oid, | |
| 470 | + raw, | |
| 471 | + path, | |
| 472 | + entries, | |
| 473 | + next: 0, | |
| 474 | + done: Vec::with_capacity(count), | |
| 475 | + canonical_subtrees: true, | |
| 476 | + dropped_empty: false, | |
| 477 | + }) | |
| 478 | + } | |
| 479 | + | |
| 480 | + /// Stores the braid tree of a converted git tree, decides whether the git | |
| 481 | + /// tree is canonical, and records it. | |
| 482 | + fn finish_tree(&mut self, frame: Frame, commit: GitOid) -> Result<ObjectId, Error> { | |
| 483 | + let Frame { | |
| 484 | + oid, | |
| 485 | + raw, | |
| 486 | + path, | |
| 487 | + done, | |
| 488 | + canonical_subtrees, | |
| 489 | + dropped_empty, | |
| 490 | + .. | |
| 491 | + } = frame; | |
| 492 | + // Braid names are unique: of duplicate entries, the last one written | |
| 493 | + // stays, which is the one git puts in the index and checks out. The | |
| 494 | + // raw bytes keep the others. | |
| 495 | + let written = done.len(); | |
| 496 | + let mut names = HashSet::with_capacity(written); | |
| 497 | + let entries: Vec<Entry> = done | |
| 498 | + .into_iter() | |
| 499 | + .rev() | |
| 500 | + .filter(|entry| names.insert(entry.name.clone())) | |
| 501 | + .collect(); | |
| 502 | + let unique = entries.len() == written; | |
| 503 | + for entry in &entries { | |
| 504 | + validate_entry(entry).map_err(|err| Error::RefusedPath { | |
| 505 | + commit, | |
| 506 | + path: join(&path, &entry.name), | |
| 507 | + reason: err.to_string(), | |
| 508 | + })?; | |
| 509 | + } | |
| 510 | + let directory = build_directory(entries).map_err(|err| Error::RefusedPath { | |
| 511 | + commit, | |
| 512 | + path: path.clone(), | |
| 513 | + reason: err.to_string(), | |
| 514 | + })?; | |
| 515 | + for (_, bytes) in &directory.nodes { | |
| 516 | + fetch::put(self.objects, Kind::Tree, bytes)?; | |
| 517 | + } | |
| 518 | + let tree = directory.root(); | |
| 519 | + | |
| 520 | + // Canonical means the export, reading back what was just stored, | |
| 521 | + // gives exactly these bytes. A tree naming a subtree that is not | |
| 522 | + // canonical cannot be: the subtree's canonical id differs. Neither can | |
| 523 | + // one that lost duplicates or empty directories. | |
| 524 | + let canonical = canonical_subtrees | |
| 525 | + && unique | |
| 526 | + && !dropped_empty | |
| 527 | + && Exporter::new(self.objects, &*self.map).tree(&tree)?.1 == raw; | |
| 528 | + let raw_blob = if canonical { | |
| 529 | + None | |
| 530 | + } else { | |
| 531 | + let blob = fetch::put(self.objects, Kind::Blob, &raw)?; | |
| 532 | + let stored = fetch::get(self.objects, &blob, Kind::Blob)?; | |
| 533 | + if GitOid::for_object(GitKind::Tree, &stored)? != oid { | |
| 534 | + return Err(Error::Verification { | |
| 535 | + oid, | |
| 536 | + kind: GitKind::Tree, | |
| 537 | + detail: "its raw bytes do not read back".into(), | |
| 538 | + }); | |
| 539 | + } | |
| 540 | + Some(blob) | |
| 541 | + }; | |
| 542 | + self.map.insert_tree(oid, tree, raw_blob); | |
| 543 | + self.report.trees += 1; | |
| 544 | + if raw_blob.is_some() { | |
| 545 | + self.report.raw_trees += 1; | |
| 546 | + } | |
| 547 | + Ok(tree) | |
| 548 | + } | |
| 549 | + | |
| 550 | + fn import_blob(&mut self, oid: GitOid) -> Result<(ObjectId, u64), Error> { | |
| 551 | + if let Some(found) = self.map.blob(&oid) { | |
| 552 | + return Ok(found); | |
| 553 | + } | |
| 554 | + let bytes = self.repo.read_kind(&oid, GitKind::Blob)?; | |
| 555 | + let blob = fetch::put(self.objects, Kind::Blob, &bytes)?; | |
| 556 | + let size = bytes.len() as u64; | |
| 557 | + self.map.insert_blob(oid, blob, size); | |
| 558 | + self.report.blobs += 1; | |
| 559 | + Ok((blob, size)) | |
| 560 | + } | |
| 561 | + | |
| 562 | + fn import_tag(&mut self, oid: GitOid) -> Result<(), Error> { | |
| 563 | + if self.map.tag(&oid).is_some() { | |
| 564 | + return Ok(()); | |
| 565 | + } | |
| 566 | + let bytes = self.repo.read_kind(&oid, GitKind::Tag)?; | |
| 567 | + let target = raw::parse_tag(&bytes).map_err(|reason| Error::Malformed { | |
| 568 | + oid, | |
| 569 | + kind: GitKind::Tag, | |
| 570 | + reason, | |
| 571 | + })?; | |
| 572 | + let target_kind = self.repo.kind(&target)?; | |
| 573 | + let imported = match target_kind { | |
| 574 | + GitKind::Commit => self.map.changeset(&target).is_some(), | |
| 575 | + GitKind::Tree => self.map.tree(&target).is_some(), | |
| 576 | + GitKind::Blob => self.map.blob(&target).is_some(), | |
| 577 | + GitKind::Tag => self.map.tag(&target).is_some(), | |
| 578 | + }; | |
| 579 | + if !imported { | |
| 580 | + return Err(Error::NotMapped { | |
| 581 | + what: target_kind.name(), | |
| 582 | + id: target.to_hex(), | |
| 583 | + }); | |
| 584 | + } | |
| 585 | + let raw = fetch::put(self.objects, Kind::Blob, &bytes)?; | |
| 586 | + let stored = fetch::get(self.objects, &raw, Kind::Blob)?; | |
| 587 | + if GitOid::for_object(GitKind::Tag, &stored)? != oid { | |
| 588 | + return Err(Error::Verification { | |
| 589 | + oid, | |
| 590 | + kind: GitKind::Tag, | |
| 591 | + detail: "its raw bytes do not read back".into(), | |
| 592 | + }); | |
| 593 | + } | |
| 594 | + self.map.insert_tag( | |
| 595 | + oid, | |
| 596 | + TagEntry { | |
| 597 | + raw, | |
| 598 | + target, | |
| 599 | + target_kind, | |
| 600 | + }, | |
| 601 | + ); | |
| 602 | + self.report.tags += 1; | |
| 603 | + Ok(()) | |
| 604 | + } | |
| 605 | +} | |
| 606 | + | |
| 607 | +fn join(prefix: &[u8], name: &[u8]) -> Vec<u8> { | |
| 608 | + if prefix.is_empty() { | |
| 609 | + return name.to_vec(); | |
| 610 | + } | |
| 611 | + let mut path = Vec::with_capacity(prefix.len() + 1 + name.len()); | |
| 612 | + path.extend_from_slice(prefix); | |
| 613 | + path.push(b'/'); | |
| 614 | + path.extend_from_slice(name); | |
| 615 | + path | |
| 616 | +} |
added crates/git/src/lib.rs +58 −0
| @@ -0,0 +1,58 @@ | ||
| 1 | +// SPDX-License-Identifier: Apache-2.0 | |
| 2 | +// Copyright (c) 2026 UtopiaIA | |
| 3 | + | |
| 4 | +//! The git bridge of elffuss-braid: git history in, git history out, bit for | |
| 5 | +//! bit. | |
| 6 | +//! | |
| 7 | +//! - [`import`] reads a git repository and stores every blob, tree, commit and | |
| 8 | +//! annotated tag reachable from its branches and tags as braid objects, | |
| 9 | +//! recording each mapping in a [`GitMap`]. Every commit is exported again | |
| 10 | +//! as it is imported, and the import stops unless its id comes back the | |
| 11 | +//! same. | |
| 12 | +//! - The [`Exporter`] turns braid objects back into git objects: imported ones | |
| 13 | +//! byte for byte, from the raw bytes they keep, and new ones | |
| 14 | +//! deterministically. [`write_to_repo`] writes them into a git repository | |
| 15 | +//! and points refs at them. | |
| 16 | +//! - [`verify_round_trip`] imports a repository, exports it into a fresh one, | |
| 17 | +//! and checks that every id matches. | |
| 18 | +//! | |
| 19 | +//! Git access goes through [gitoxide](https://github.com/GitoxideLabs/gitoxide) | |
| 20 | +//! (MIT or Apache-2.0). Braid contains no code from git, which is GPLv2: the | |
| 21 | +//! few git formats parsed here are written from their documentation. | |
| 22 | +//! | |
| 23 | +//! Only SHA-1 repositories are supported for now, and every git id is | |
| 24 | +//! computed with SHA-1 collision detection. | |
| 25 | + | |
| 26 | +#![forbid(unsafe_code)] | |
| 27 | + | |
| 28 | +mod diff; | |
| 29 | +mod error; | |
| 30 | +mod export; | |
| 31 | +mod fetch; | |
| 32 | +mod import; | |
| 33 | +mod map; | |
| 34 | +mod oid; | |
| 35 | +mod raw; | |
| 36 | +mod repo; | |
| 37 | +mod roundtrip; | |
| 38 | + | |
| 39 | +pub use error::{BoxError, Error}; | |
| 40 | +pub use export::{ | |
| 41 | + Exporter, RefTarget, RefUpdate, WriteReport, export_blob, export_commit, export_object, | |
| 42 | + export_tree, write_to_repo, | |
| 43 | +}; | |
| 44 | +pub use import::{ImportOptions, ImportReport, ImportedRef, import}; | |
| 45 | +pub use map::{GitMap, MapCounts, TagEntry}; | |
| 46 | +pub use oid::{GitKind, GitOid, ParseGitOidError}; | |
| 47 | +pub use roundtrip::{RoundTripReport, verify_round_trip, verify_round_trip_with}; | |
| 48 | + | |
| 49 | +/// The parsers of raw git objects, for the fuzz targets in `fuzz/`. Not part | |
| 50 | +/// of the stable API. | |
| 51 | +#[cfg(feature = "fuzzing")] | |
| 52 | +#[doc(hidden)] | |
| 53 | +pub mod fuzzing { | |
| 54 | + pub use crate::raw::{ | |
| 55 | + CommitFields, EntryType, RawEntry, encode_commit, parse_commit, parse_signature, parse_tag, | |
| 56 | + parse_tree, | |
| 57 | + }; | |
| 58 | +} |
added crates/git/src/map.rs +474 −0
| @@ -0,0 +1,474 @@ | ||
| 1 | +// SPDX-License-Identifier: Apache-2.0 | |
| 2 | +// Copyright (c) 2026 UtopiaIA | |
| 3 | + | |
| 4 | +//! The two-way mapping between git objects and braid objects. | |
| 5 | +//! | |
| 6 | +//! Every imported git object has a braid counterpart: a commit has a | |
| 7 | +//! changeset, a tree a braid tree, a blob a braid blob, and an annotated tag | |
| 8 | +//! the blob holding its raw bytes. The map records both directions, plus the | |
| 9 | +//! raw bytes of the git trees that cannot be regenerated from their braid | |
| 10 | +//! tree. It is derived data: importing the same repository again rebuilds it. | |
| 11 | + | |
| 12 | +use std::collections::{BTreeMap, HashMap}; | |
| 13 | + | |
| 14 | +use braid_format::codec::{Reader, put_bytes, put_id, put_uv}; | |
| 15 | +use braid_format::{DecodeError, ObjectId}; | |
| 16 | + | |
| 17 | +use crate::oid::{GitKind, GitOid}; | |
| 18 | + | |
| 19 | +/// What the map records about an annotated tag object. | |
| 20 | +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | |
| 21 | +pub struct TagEntry { | |
| 22 | + /// The braid blob holding the tag's raw bytes. | |
| 23 | + pub raw: ObjectId, | |
| 24 | + /// The object the tag points to. | |
| 25 | + pub target: GitOid, | |
| 26 | + /// The kind of that object. | |
| 27 | + pub target_kind: GitKind, | |
| 28 | +} | |
| 29 | + | |
| 30 | +/// How many objects of each kind a map holds. | |
| 31 | +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] | |
| 32 | +pub struct MapCounts { | |
| 33 | + /// Commits. | |
| 34 | + pub commits: usize, | |
| 35 | + /// Trees, raw or not. | |
| 36 | + pub trees: usize, | |
| 37 | + /// Trees kept as raw bytes. | |
| 38 | + pub raw_trees: usize, | |
| 39 | + /// Blobs. | |
| 40 | + pub blobs: usize, | |
| 41 | + /// Annotated tag objects. | |
| 42 | + pub tags: usize, | |
| 43 | + /// Tag names. | |
| 44 | + pub tag_names: usize, | |
| 45 | +} | |
| 46 | + | |
| 47 | +/// The two-way mapping between imported git objects and braid objects. | |
| 48 | +/// | |
| 49 | +/// - **Commits** map one to one to changesets. | |
| 50 | +/// - **Trees**: every git tree maps to one braid tree. A git tree is | |
| 51 | +/// *canonical* when exporting its braid tree gives it back byte for byte; a | |
| 52 | +/// braid tree has at most one canonical git tree, which is its reverse | |
| 53 | +/// mapping. A git tree that is not canonical (a mode such as `100664`, | |
| 54 | +/// unsorted or duplicate entries, or a subtree that is itself not canonical) | |
| 55 | +/// keeps its raw bytes in a blob, keyed by its git id: several git trees can | |
| 56 | +/// share one braid tree, so the git id is what tells them apart. | |
| 57 | +/// - **Blobs** map one to one, with the size of the content. | |
| 58 | +/// - **Tags**: an annotated tag maps to the blob with its raw bytes, and | |
| 59 | +/// records its target. Tag names map to the tag object they point to. | |
| 60 | +/// | |
| 61 | +/// [`to_bytes`](Self::to_bytes) and [`from_bytes`](Self::from_bytes) give a | |
| 62 | +/// versioned, canonical encoding, so the store can keep the map as a derived | |
| 63 | +/// record. | |
| 64 | +#[derive(Clone, Debug, Default, PartialEq, Eq)] | |
| 65 | +pub struct GitMap { | |
| 66 | + commits: HashMap<GitOid, ObjectId>, | |
| 67 | + changesets: HashMap<ObjectId, GitOid>, | |
| 68 | + trees: HashMap<GitOid, ObjectId>, | |
| 69 | + canonical_trees: HashMap<ObjectId, GitOid>, | |
| 70 | + raw_trees: HashMap<GitOid, ObjectId>, | |
| 71 | + blobs: HashMap<GitOid, (ObjectId, u64)>, | |
| 72 | + git_blobs: HashMap<ObjectId, GitOid>, | |
| 73 | + tags: HashMap<GitOid, TagEntry>, | |
| 74 | + tag_blobs: HashMap<ObjectId, GitOid>, | |
| 75 | + tag_names: BTreeMap<Vec<u8>, GitOid>, | |
| 76 | +} | |
| 77 | + | |
| 78 | +impl GitMap { | |
| 79 | + /// An empty map. | |
| 80 | + pub fn new() -> Self { | |
| 81 | + Self::default() | |
| 82 | + } | |
| 83 | + | |
| 84 | + /// The changeset imported from a commit. | |
| 85 | + pub fn changeset(&self, commit: &GitOid) -> Option<ObjectId> { | |
| 86 | + self.commits.get(commit).copied() | |
| 87 | + } | |
| 88 | + | |
| 89 | + /// The commit a changeset was imported from. | |
| 90 | + pub fn commit(&self, changeset: &ObjectId) -> Option<GitOid> { | |
| 91 | + self.changesets.get(changeset).copied() | |
| 92 | + } | |
| 93 | + | |
| 94 | + /// The braid tree of a git tree. | |
| 95 | + pub fn tree(&self, tree: &GitOid) -> Option<ObjectId> { | |
| 96 | + self.trees.get(tree).copied() | |
| 97 | + } | |
| 98 | + | |
| 99 | + /// The canonical git tree of a braid tree, if one was imported. | |
| 100 | + pub fn git_tree(&self, tree: &ObjectId) -> Option<GitOid> { | |
| 101 | + self.canonical_trees.get(tree).copied() | |
| 102 | + } | |
| 103 | + | |
| 104 | + /// The blob holding the raw bytes of a git tree that is not canonical. | |
| 105 | + pub fn raw_tree(&self, tree: &GitOid) -> Option<ObjectId> { | |
| 106 | + self.raw_trees.get(tree).copied() | |
| 107 | + } | |
| 108 | + | |
| 109 | + /// The braid blob of a git blob, and its size. | |
| 110 | + pub fn blob(&self, blob: &GitOid) -> Option<(ObjectId, u64)> { | |
| 111 | + self.blobs.get(blob).copied() | |
| 112 | + } | |
| 113 | + | |
| 114 | + /// The git blob of a braid blob. | |
| 115 | + pub fn git_blob(&self, blob: &ObjectId) -> Option<GitOid> { | |
| 116 | + self.git_blobs.get(blob).copied() | |
| 117 | + } | |
| 118 | + | |
| 119 | + /// What the map knows about an annotated tag object. | |
| 120 | + pub fn tag(&self, tag: &GitOid) -> Option<TagEntry> { | |
| 121 | + self.tags.get(tag).copied() | |
| 122 | + } | |
| 123 | + | |
| 124 | + /// The tag object whose raw bytes are in this braid blob. | |
| 125 | + pub fn git_tag(&self, raw: &ObjectId) -> Option<GitOid> { | |
| 126 | + self.tag_blobs.get(raw).copied() | |
| 127 | + } | |
| 128 | + | |
| 129 | + /// The annotated tag a tag name points to, by its full ref name such as | |
| 130 | + /// `refs/tags/v1.0`, with what the map knows about it. | |
| 131 | + pub fn tag_by_name(&self, name: &[u8]) -> Option<(GitOid, TagEntry)> { | |
| 132 | + let oid = *self.tag_names.get(name)?; | |
| 133 | + Some((oid, self.tags.get(&oid).copied()?)) | |
| 134 | + } | |
| 135 | + | |
| 136 | + /// Every tag name and the annotated tag it points to, in name order. | |
| 137 | + pub fn tag_names(&self) -> impl Iterator<Item = (&[u8], GitOid)> + '_ { | |
| 138 | + self.tag_names | |
| 139 | + .iter() | |
| 140 | + .map(|(name, oid)| (name.as_slice(), *oid)) | |
| 141 | + } | |
| 142 | + | |
| 143 | + /// Every commit and its changeset, in no particular order. | |
| 144 | + pub fn commits(&self) -> impl Iterator<Item = (GitOid, ObjectId)> + '_ { | |
| 145 | + self.commits.iter().map(|(oid, id)| (*oid, *id)) | |
| 146 | + } | |
| 147 | + | |
| 148 | + /// How many objects of each kind the map holds. | |
| 149 | + pub fn counts(&self) -> MapCounts { | |
| 150 | + MapCounts { | |
| 151 | + commits: self.commits.len(), | |
| 152 | + trees: self.trees.len(), | |
| 153 | + raw_trees: self.raw_trees.len(), | |
| 154 | + blobs: self.blobs.len(), | |
| 155 | + tags: self.tags.len(), | |
| 156 | + tag_names: self.tag_names.len(), | |
| 157 | + } | |
| 158 | + } | |
| 159 | + | |
| 160 | + pub(crate) fn insert_commit(&mut self, commit: GitOid, changeset: ObjectId) { | |
| 161 | + self.commits.insert(commit, changeset); | |
| 162 | + self.changesets.insert(changeset, commit); | |
| 163 | + } | |
| 164 | + | |
| 165 | + /// Records a git tree. `raw` is the blob with its bytes when it is not | |
| 166 | + /// canonical. | |
| 167 | + pub(crate) fn insert_tree(&mut self, tree: GitOid, braid: ObjectId, raw: Option<ObjectId>) { | |
| 168 | + self.trees.insert(tree, braid); | |
| 169 | + match raw { | |
| 170 | + Some(blob) => { | |
| 171 | + self.raw_trees.insert(tree, blob); | |
| 172 | + } | |
| 173 | + None => { | |
| 174 | + self.canonical_trees.entry(braid).or_insert(tree); | |
| 175 | + } | |
| 176 | + } | |
| 177 | + } | |
| 178 | + | |
| 179 | + pub(crate) fn insert_blob(&mut self, blob: GitOid, braid: ObjectId, size: u64) { | |
| 180 | + self.blobs.insert(blob, (braid, size)); | |
| 181 | + self.git_blobs.insert(braid, blob); | |
| 182 | + } | |
| 183 | + | |
| 184 | + pub(crate) fn insert_tag(&mut self, tag: GitOid, entry: TagEntry) { | |
| 185 | + self.tags.insert(tag, entry); | |
| 186 | + self.tag_blobs.insert(entry.raw, tag); | |
| 187 | + } | |
| 188 | + | |
| 189 | + pub(crate) fn set_tag_name(&mut self, name: Vec<u8>, tag: GitOid) { | |
| 190 | + self.tag_names.insert(name, tag); | |
| 191 | + } | |
| 192 | + | |
| 193 | + pub(crate) fn remove_tag_name(&mut self, name: &[u8]) { | |
| 194 | + self.tag_names.remove(name); | |
| 195 | + } | |
| 196 | + | |
| 197 | + /// The canonical encoding: a magic string and a version, then each table | |
| 198 | + /// sorted by key. | |
| 199 | + /// | |
| 200 | + /// ```text | |
| 201 | + /// "braid-git-map" u8 version = 1 | |
| 202 | + /// uv n, n × ([20] commit, [32] changeset) | |
| 203 | + /// uv n, n × ([20] tree, [32] braid tree) | |
| 204 | + /// uv n, n × ([20] tree, [32] blob with its raw bytes) | |
| 205 | + /// uv n, n × ([20] blob, [32] braid blob, uv size) | |
| 206 | + /// uv n, n × ([20] tag, [32] blob with its raw bytes, [20] target, u8 target kind) | |
| 207 | + /// uv n, n × (bytes name, [20] tag) | |
| 208 | + /// ``` | |
| 209 | + /// | |
| 210 | + /// Target kinds are 1 commit, 2 tree, 3 blob, 4 tag. | |
| 211 | + pub fn to_bytes(&self) -> Vec<u8> { | |
| 212 | + let mut out = Vec::new(); | |
| 213 | + out.extend_from_slice(MAGIC); | |
| 214 | + out.push(VERSION); | |
| 215 | + put_table(&mut out, &self.commits, put_id); | |
| 216 | + put_table(&mut out, &self.trees, put_id); | |
| 217 | + put_table(&mut out, &self.raw_trees, put_id); | |
| 218 | + put_table(&mut out, &self.blobs, |out, (id, size)| { | |
| 219 | + put_id(out, id); | |
| 220 | + put_uv(out, *size); | |
| 221 | + }); | |
| 222 | + put_table(&mut out, &self.tags, |out, entry| { | |
| 223 | + put_id(out, &entry.raw); | |
| 224 | + out.extend_from_slice(entry.target.as_bytes()); | |
| 225 | + out.push(entry.target_kind.code()); | |
| 226 | + }); | |
| 227 | + put_uv(&mut out, self.tag_names.len() as u64); | |
| 228 | + for (name, oid) in &self.tag_names { | |
| 229 | + put_bytes(&mut out, name); | |
| 230 | + out.extend_from_slice(oid.as_bytes()); | |
| 231 | + } | |
| 232 | + out | |
| 233 | + } | |
| 234 | + | |
| 235 | + /// Decodes [`to_bytes`](Self::to_bytes), checking that the encoding is | |
| 236 | + /// canonical and that the tables agree with each other. | |
| 237 | + pub fn from_bytes(bytes: &[u8]) -> Result<Self, DecodeError> { | |
| 238 | + let mut reader = Reader::new(bytes); | |
| 239 | + let at = reader.position(); | |
| 240 | + if reader.take(MAGIC.len())? != MAGIC { | |
| 241 | + return Err(invalid(at, "git map magic")); | |
| 242 | + } | |
| 243 | + let at = reader.position(); | |
| 244 | + if reader.u8()? != VERSION { | |
| 245 | + return Err(invalid(at, "git map version")); | |
| 246 | + } | |
| 247 | + let mut map = GitMap::new(); | |
| 248 | + for (oid, id) in read_table(&mut reader, 32, |r| r.id())? { | |
| 249 | + if map.changesets.insert(id, oid).is_some() { | |
| 250 | + return Err(invalid(reader.position(), "changeset mapped twice")); | |
| 251 | + } | |
| 252 | + map.commits.insert(oid, id); | |
| 253 | + } | |
| 254 | + map.trees = read_table(&mut reader, 32, |r| r.id())? | |
| 255 | + .into_iter() | |
| 256 | + .collect(); | |
| 257 | + for (oid, blob) in read_table(&mut reader, 32, |r| r.id())? { | |
| 258 | + if !map.trees.contains_key(&oid) { | |
| 259 | + return Err(invalid(reader.position(), "raw tree that is not a tree")); | |
| 260 | + } | |
| 261 | + map.raw_trees.insert(oid, blob); | |
| 262 | + } | |
| 263 | + for (oid, braid) in &map.trees { | |
| 264 | + if !map.raw_trees.contains_key(oid) | |
| 265 | + && map.canonical_trees.insert(*braid, *oid).is_some() | |
| 266 | + { | |
| 267 | + return Err(invalid( | |
| 268 | + reader.position(), | |
| 269 | + "two canonical trees for one tree", | |
| 270 | + )); | |
| 271 | + } | |
| 272 | + } | |
| 273 | + for (oid, (id, size)) in read_table(&mut reader, 33, |r| Ok((r.id()?, r.uv()?)))? { | |
| 274 | + if map.git_blobs.insert(id, oid).is_some() { | |
| 275 | + return Err(invalid(reader.position(), "blob mapped twice")); | |
| 276 | + } | |
| 277 | + map.blobs.insert(oid, (id, size)); | |
| 278 | + } | |
| 279 | + let tags = read_table(&mut reader, 53, |r| { | |
| 280 | + let raw = r.id()?; | |
| 281 | + let target = GitOid::from_bytes(r.array()?); | |
| 282 | + let at = r.position(); | |
| 283 | + let target_kind = GitKind::from_code(r.u8()?).ok_or(invalid(at, "tag target kind"))?; | |
| 284 | + Ok(TagEntry { | |
| 285 | + raw, | |
| 286 | + target, | |
| 287 | + target_kind, | |
| 288 | + }) | |
| 289 | + })?; | |
| 290 | + for (oid, entry) in tags { | |
| 291 | + if map.tag_blobs.insert(entry.raw, oid).is_some() { | |
| 292 | + return Err(invalid(reader.position(), "tag mapped twice")); | |
| 293 | + } | |
| 294 | + map.tags.insert(oid, entry); | |
| 295 | + } | |
| 296 | + let count = reader.count(1 + GitOid::LEN)?; | |
| 297 | + let mut previous: Option<Vec<u8>> = None; | |
| 298 | + for _ in 0..count { | |
| 299 | + let at = reader.position(); | |
| 300 | + let name = reader.bytes()?.to_vec(); | |
| 301 | + let oid = GitOid::from_bytes(reader.array()?); | |
| 302 | + if previous.as_ref().is_some_and(|p| *p >= name) { | |
| 303 | + return Err(invalid(at, "tag names out of order")); | |
| 304 | + } | |
| 305 | + if !map.tags.contains_key(&oid) { | |
| 306 | + return Err(invalid(at, "tag name for an unknown tag")); | |
| 307 | + } | |
| 308 | + previous = Some(name.clone()); | |
| 309 | + map.tag_names.insert(name, oid); | |
| 310 | + } | |
| 311 | + reader.finish()?; | |
| 312 | + Ok(map) | |
| 313 | + } | |
| 314 | +} | |
| 315 | + | |
| 316 | +const MAGIC: &[u8] = b"braid-git-map"; | |
| 317 | +const VERSION: u8 = 1; | |
| 318 | + | |
| 319 | +fn invalid(at: usize, what: &'static str) -> DecodeError { | |
| 320 | + DecodeError::Invalid { at, what } | |
| 321 | +} | |
| 322 | + | |
| 323 | +fn put_table<V>( | |
| 324 | + out: &mut Vec<u8>, | |
| 325 | + table: &HashMap<GitOid, V>, | |
| 326 | + mut put_value: impl FnMut(&mut Vec<u8>, &V), | |
| 327 | +) { | |
| 328 | + let mut keys: Vec<&GitOid> = table.keys().collect(); | |
| 329 | + keys.sort_unstable(); | |
| 330 | + put_uv(out, keys.len() as u64); | |
| 331 | + for key in keys { | |
| 332 | + out.extend_from_slice(key.as_bytes()); | |
| 333 | + put_value(out, &table[key]); | |
| 334 | + } | |
| 335 | +} | |
| 336 | + | |
| 337 | +/// Reads a table written by [`put_table`]: keys strictly ascending, each | |
| 338 | +/// value at least `min_value_bytes` long. | |
| 339 | +fn read_table<V>( | |
| 340 | + reader: &mut Reader<'_>, | |
| 341 | + min_value_bytes: usize, | |
| 342 | + mut read_value: impl FnMut(&mut Reader<'_>) -> Result<V, DecodeError>, | |
| 343 | +) -> Result<Vec<(GitOid, V)>, DecodeError> { | |
| 344 | + let count = reader.count(GitOid::LEN + min_value_bytes)?; | |
| 345 | + let mut rows: Vec<(GitOid, V)> = Vec::with_capacity(count); | |
| 346 | + for _ in 0..count { | |
| 347 | + let at = reader.position(); | |
| 348 | + let key = GitOid::from_bytes(reader.array()?); | |
| 349 | + if rows.last().is_some_and(|(previous, _)| *previous >= key) { | |
| 350 | + return Err(invalid(at, "git map keys out of order")); | |
| 351 | + } | |
| 352 | + let value = read_value(reader)?; | |
| 353 | + rows.push((key, value)); | |
| 354 | + } | |
| 355 | + Ok(rows) | |
| 356 | +} | |
| 357 | + | |
| 358 | +#[cfg(test)] | |
| 359 | +mod tests { | |
| 360 | + use super::*; | |
| 361 | + use braid_format::Kind; | |
| 362 | + | |
| 363 | + fn oid(byte: u8) -> GitOid { | |
| 364 | + GitOid::from_bytes([byte; 20]) | |
| 365 | + } | |
| 366 | + | |
| 367 | + fn id(text: &str) -> ObjectId { | |
| 368 | + ObjectId::hash(Kind::Blob, text.as_bytes()) | |
| 369 | + } | |
| 370 | + | |
| 371 | + fn sample() -> GitMap { | |
| 372 | + let mut map = GitMap::new(); | |
| 373 | + map.insert_commit(oid(1), id("c1")); | |
| 374 | + map.insert_commit(oid(2), id("c2")); | |
| 375 | + map.insert_tree(oid(3), id("t1"), None); | |
| 376 | + map.insert_tree(oid(4), id("t1"), Some(id("raw t1"))); | |
| 377 | + map.insert_tree(oid(5), id("t2"), None); | |
| 378 | + map.insert_blob(oid(6), id("b1"), 42); | |
| 379 | + map.insert_tag( | |
| 380 | + oid(7), | |
| 381 | + TagEntry { | |
| 382 | + raw: id("tag"), | |
| 383 | + target: oid(1), | |
| 384 | + target_kind: GitKind::Commit, | |
| 385 | + }, | |
| 386 | + ); | |
| 387 | + map.set_tag_name(b"refs/tags/v1".to_vec(), oid(7)); | |
| 388 | + map | |
| 389 | + } | |
| 390 | + | |
| 391 | + #[test] | |
| 392 | + fn lookups_both_ways() { | |
| 393 | + let map = sample(); | |
| 394 | + assert_eq!(map.changeset(&oid(1)), Some(id("c1"))); | |
| 395 | + assert_eq!(map.commit(&id("c2")), Some(oid(2))); | |
| 396 | + assert_eq!(map.tree(&oid(4)), Some(id("t1"))); | |
| 397 | + assert_eq!(map.git_tree(&id("t1")), Some(oid(3))); | |
| 398 | + assert_eq!(map.raw_tree(&oid(4)), Some(id("raw t1"))); | |
| 399 | + assert_eq!(map.raw_tree(&oid(3)), None); | |
| 400 | + assert_eq!(map.blob(&oid(6)), Some((id("b1"), 42))); | |
| 401 | + assert_eq!(map.git_blob(&id("b1")), Some(oid(6))); | |
| 402 | + assert_eq!(map.git_tag(&id("tag")), Some(oid(7))); | |
| 403 | + let (tag, entry) = map.tag_by_name(b"refs/tags/v1").unwrap(); | |
| 404 | + assert_eq!(tag, oid(7)); | |
| 405 | + assert_eq!(entry.target, oid(1)); | |
| 406 | + assert_eq!( | |
| 407 | + map.counts(), | |
| 408 | + MapCounts { | |
| 409 | + commits: 2, | |
| 410 | + trees: 3, | |
| 411 | + raw_trees: 1, | |
| 412 | + blobs: 1, | |
| 413 | + tags: 1, | |
| 414 | + tag_names: 1, | |
| 415 | + } | |
| 416 | + ); | |
| 417 | + } | |
| 418 | + | |
| 419 | + #[test] | |
| 420 | + fn bytes_round_trip() { | |
| 421 | + let map = sample(); | |
| 422 | + let bytes = map.to_bytes(); | |
| 423 | + let decoded = GitMap::from_bytes(&bytes).unwrap(); | |
| 424 | + assert_eq!(decoded, map); | |
| 425 | + assert_eq!(decoded.to_bytes(), bytes); | |
| 426 | + assert_eq!( | |
| 427 | + GitMap::from_bytes(&GitMap::new().to_bytes()).unwrap(), | |
| 428 | + GitMap::new() | |
| 429 | + ); | |
| 430 | + } | |
| 431 | + | |
| 432 | + #[test] | |
| 433 | + fn rejects_bad_encodings() { | |
| 434 | + let bytes = sample().to_bytes(); | |
| 435 | + for cut in 0..bytes.len() { | |
| 436 | + assert!(GitMap::from_bytes(&bytes[..cut]).is_err(), "cut at {cut}"); | |
| 437 | + } | |
| 438 | + let mut trailing = bytes.clone(); | |
| 439 | + trailing.push(0); | |
| 440 | + assert!(GitMap::from_bytes(&trailing).is_err()); | |
| 441 | + let mut version = bytes.clone(); | |
| 442 | + version[MAGIC.len()] = 2; | |
| 443 | + assert!(GitMap::from_bytes(&version).is_err()); | |
| 444 | + | |
| 445 | + // Two commits for one changeset. | |
| 446 | + let mut map = GitMap::new(); | |
| 447 | + map.commits.insert(oid(1), id("c")); | |
| 448 | + map.commits.insert(oid(2), id("c")); | |
| 449 | + assert!(GitMap::from_bytes(&map.to_bytes()).is_err()); | |
| 450 | + | |
| 451 | + // Two canonical trees for one braid tree. | |
| 452 | + let mut map = GitMap::new(); | |
| 453 | + map.trees.insert(oid(1), id("t")); | |
| 454 | + map.trees.insert(oid(2), id("t")); | |
| 455 | + assert!(GitMap::from_bytes(&map.to_bytes()).is_err()); | |
| 456 | + | |
| 457 | + // A raw tree that is not a tree, and a name for an unknown tag. | |
| 458 | + let mut map = GitMap::new(); | |
| 459 | + map.raw_trees.insert(oid(1), id("raw")); | |
| 460 | + assert!(GitMap::from_bytes(&map.to_bytes()).is_err()); | |
| 461 | + let mut map = GitMap::new(); | |
| 462 | + map.tag_names.insert(b"refs/tags/x".to_vec(), oid(9)); | |
| 463 | + assert!(GitMap::from_bytes(&map.to_bytes()).is_err()); | |
| 464 | + | |
| 465 | + // Keys out of order: swap the two commit rows. | |
| 466 | + let map = sample(); | |
| 467 | + let mut swapped = map.to_bytes(); | |
| 468 | + let start = MAGIC.len() + 1 + 1; | |
| 469 | + let row = 20 + 32; | |
| 470 | + let (first, second) = swapped[start..start + 2 * row].split_at_mut(row); | |
| 471 | + first.swap_with_slice(second); | |
| 472 | + assert!(GitMap::from_bytes(&swapped).is_err()); | |
| 473 | + } | |
| 474 | +} |
added crates/git/src/oid.rs +243 −0
| @@ -0,0 +1,243 @@ | ||
| 1 | +// SPDX-License-Identifier: Apache-2.0 | |
| 2 | +// Copyright (c) 2026 UtopiaIA | |
| 3 | + | |
| 4 | +//! Git object ids and kinds. | |
| 5 | + | |
| 6 | +use core::fmt; | |
| 7 | +use core::str::FromStr; | |
| 8 | + | |
| 9 | +use braid_format::GitId; | |
| 10 | + | |
| 11 | +use crate::error::Error; | |
| 12 | + | |
| 13 | +/// The four kinds of git object. | |
| 14 | +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | |
| 15 | +pub enum GitKind { | |
| 16 | + /// A commit. | |
| 17 | + Commit, | |
| 18 | + /// A directory listing. | |
| 19 | + Tree, | |
| 20 | + /// File content, or the target of a symlink. | |
| 21 | + Blob, | |
| 22 | + /// An annotated tag. | |
| 23 | + Tag, | |
| 24 | +} | |
| 25 | + | |
| 26 | +impl GitKind { | |
| 27 | + /// The name git writes in object headers: `commit`, `tree`, `blob` or `tag`. | |
| 28 | + pub const fn name(self) -> &'static str { | |
| 29 | + match self { | |
| 30 | + GitKind::Commit => "commit", | |
| 31 | + GitKind::Tree => "tree", | |
| 32 | + GitKind::Blob => "blob", | |
| 33 | + GitKind::Tag => "tag", | |
| 34 | + } | |
| 35 | + } | |
| 36 | + | |
| 37 | + /// The code used in serialized maps. | |
| 38 | + pub(crate) const fn code(self) -> u8 { | |
| 39 | + match self { | |
| 40 | + GitKind::Commit => 1, | |
| 41 | + GitKind::Tree => 2, | |
| 42 | + GitKind::Blob => 3, | |
| 43 | + GitKind::Tag => 4, | |
| 44 | + } | |
| 45 | + } | |
| 46 | + | |
| 47 | + /// The kind with this map code. | |
| 48 | + pub(crate) const fn from_code(code: u8) -> Option<Self> { | |
| 49 | + match code { | |
| 50 | + 1 => Some(GitKind::Commit), | |
| 51 | + 2 => Some(GitKind::Tree), | |
| 52 | + 3 => Some(GitKind::Blob), | |
| 53 | + 4 => Some(GitKind::Tag), | |
| 54 | + _ => None, | |
| 55 | + } | |
| 56 | + } | |
| 57 | + | |
| 58 | + pub(crate) fn to_gix(self) -> gix::objs::Kind { | |
| 59 | + match self { | |
| 60 | + GitKind::Commit => gix::objs::Kind::Commit, | |
| 61 | + GitKind::Tree => gix::objs::Kind::Tree, | |
| 62 | + GitKind::Blob => gix::objs::Kind::Blob, | |
| 63 | + GitKind::Tag => gix::objs::Kind::Tag, | |
| 64 | + } | |
| 65 | + } | |
| 66 | + | |
| 67 | + pub(crate) fn from_gix(kind: gix::objs::Kind) -> Self { | |
| 68 | + match kind { | |
| 69 | + gix::objs::Kind::Commit => GitKind::Commit, | |
| 70 | + gix::objs::Kind::Tree => GitKind::Tree, | |
| 71 | + gix::objs::Kind::Blob => GitKind::Blob, | |
| 72 | + gix::objs::Kind::Tag => GitKind::Tag, | |
| 73 | + } | |
| 74 | + } | |
| 75 | +} | |
| 76 | + | |
| 77 | +impl fmt::Display for GitKind { | |
| 78 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
| 79 | + f.write_str(self.name()) | |
| 80 | + } | |
| 81 | +} | |
| 82 | + | |
| 83 | +/// A git object id: the SHA-1 of the object's header and content. Its text | |
| 84 | +/// form is 40 lowercase hex digits. | |
| 85 | +#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] | |
| 86 | +pub struct GitOid([u8; 20]); | |
| 87 | + | |
| 88 | +impl GitOid { | |
| 89 | + /// Length of an id in bytes. | |
| 90 | + pub const LEN: usize = 20; | |
| 91 | + | |
| 92 | + /// Wraps raw id bytes. | |
| 93 | + pub const fn from_bytes(bytes: [u8; 20]) -> Self { | |
| 94 | + Self(bytes) | |
| 95 | + } | |
| 96 | + | |
| 97 | + /// The raw id bytes. | |
| 98 | + pub const fn as_bytes(&self) -> &[u8; 20] { | |
| 99 | + &self.0 | |
| 100 | + } | |
| 101 | + | |
| 102 | + /// The full text form: 40 lowercase hex digits. | |
| 103 | + pub fn to_hex(&self) -> String { | |
| 104 | + self.to_string() | |
| 105 | + } | |
| 106 | + | |
| 107 | + /// The id git gives an object of `kind` holding `data`. | |
| 108 | + /// | |
| 109 | + /// The hash runs with SHA-1 collision detection, as git's does: data that | |
| 110 | + /// carries a known collision attack gets an error instead of an id. | |
| 111 | + pub fn for_object(kind: GitKind, data: &[u8]) -> Result<Self, Error> { | |
| 112 | + let id = gix::objs::compute_hash(gix::hash::Kind::Sha1, kind.to_gix(), data) | |
| 113 | + .map_err(|_| Error::Collision { kind })?; | |
| 114 | + Ok(Self::from_gix(&id).expect("a SHA-1 hash has 20 bytes")) | |
| 115 | + } | |
| 116 | + | |
| 117 | + /// The id, if `id` is a SHA-1 id. | |
| 118 | + pub(crate) fn from_gix(id: &gix::oid) -> Option<Self> { | |
| 119 | + <[u8; 20]>::try_from(id.as_bytes()).ok().map(Self) | |
| 120 | + } | |
| 121 | + | |
| 122 | + pub(crate) fn to_gix(self) -> gix::ObjectId { | |
| 123 | + gix::ObjectId::Sha1(self.0) | |
| 124 | + } | |
| 125 | + | |
| 126 | + /// Parses 40 hex digits of either case, as found inside git objects. | |
| 127 | + pub(crate) fn parse_hex(digits: &[u8]) -> Option<Self> { | |
| 128 | + if digits.len() != 40 { | |
| 129 | + return None; | |
| 130 | + } | |
| 131 | + let mut bytes = [0u8; 20]; | |
| 132 | + for (byte, pair) in bytes.iter_mut().zip(digits.chunks_exact(2)) { | |
| 133 | + *byte = (hex_value(pair[0])? << 4) | hex_value(pair[1])?; | |
| 134 | + } | |
| 135 | + Some(Self(bytes)) | |
| 136 | + } | |
| 137 | +} | |
| 138 | + | |
| 139 | +fn hex_value(digit: u8) -> Option<u8> { | |
| 140 | + match digit { | |
| 141 | + b'0'..=b'9' => Some(digit - b'0'), | |
| 142 | + b'a'..=b'f' => Some(digit - b'a' + 10), | |
| 143 | + b'A'..=b'F' => Some(digit - b'A' + 10), | |
| 144 | + _ => None, | |
| 145 | + } | |
| 146 | +} | |
| 147 | + | |
| 148 | +const HEX_DIGITS: &[u8; 16] = b"0123456789abcdef"; | |
| 149 | + | |
| 150 | +impl fmt::Display for GitOid { | |
| 151 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
| 152 | + let mut text = [0u8; 40]; | |
| 153 | + for (i, byte) in self.0.iter().enumerate() { | |
| 154 | + text[2 * i] = HEX_DIGITS[usize::from(byte >> 4)]; | |
| 155 | + text[2 * i + 1] = HEX_DIGITS[usize::from(byte & 0x0f)]; | |
| 156 | + } | |
| 157 | + // Every byte written above is an ASCII hex digit. | |
| 158 | + f.write_str(core::str::from_utf8(&text).map_err(|_| fmt::Error)?) | |
| 159 | + } | |
| 160 | +} | |
| 161 | + | |
| 162 | +impl fmt::Debug for GitOid { | |
| 163 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
| 164 | + write!(f, "GitOid({self})") | |
| 165 | + } | |
| 166 | +} | |
| 167 | + | |
| 168 | +/// Why a string is not a git object id. | |
| 169 | +#[derive(Clone, Debug, PartialEq, Eq)] | |
| 170 | +pub struct ParseGitOidError; | |
| 171 | + | |
| 172 | +impl fmt::Display for ParseGitOidError { | |
| 173 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | |
| 174 | + f.write_str("a git object id is 40 lowercase hex digits") | |
| 175 | + } | |
| 176 | +} | |
| 177 | + | |
| 178 | +impl std::error::Error for ParseGitOidError {} | |
| 179 | + | |
| 180 | +impl FromStr for GitOid { | |
| 181 | + type Err = ParseGitOidError; | |
| 182 | + | |
| 183 | + /// Parses the 40-digit form. Only lowercase is accepted, so two equal ids | |
| 184 | + /// always have equal text. | |
| 185 | + fn from_str(text: &str) -> Result<Self, Self::Err> { | |
| 186 | + if text.bytes().any(|b| b.is_ascii_uppercase()) { | |
| 187 | + return Err(ParseGitOidError); | |
| 188 | + } | |
| 189 | + Self::parse_hex(text.as_bytes()).ok_or(ParseGitOidError) | |
| 190 | + } | |
| 191 | +} | |
| 192 | + | |
| 193 | +impl From<GitOid> for GitId { | |
| 194 | + fn from(oid: GitOid) -> Self { | |
| 195 | + GitId::Sha1(oid.0) | |
| 196 | + } | |
| 197 | +} | |
| 198 | + | |
| 199 | +#[cfg(test)] | |
| 200 | +mod tests { | |
| 201 | + use super::*; | |
| 202 | + | |
| 203 | + #[test] | |
| 204 | + fn well_known_ids() { | |
| 205 | + // The empty blob and the empty tree have ids every git user has seen. | |
| 206 | + assert_eq!( | |
| 207 | + GitOid::for_object(GitKind::Blob, b"").unwrap().to_hex(), | |
| 208 | + "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" | |
| 209 | + ); | |
| 210 | + assert_eq!( | |
| 211 | + GitOid::for_object(GitKind::Tree, b"").unwrap().to_hex(), | |
| 212 | + "4b825dc642cb6eb9a060e54bf8d69288fbee4904" | |
| 213 | + ); | |
| 214 | + assert_eq!( | |
| 215 | + GitOid::for_object(GitKind::Blob, b"hello\n") | |
| 216 | + .unwrap() | |
| 217 | + .to_hex(), | |
| 218 | + "ce013625030ba8dba906f756967f9e9ca394464a" | |
| 219 | + ); | |
| 220 | + } | |
| 221 | + | |
| 222 | + #[test] | |
| 223 | + fn text_round_trip() { | |
| 224 | + let oid = GitOid::for_object(GitKind::Blob, b"x").unwrap(); | |
| 225 | + let text = oid.to_hex(); | |
| 226 | + assert_eq!(text.parse::<GitOid>(), Ok(oid)); | |
| 227 | + assert_eq!(format!("{oid:?}"), format!("GitOid({text})")); | |
| 228 | + assert_eq!(text.to_uppercase().parse::<GitOid>(), Err(ParseGitOidError)); | |
| 229 | + assert_eq!(GitOid::parse_hex(text.to_uppercase().as_bytes()), Some(oid)); | |
| 230 | + assert_eq!(text[..39].parse::<GitOid>(), Err(ParseGitOidError)); | |
| 231 | + assert_eq!(GitOid::parse_hex(b"zz"), None); | |
| 232 | + } | |
| 233 | + | |
| 234 | + #[test] | |
| 235 | + fn kind_codes_round_trip() { | |
| 236 | + for kind in [GitKind::Commit, GitKind::Tree, GitKind::Blob, GitKind::Tag] { | |
| 237 | + assert_eq!(GitKind::from_code(kind.code()), Some(kind)); | |
| 238 | + assert_eq!(GitKind::from_gix(kind.to_gix()), kind); | |
| 239 | + } | |
| 240 | + assert_eq!(GitKind::from_code(0), None); | |
| 241 | + assert_eq!(GitKind::from_code(5), None); | |
| 242 | + } | |
| 243 | +} |
added crates/git/src/raw.rs +625 −0
| @@ -0,0 +1,625 @@ | ||
| 1 | +// SPDX-License-Identifier: Apache-2.0 | |
| 2 | +// Copyright (c) 2026 UtopiaIA | |
| 3 | + | |
| 4 | +//! The raw bytes of git objects: the few fields braid reads from them, and the | |
| 5 | +//! canonical form it writes. | |
| 6 | +//! | |
| 7 | +//! Braid keeps the original bytes of every imported commit and tag, and of | |
| 8 | +//! every tree it cannot regenerate exactly, so these parsers only need the | |
| 9 | +//! fields that link objects together and the fields a changeset records. They | |
| 10 | +//! are total where they can be: odd author lines or extra headers never stop an | |
| 11 | +//! import, because the original bytes travel with the changeset. | |
| 12 | +//! | |
| 13 | +//! Written from git's documented object format; no code comes from git. | |
| 14 | + | |
| 15 | +use core::cmp::Ordering; | |
| 16 | + | |
| 17 | +use braid_format::Signature; | |
| 18 | + | |
| 19 | +use crate::oid::GitOid; | |
| 20 | + | |
| 21 | +/// What a git tree entry is, by the file type bits of its mode. | |
| 22 | +#[derive(Clone, Copy, Debug, PartialEq, Eq)] | |
| 23 | +pub enum EntryType { | |
| 24 | + /// A regular file. | |
| 25 | + File, | |
| 26 | + /// A regular file the owner may execute. | |
| 27 | + Executable, | |
| 28 | + /// A symlink; its blob is the target. | |
| 29 | + Symlink, | |
| 30 | + /// A directory. | |
| 31 | + Tree, | |
| 32 | + /// A submodule commit. | |
| 33 | + Gitlink, | |
| 34 | +} | |
| 35 | + | |
| 36 | +impl EntryType { | |
| 37 | + /// The type of an entry with this mode, written in octal as in a tree. | |
| 38 | + /// A regular file is executable when the owner may execute it, so a | |
| 39 | + /// non-canonical mode such as `100664` still has a type; `None` means the | |
| 40 | + /// file type bits name nothing git can store. | |
| 41 | + pub fn from_mode(mode: &[u8]) -> Option<EntryType> { | |
| 42 | + let value = parse_octal(mode)?; | |
| 43 | + match value & 0o170_000 { | |
| 44 | + 0o100_000 if value & 0o100 != 0 => Some(EntryType::Executable), | |
| 45 | + 0o100_000 => Some(EntryType::File), | |
| 46 | + 0o120_000 => Some(EntryType::Symlink), | |
| 47 | + 0o040_000 => Some(EntryType::Tree), | |
| 48 | + 0o160_000 => Some(EntryType::Gitlink), | |
| 49 | + _ => None, | |
| 50 | + } | |
| 51 | + } | |
| 52 | + | |
| 53 | + /// The mode git writes for this type. | |
| 54 | + pub(crate) const fn canonical_mode(self) -> &'static [u8] { | |
| 55 | + match self { | |
| 56 | + EntryType::File => b"100644", | |
| 57 | + EntryType::Executable => b"100755", | |
| 58 | + EntryType::Symlink => b"120000", | |
| 59 | + EntryType::Tree => b"40000", | |
| 60 | + EntryType::Gitlink => b"160000", | |
| 61 | + } | |
| 62 | + } | |
| 63 | +} | |
| 64 | + | |
| 65 | +fn parse_octal(digits: &[u8]) -> Option<u32> { | |
| 66 | + if digits.is_empty() { | |
| 67 | + return None; | |
| 68 | + } | |
| 69 | + digits.iter().try_fold(0u32, |value, digit| match digit { | |
| 70 | + b'0'..=b'7' => value.checked_mul(8)?.checked_add(u32::from(digit - b'0')), | |
| 71 | + _ => None, | |
| 72 | + }) | |
| 73 | +} | |
| 74 | + | |
| 75 | +/// One entry of a git tree, as written. | |
| 76 | +#[derive(Clone, Copy, Debug, PartialEq, Eq)] | |
| 77 | +pub struct RawEntry<'a> { | |
| 78 | + /// The mode, in octal digits. | |
| 79 | + pub mode: &'a [u8], | |
| 80 | + /// The name. | |
| 81 | + pub name: &'a [u8], | |
| 82 | + /// The object the entry names. | |
| 83 | + pub oid: GitOid, | |
| 84 | +} | |
| 85 | + | |
| 86 | +/// Splits a tree into its entries, in the order they are written. | |
| 87 | +pub fn parse_tree(data: &[u8]) -> Result<Vec<RawEntry<'_>>, &'static str> { | |
| 88 | + let mut entries = Vec::new(); | |
| 89 | + let mut rest = data; | |
| 90 | + while !rest.is_empty() { | |
| 91 | + let space = find_byte(rest, b' ').ok_or("an entry has no space after its mode")?; | |
| 92 | + let mode = &rest[..space]; | |
| 93 | + let after = &rest[space + 1..]; | |
| 94 | + let nul = find_byte(after, 0).ok_or("an entry name has no terminating NUL")?; | |
| 95 | + let name = &after[..nul]; | |
| 96 | + let id: [u8; 20] = after | |
| 97 | + .get(nul + 1..nul + 1 + GitOid::LEN) | |
| 98 | + .and_then(|bytes| bytes.try_into().ok()) | |
| 99 | + .ok_or("an entry id is cut short")?; | |
| 100 | + entries.push(RawEntry { | |
| 101 | + mode, | |
| 102 | + name, | |
| 103 | + oid: GitOid::from_bytes(id), | |
| 104 | + }); | |
| 105 | + rest = &after[nul + 1 + GitOid::LEN..]; | |
| 106 | + } | |
| 107 | + Ok(entries) | |
| 108 | +} | |
| 109 | + | |
| 110 | +/// One entry of a tree to write. | |
| 111 | +#[derive(Clone, Copy, Debug)] | |
| 112 | +pub(crate) struct TreeItem<'a> { | |
| 113 | + pub kind: EntryType, | |
| 114 | + pub name: &'a [u8], | |
| 115 | + pub oid: GitOid, | |
| 116 | +} | |
| 117 | + | |
| 118 | +/// Writes a tree as git does: canonical modes, and entries sorted by name | |
| 119 | +/// bytes with a directory compared as if its name ended in `/`. | |
| 120 | +pub(crate) fn encode_tree(items: &mut [TreeItem<'_>]) -> Vec<u8> { | |
| 121 | + items.sort_by(|a, b| { | |
| 122 | + git_order( | |
| 123 | + a.name, | |
| 124 | + a.kind == EntryType::Tree, | |
| 125 | + b.name, | |
| 126 | + b.kind == EntryType::Tree, | |
| 127 | + ) | |
| 128 | + }); | |
| 129 | + let size = items | |
| 130 | + .iter() | |
| 131 | + .map(|item| item.kind.canonical_mode().len() + item.name.len() + 2 + GitOid::LEN) | |
| 132 | + .sum(); | |
| 133 | + let mut out = Vec::with_capacity(size); | |
| 134 | + for item in items.iter() { | |
| 135 | + out.extend_from_slice(item.kind.canonical_mode()); | |
| 136 | + out.push(b' '); | |
| 137 | + out.extend_from_slice(item.name); | |
| 138 | + out.push(0); | |
| 139 | + out.extend_from_slice(item.oid.as_bytes()); | |
| 140 | + } | |
| 141 | + out | |
| 142 | +} | |
| 143 | + | |
| 144 | +/// Git's order of tree entries: by name bytes, with a directory's name | |
| 145 | +/// followed by `/`. | |
| 146 | +pub(crate) fn git_order(a: &[u8], a_dir: bool, b: &[u8], b_dir: bool) -> Ordering { | |
| 147 | + let common = a.len().min(b.len()); | |
| 148 | + a[..common].cmp(&b[..common]).then_with(|| { | |
| 149 | + let next = |name: &[u8], dir: bool| name.get(common).copied().or(dir.then_some(b'/')); | |
| 150 | + next(a, a_dir).cmp(&next(b, b_dir)) | |
| 151 | + }) | |
| 152 | +} | |
| 153 | + | |
| 154 | +/// The fields of a commit that braid reads. | |
| 155 | +#[derive(Clone, Debug, PartialEq, Eq)] | |
| 156 | +pub struct CommitFields<'a> { | |
| 157 | + /// The tree. | |
| 158 | + pub tree: GitOid, | |
| 159 | + /// The parents, in order. | |
| 160 | + pub parents: Vec<GitOid>, | |
| 161 | + /// The value of the first `author` header. | |
| 162 | + pub author: Option<&'a [u8]>, | |
| 163 | + /// The value of the first `committer` header. | |
| 164 | + pub committer: Option<&'a [u8]>, | |
| 165 | + /// Everything after the first empty line. | |
| 166 | + pub message: &'a [u8], | |
| 167 | +} | |
| 168 | + | |
| 169 | +/// Splits an object at its first empty line into the header lines (each one | |
| 170 | +/// ending in a newline) and the message. | |
| 171 | +fn split_message(data: &[u8]) -> (&[u8], &[u8]) { | |
| 172 | + if data.first() == Some(&b'\n') { | |
| 173 | + return (&[], &data[1..]); | |
| 174 | + } | |
| 175 | + match data.windows(2).position(|pair| pair == b"\n\n") { | |
| 176 | + Some(end) => (&data[..end + 1], &data[end + 2..]), | |
| 177 | + None => (data, &[]), | |
| 178 | + } | |
| 179 | +} | |
| 180 | + | |
| 181 | +/// The header lines as key and value. Continuation lines, which start with a | |
| 182 | +/// space and belong to a multi-line header such as a signature, are skipped. | |
| 183 | +fn header_lines(headers: &[u8]) -> impl Iterator<Item = (&[u8], &[u8])> { | |
| 184 | + headers | |
| 185 | + .split(|byte| *byte == b'\n') | |
| 186 | + .filter(|line| line.first().is_some_and(|byte| *byte != b' ')) | |
| 187 | + .map(|line| match find_byte(line, b' ') { | |
| 188 | + Some(space) => (&line[..space], &line[space + 1..]), | |
| 189 | + None => (line, &line[line.len()..]), | |
| 190 | + }) | |
| 191 | +} | |
| 192 | + | |
| 193 | +/// Reads the tree, the parents, the author and committer lines and the | |
| 194 | +/// message of a commit. | |
| 195 | +/// | |
| 196 | +/// The tree is the first header and the parents are the `parent` headers right | |
| 197 | +/// after it. The author and committer are the first headers with those names, | |
| 198 | +/// wherever they are; the message is everything after the first empty line. | |
| 199 | +pub fn parse_commit(data: &[u8]) -> Result<CommitFields<'_>, &'static str> { | |
| 200 | + let (headers, message) = split_message(data); | |
| 201 | + let mut lines = header_lines(headers).peekable(); | |
| 202 | + let tree = match lines.next() { | |
| 203 | + Some((b"tree", value)) => { | |
| 204 | + GitOid::parse_hex(value).ok_or("the tree header does not hold an object id")? | |
| 205 | + } | |
| 206 | + _ => return Err("the first header is not a tree"), | |
| 207 | + }; | |
| 208 | + let mut parents = Vec::new(); | |
| 209 | + while let Some((b"parent", value)) = lines.peek() { | |
| 210 | + parents.push(GitOid::parse_hex(value).ok_or("a parent header does not hold an object id")?); | |
| 211 | + lines.next(); | |
| 212 | + } | |
| 213 | + let mut author = None; | |
| 214 | + let mut committer = None; | |
| 215 | + for (key, value) in lines { | |
| 216 | + match key { | |
| 217 | + b"author" if author.is_none() => author = Some(value), | |
| 218 | + b"committer" if committer.is_none() => committer = Some(value), | |
| 219 | + _ => {} | |
| 220 | + } | |
| 221 | + } | |
| 222 | + Ok(CommitFields { | |
| 223 | + tree, | |
| 224 | + parents, | |
| 225 | + author, | |
| 226 | + committer, | |
| 227 | + message, | |
| 228 | + }) | |
| 229 | +} | |
| 230 | + | |
| 231 | +/// Reads the object an annotated tag points to: its first header. | |
| 232 | +pub fn parse_tag(data: &[u8]) -> Result<GitOid, &'static str> { | |
| 233 | + let (headers, _) = split_message(data); | |
| 234 | + match header_lines(headers).next() { | |
| 235 | + Some((b"object", value)) => { | |
| 236 | + GitOid::parse_hex(value).ok_or("the object header does not hold an object id") | |
| 237 | + } | |
| 238 | + _ => Err("the first header is not an object"), | |
| 239 | + } | |
| 240 | +} | |
| 241 | + | |
| 242 | +/// Reads an author or committer line: `Name <email> seconds ±HHMM`. | |
| 243 | +/// | |
| 244 | +/// The rule is fixed, because these fields are hashed into the changeset id: | |
| 245 | +/// | |
| 246 | +/// - The name is everything before the first `<`, without surrounding ASCII | |
| 247 | +/// whitespace; the email is everything between it and the next `>`. | |
| 248 | +/// - After the `>`, the first word is the time in seconds and the second the | |
| 249 | +/// offset as `±HHMM`. A missing or unreadable value is 0. | |
| 250 | +/// - A line without `<` and a later `>` is all name, with no email and time 0. | |
| 251 | +/// | |
| 252 | +/// Nothing is lost: the original line stays in the commit bytes. | |
| 253 | +pub fn parse_signature(line: &[u8]) -> Signature { | |
| 254 | + let parts = find_byte(line, b'<').and_then(|open| { | |
| 255 | + let close = open + 1 + find_byte(&line[open + 1..], b'>')?; | |
| 256 | + Some((&line[..open], &line[open + 1..close], &line[close + 1..])) | |
| 257 | + }); | |
| 258 | + let Some((name, email, rest)) = parts else { | |
| 259 | + return Signature { | |
| 260 | + name: line.trim_ascii().to_vec(), | |
| 261 | + email: Vec::new(), | |
| 262 | + seconds: 0, | |
| 263 | + offset_minutes: 0, | |
| 264 | + }; | |
| 265 | + }; | |
| 266 | + let mut words = rest | |
| 267 | + .split(|byte| byte.is_ascii_whitespace()) | |
| 268 | + .filter(|word| !word.is_empty()); | |
| 269 | + let seconds = words.next().and_then(parse_decimal).unwrap_or(0); | |
| 270 | + let offset_minutes = words.next().and_then(parse_offset).unwrap_or(0); | |
| 271 | + Signature { | |
| 272 | + name: name.trim_ascii().to_vec(), | |
| 273 | + email: email.to_vec(), | |
| 274 | + seconds, | |
| 275 | + offset_minutes, | |
| 276 | + } | |
| 277 | +} | |
| 278 | + | |
| 279 | +/// An optional sign followed by decimal digits, if it fits in an `i64`. | |
| 280 | +fn parse_decimal(word: &[u8]) -> Option<i64> { | |
| 281 | + let (negative, digits) = match word.split_first() { | |
| 282 | + Some((b'-', rest)) => (true, rest), | |
| 283 | + Some((b'+', rest)) => (false, rest), | |
| 284 | + _ => (false, word), | |
| 285 | + }; | |
| 286 | + if digits.is_empty() { | |
| 287 | + return None; | |
| 288 | + } | |
| 289 | + let magnitude = digits.iter().try_fold(0i64, |value, digit| match digit { | |
| 290 | + b'0'..=b'9' => value.checked_mul(10)?.checked_add(i64::from(digit - b'0')), | |
| 291 | + _ => None, | |
| 292 | + })?; | |
| 293 | + Some(if negative { -magnitude } else { magnitude }) | |
| 294 | +} | |
| 295 | + | |
| 296 | +/// `±HHMM` as minutes. | |
| 297 | +fn parse_offset(word: &[u8]) -> Option<i64> { | |
| 298 | + let value = parse_decimal(word)?; | |
| 299 | + let minutes = (value.abs() / 100) | |
| 300 | + .checked_mul(60)? | |
| 301 | + .checked_add(value.abs() % 100)?; | |
| 302 | + Some(if value < 0 { -minutes } else { minutes }) | |
| 303 | +} | |
| 304 | + | |
| 305 | +/// Appends `key Name <email> seconds ±HHMM` and a newline. | |
| 306 | +fn write_signature(out: &mut Vec<u8>, key: &[u8], signature: &Signature) -> Result<(), String> { | |
| 307 | + let forbidden = |byte: &u8| matches!(byte, b'<' | b'>' | b'\n' | 0); | |
| 308 | + if signature.name.iter().any(forbidden) { | |
| 309 | + return Err("a name holds '<', '>', a newline or NUL".into()); | |
| 310 | + } | |
| 311 | + if signature.email.iter().any(forbidden) { | |
| 312 | + return Err("an email holds '<', '>', a newline or NUL".into()); | |
| 313 | + } | |
| 314 | + let magnitude = signature.offset_minutes.unsigned_abs(); | |
| 315 | + if magnitude / 60 > 99 { | |
| 316 | + return Err(format!( | |
| 317 | + "the offset of {} minutes does not fit in ±HHMM", | |
| 318 | + signature.offset_minutes | |
| 319 | + )); | |
| 320 | + } | |
| 321 | + out.extend_from_slice(key); | |
| 322 | + out.push(b' '); | |
| 323 | + out.extend_from_slice(&signature.name); | |
| 324 | + out.extend_from_slice(b" <"); | |
| 325 | + out.extend_from_slice(&signature.email); | |
| 326 | + out.extend_from_slice(b"> "); | |
| 327 | + out.extend_from_slice(signature.seconds.to_string().as_bytes()); | |
| 328 | + let sign = if signature.offset_minutes < 0 { | |
| 329 | + '-' | |
| 330 | + } else { | |
| 331 | + '+' | |
| 332 | + }; | |
| 333 | + let offset = format!(" {sign}{:02}{:02}\n", magnitude / 60, magnitude % 60); | |
| 334 | + out.extend_from_slice(offset.as_bytes()); | |
| 335 | + Ok(()) | |
| 336 | +} | |
| 337 | + | |
| 338 | +/// The headers a commit generated by braid writes itself, which an extra must | |
| 339 | +/// not repeat. | |
| 340 | +const RESERVED_HEADERS: [&[u8]; 4] = [b"tree", b"parent", b"author", b"committer"]; | |
| 341 | + | |
| 342 | +/// Writes a commit for a changeset that did not come from git. | |
| 343 | +/// | |
| 344 | +/// The headers are `tree`, `parent` for each parent, `author`, `committer`, | |
| 345 | +/// then one header per extra in order, a multi-line value continuing on lines | |
| 346 | +/// that start with a space; then an empty line and the message, unchanged. | |
| 347 | +pub fn encode_commit( | |
| 348 | + tree: GitOid, | |
| 349 | + parents: &[GitOid], | |
| 350 | + author: &Signature, | |
| 351 | + committer: &Signature, | |
| 352 | + extras: &[(Vec<u8>, Vec<u8>)], | |
| 353 | + message: &[u8], | |
| 354 | +) -> Result<Vec<u8>, String> { | |
| 355 | + let mut out = Vec::with_capacity(256 + message.len()); | |
| 356 | + out.extend_from_slice(b"tree "); | |
| 357 | + out.extend_from_slice(tree.to_hex().as_bytes()); | |
| 358 | + out.push(b'\n'); | |
| 359 | + for parent in parents { | |
| 360 | + out.extend_from_slice(b"parent "); | |
| 361 | + out.extend_from_slice(parent.to_hex().as_bytes()); | |
| 362 | + out.push(b'\n'); | |
| 363 | + } | |
| 364 | + write_signature(&mut out, b"author", author)?; | |
| 365 | + write_signature(&mut out, b"committer", committer)?; | |
| 366 | + for (key, value) in extras { | |
| 367 | + if key.is_empty() | |
| 368 | + || key.iter().any(|byte| matches!(byte, b' ' | b'\n' | 0)) | |
| 369 | + || RESERVED_HEADERS.contains(&key.as_slice()) | |
| 370 | + { | |
| 371 | + return Err(format!( | |
| 372 | + "the extra {:?} cannot be a header", | |
| 373 | + String::from_utf8_lossy(key) | |
| 374 | + )); | |
| 375 | + } | |
| 376 | + if value.contains(&0) { | |
| 377 | + return Err(format!( | |
| 378 | + "the extra {:?} holds a NUL byte", | |
| 379 | + String::from_utf8_lossy(key) | |
| 380 | + )); | |
| 381 | + } | |
| 382 | + out.extend_from_slice(key); | |
| 383 | + out.push(b' '); | |
| 384 | + for (index, line) in value.split(|byte| *byte == b'\n').enumerate() { | |
| 385 | + if index > 0 { | |
| 386 | + out.extend_from_slice(b"\n "); | |
| 387 | + } | |
| 388 | + out.extend_from_slice(line); | |
| 389 | + } | |
| 390 | + out.push(b'\n'); | |
| 391 | + } | |
| 392 | + out.push(b'\n'); | |
| 393 | + out.extend_from_slice(message); | |
| 394 | + Ok(out) | |
| 395 | +} | |
| 396 | + | |
| 397 | +fn find_byte(haystack: &[u8], needle: u8) -> Option<usize> { | |
| 398 | + haystack.iter().position(|byte| *byte == needle) | |
| 399 | +} | |
| 400 | + | |
| 401 | +#[cfg(test)] | |
| 402 | +mod tests { | |
| 403 | + use super::*; | |
| 404 | + | |
| 405 | + fn oid(byte: u8) -> GitOid { | |
| 406 | + GitOid::from_bytes([byte; 20]) | |
| 407 | + } | |
| 408 | + | |
| 409 | + #[test] | |
| 410 | + fn modes() { | |
| 411 | + use EntryType::*; | |
| 412 | + let cases: &[(&[u8], Option<EntryType>)] = &[ | |
| 413 | + (b"100644", Some(File)), | |
| 414 | + (b"100664", Some(File)), | |
| 415 | + (b"100600", Some(File)), | |
| 416 | + (b"0100644", Some(File)), | |
| 417 | + (b"100755", Some(Executable)), | |
| 418 | + (b"100775", Some(Executable)), | |
| 419 | + (b"100700", Some(Executable)), | |
| 420 | + (b"120000", Some(Symlink)), | |
| 421 | + (b"40000", Some(Tree)), | |
| 422 | + (b"040000", Some(Tree)), | |
| 423 | + (b"160000", Some(Gitlink)), | |
| 424 | + (b"", None), | |
| 425 | + (b"100648", None), | |
| 426 | + (b"777777777777", None), | |
| 427 | + (b"20000", None), | |
| 428 | + (b"0", None), | |
| 429 | + ]; | |
| 430 | + for (mode, expected) in cases { | |
| 431 | + assert_eq!( | |
| 432 | + EntryType::from_mode(mode), | |
| 433 | + *expected, | |
| 434 | + "{}", | |
| 435 | + String::from_utf8_lossy(mode) | |
| 436 | + ); | |
| 437 | + } | |
| 438 | + for kind in [File, Executable, Symlink, Tree, Gitlink] { | |
| 439 | + assert_eq!(EntryType::from_mode(kind.canonical_mode()), Some(kind)); | |
| 440 | + } | |
| 441 | + } | |
| 442 | + | |
| 443 | + #[test] | |
| 444 | + fn git_orders_directories_as_if_they_ended_in_a_slash() { | |
| 445 | + use Ordering::*; | |
| 446 | + assert_eq!(git_order(b"a", false, b"b", false), Less); | |
| 447 | + assert_eq!(git_order(b"a.c", false, b"a", true), Less); // "a.c" < "a/" | |
| 448 | + assert_eq!(git_order(b"a", true, b"a0", false), Less); // "a/" < "a0" | |
| 449 | + assert_eq!(git_order(b"a", false, b"a.c", false), Less); | |
| 450 | + assert_eq!(git_order(b"a", false, b"a", true), Less); | |
| 451 | + assert_eq!(git_order(b"ab", true, b"a", true), Greater); | |
| 452 | + let mut items = [ | |
| 453 | + TreeItem { | |
| 454 | + kind: EntryType::Tree, | |
| 455 | + name: b"a", | |
| 456 | + oid: oid(1), | |
| 457 | + }, | |
| 458 | + TreeItem { | |
| 459 | + kind: EntryType::File, | |
| 460 | + name: b"a.c", | |
| 461 | + oid: oid(2), | |
| 462 | + }, | |
| 463 | + TreeItem { | |
| 464 | + kind: EntryType::File, | |
| 465 | + name: b"a0", | |
| 466 | + oid: oid(3), | |
| 467 | + }, | |
| 468 | + ]; | |
| 469 | + let bytes = encode_tree(&mut items); | |
| 470 | + let names: Vec<&[u8]> = parse_tree(&bytes).unwrap().iter().map(|e| e.name).collect(); | |
| 471 | + assert_eq!(names, [&b"a.c"[..], b"a", b"a0"]); | |
| 472 | + } | |
| 473 | + | |
| 474 | + #[test] | |
| 475 | + fn tree_round_trip_and_errors() { | |
| 476 | + let mut items = [ | |
| 477 | + TreeItem { | |
| 478 | + kind: EntryType::Executable, | |
| 479 | + name: b"run", | |
| 480 | + oid: oid(7), | |
| 481 | + }, | |
| 482 | + TreeItem { | |
| 483 | + kind: EntryType::Gitlink, | |
| 484 | + name: b"sub", | |
| 485 | + oid: oid(8), | |
| 486 | + }, | |
| 487 | + ]; | |
| 488 | + let bytes = encode_tree(&mut items); | |
| 489 | + assert!(bytes.starts_with(b"100755 run\0")); | |
| 490 | + let entries = parse_tree(&bytes).unwrap(); | |
| 491 | + assert_eq!(entries.len(), 2); | |
| 492 | + assert_eq!(entries[1].mode, b"160000"); | |
| 493 | + assert_eq!(entries[1].oid, oid(8)); | |
| 494 | + assert!(parse_tree(b"").unwrap().is_empty()); | |
| 495 | + assert!(parse_tree(b"100644").is_err()); | |
| 496 | + assert!(parse_tree(b"100644 name").is_err()); | |
| 497 | + assert!(parse_tree(&bytes[..bytes.len() - 1]).is_err()); | |
| 498 | + } | |
| 499 | + | |
| 500 | + #[test] | |
| 501 | + fn commits() { | |
| 502 | + let tree = oid(0xaa).to_hex(); | |
| 503 | + let parent = oid(0xbb).to_hex(); | |
| 504 | + let text = format!( | |
| 505 | + "tree {tree}\nparent {parent}\nparent {}\nauthor A U Thor <a@example.org> 1700000000 +0130\n\ | |
| 506 | + committer C O Mitter <c@example.org> 1700000001 -0800\nencoding ISO-8859-1\n\ | |
| 507 | + gpgsig -----BEGIN-----\n \n line\n -----END-----\n\nsubject\n\nbody\n", | |
| 508 | + parent.to_uppercase() | |
| 509 | + ); | |
| 510 | + let fields = parse_commit(text.as_bytes()).unwrap(); | |
| 511 | + assert_eq!(fields.tree, oid(0xaa)); | |
| 512 | + assert_eq!(fields.parents, [oid(0xbb), oid(0xbb)]); | |
| 513 | + assert_eq!( | |
| 514 | + parse_signature(fields.author.unwrap()), | |
| 515 | + Signature { | |
| 516 | + name: b"A U Thor".to_vec(), | |
| 517 | + email: b"a@example.org".to_vec(), | |
| 518 | + seconds: 1_700_000_000, | |
| 519 | + offset_minutes: 90, | |
| 520 | + } | |
| 521 | + ); | |
| 522 | + assert_eq!( | |
| 523 | + parse_signature(fields.committer.unwrap()).offset_minutes, | |
| 524 | + -480 | |
| 525 | + ); | |
| 526 | + assert_eq!(fields.message, b"subject\n\nbody\n"); | |
| 527 | + | |
| 528 | + // No message at all, and an empty one. | |
| 529 | + let bare = format!("tree {tree}\nauthor x <y> 1 +0000\n"); | |
| 530 | + assert_eq!(parse_commit(bare.as_bytes()).unwrap().message, b""); | |
| 531 | + let empty = format!("tree {tree}\n\n"); | |
| 532 | + let fields = parse_commit(empty.as_bytes()).unwrap(); | |
| 533 | + assert_eq!(fields.message, b""); | |
| 534 | + assert_eq!(fields.author, None); | |
| 535 | + | |
| 536 | + // A parent after another header is not a parent. | |
| 537 | + let late = format!("tree {tree}\nauthor x <y> 1 +0000\nparent {parent}\n\n"); | |
| 538 | + assert!(parse_commit(late.as_bytes()).unwrap().parents.is_empty()); | |
| 539 | + | |
| 540 | + assert!(parse_commit(b"").is_err()); | |
| 541 | + assert!(parse_commit(b"parent x\n").is_err()); | |
| 542 | + assert!(parse_commit(b"tree 1234\n").is_err()); | |
| 543 | + } | |
| 544 | + | |
| 545 | + /// Name, email, seconds and offset. | |
| 546 | + type Expected<'a> = (&'a [u8], &'a [u8], i64, i64); | |
| 547 | + | |
| 548 | + #[test] | |
| 549 | + fn odd_signatures_never_fail() { | |
| 550 | + let cases: &[(&[u8], Expected<'_>)] = &[ | |
| 551 | + (b"Name <e> 5 +0000", (b"Name", b"e", 5, 0)), | |
| 552 | + (b"Name<e>5 -0130", (b"Name", b"e", 5, -90)), | |
| 553 | + (b" Spaced <e> 7 +0200 ", (b"Spaced", b"e", 7, 120)), | |
| 554 | + (b"<> 0 +0000", (b"", b"", 0, 0)), | |
| 555 | + (b"No email at all", (b"No email at all", b"", 0, 0)), | |
| 556 | + (b"Open <bracket only", (b"Open <bracket only", b"", 0, 0)), | |
| 557 | + (b"Name <e>", (b"Name", b"e", 0, 0)), | |
| 558 | + (b"Name <e> garbage +0100", (b"Name", b"e", 0, 60)), | |
| 559 | + (b"Name <e> -5 +0000", (b"Name", b"e", -5, 0)), | |
| 560 | + ( | |
| 561 | + b"Name <e> 99999999999999999999 +0000", | |
| 562 | + (b"Name", b"e", 0, 0), | |
| 563 | + ), | |
| 564 | + (b"Name <e> 1 +05030", (b"Name", b"e", 1, 3030)), | |
| 565 | + // The email ends at the first '>'; the next words are read as | |
| 566 | + // they come, so "b>" is an unreadable time and "1" the offset. | |
| 567 | + (b"Name <a> b> 1 +0000", (b"Name", b"a", 0, 1)), | |
| 568 | + ]; | |
| 569 | + for (line, (name, email, seconds, offset)) in cases { | |
| 570 | + let signature = parse_signature(line); | |
| 571 | + assert_eq!( | |
| 572 | + ( | |
| 573 | + signature.name.as_slice(), | |
| 574 | + signature.email.as_slice(), | |
| 575 | + signature.seconds, | |
| 576 | + signature.offset_minutes | |
| 577 | + ), | |
| 578 | + (*name, *email, *seconds, *offset), | |
| 579 | + "{}", | |
| 580 | + String::from_utf8_lossy(line) | |
| 581 | + ); | |
| 582 | + } | |
| 583 | + } | |
| 584 | + | |
| 585 | + #[test] | |
| 586 | + fn generated_commits_read_back() { | |
| 587 | + let author = Signature { | |
| 588 | + name: b"Ada Lovelace".to_vec(), | |
| 589 | + email: b"ada@example.org".to_vec(), | |
| 590 | + seconds: 1_700_000_000, | |
| 591 | + offset_minutes: -330, | |
| 592 | + }; | |
| 593 | + let extras = vec![(b"x-note".to_vec(), b"one\ntwo".to_vec())]; | |
| 594 | + let bytes = encode_commit(oid(1), &[oid(2)], &author, &author, &extras, b"msg\n").unwrap(); | |
| 595 | + let text = String::from_utf8(bytes.clone()).unwrap(); | |
| 596 | + assert!(text.contains("author Ada Lovelace <ada@example.org> 1700000000 -0530\n")); | |
| 597 | + assert!(text.contains("x-note one\n two\n\nmsg\n")); | |
| 598 | + let fields = parse_commit(&bytes).unwrap(); | |
| 599 | + assert_eq!(fields.tree, oid(1)); | |
| 600 | + assert_eq!(fields.parents, [oid(2)]); | |
| 601 | + assert_eq!(parse_signature(fields.author.unwrap()), author); | |
| 602 | + assert_eq!(fields.message, b"msg\n"); | |
| 603 | + | |
| 604 | + let mut bad = author.clone(); | |
| 605 | + bad.name = b"a <b>".to_vec(); | |
| 606 | + assert!(encode_commit(oid(1), &[], &bad, &author, &[], b"").is_err()); | |
| 607 | + let mut far = author.clone(); | |
| 608 | + far.offset_minutes = 100 * 60; | |
| 609 | + assert!(encode_commit(oid(1), &[], &far, &author, &[], b"").is_err()); | |
| 610 | + for key in [&b""[..], b"tree", b"a b", b"a\nb"] { | |
| 611 | + let extras = vec![(key.to_vec(), b"v".to_vec())]; | |
| 612 | + assert!(encode_commit(oid(1), &[], &author, &author, &extras, b"").is_err()); | |
| 613 | + } | |
| 614 | + } | |
| 615 | + | |
| 616 | + #[test] | |
| 617 | + fn tags() { | |
| 618 | + let target = oid(0x42); | |
| 619 | + let text = format!( | |
| 620 | + "object {target}\ntype commit\ntag v1\ntagger T <t@example.org> 1 +0000\n\nmsg\n" | |
| 621 | + ); | |
| 622 | + assert_eq!(parse_tag(text.as_bytes()), Ok(target)); | |
| 623 | + assert!(parse_tag(b"type commit\n").is_err()); | |
| 624 | + } | |
| 625 | +} |
added crates/git/src/repo.rs +237 −0
| @@ -0,0 +1,237 @@ | ||
| 1 | +// SPDX-License-Identifier: Apache-2.0 | |
| 2 | +// Copyright (c) 2026 UtopiaIA | |
| 3 | + | |
| 4 | +//! Raw access to git repositories through gitoxide. | |
| 5 | +//! | |
| 6 | +//! Objects are read and written as raw bytes: no filters, no line-ending | |
| 7 | +//! conversion, no LFS. Replacement objects (`refs/replace/`) are ignored and | |
| 8 | +//! grafts are never read, so every object is exactly what its id names. Only | |
| 9 | +//! the repository's own configuration is read; the user's, the system's and | |
| 10 | +//! the environment's are not. | |
| 11 | + | |
| 12 | +use std::path::Path; | |
| 13 | + | |
| 14 | +use gix::bstr::{BStr, ByteSlice}; | |
| 15 | +use gix::objs::{Exists, Find, FindHeader, Write}; | |
| 16 | + | |
| 17 | +use crate::error::{Error, ShowBytes}; | |
| 18 | +use crate::oid::{GitKind, GitOid}; | |
| 19 | + | |
| 20 | +/// Memory for the cache of decoded pack deltas, per open repository. | |
| 21 | +const PACK_CACHE_BYTES: usize = 64 * 1024 * 1024; | |
| 22 | + | |
| 23 | +/// The id of the empty tree. | |
| 24 | +const EMPTY_TREE: GitOid = GitOid::from_bytes([ | |
| 25 | + 0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60, 0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, | |
| 26 | + 0xfb, 0xee, 0x49, 0x04, | |
| 27 | +]); | |
| 28 | + | |
| 29 | +/// An open git repository. | |
| 30 | +pub(crate) struct GitRepo { | |
| 31 | + repo: gix::Repository, | |
| 32 | +} | |
| 33 | + | |
| 34 | +impl GitRepo { | |
| 35 | + /// Opens the repository at `path`, its work tree or its git directory. | |
| 36 | + /// SHA-256 repositories are refused. | |
| 37 | + pub(crate) fn open(path: &Path) -> Result<Self, Error> { | |
| 38 | + let mut repo = gix::open_opts(path, gix::open::Options::isolated()).map_err(|err| { | |
| 39 | + Error::git( | |
| 40 | + format!("cannot open a git repository at {}", path.display()), | |
| 41 | + err, | |
| 42 | + ) | |
| 43 | + })?; | |
| 44 | + if repo.object_hash() != gix::hash::Kind::Sha1 { | |
| 45 | + return Err(Error::Sha256); | |
| 46 | + } | |
| 47 | + repo.objects.ignore_replacements = true; | |
| 48 | + repo.objects.set_pack_cache(|| { | |
| 49 | + Box::new(gix::odb::pack::cache::lru::MemoryCappedHashmap::new( | |
| 50 | + PACK_CACHE_BYTES, | |
| 51 | + )) | |
| 52 | + }); | |
| 53 | + Ok(Self { repo }) | |
| 54 | + } | |
| 55 | + | |
| 56 | + /// Creates an empty bare repository at `path` and opens it. | |
| 57 | + pub(crate) fn init_bare(path: &Path) -> Result<Self, Error> { | |
| 58 | + gix::init_bare(path).map_err(|err| { | |
| 59 | + Error::git( | |
| 60 | + format!("cannot create a bare repository at {}", path.display()), | |
| 61 | + err, | |
| 62 | + ) | |
| 63 | + })?; | |
| 64 | + Self::open(path) | |
| 65 | + } | |
| 66 | + | |
| 67 | + /// Whether the repository is a shallow clone. | |
| 68 | + pub(crate) fn is_shallow(&self) -> Result<bool, Error> { | |
| 69 | + self.repo | |
| 70 | + .is_shallow() | |
| 71 | + .map_err(|err| Error::git("cannot tell whether the repository is shallow", err)) | |
| 72 | + } | |
| 73 | + | |
| 74 | + /// Reads an object and checks that its bytes hash to its id. | |
| 75 | + /// | |
| 76 | + /// The empty tree reads as itself even when it is not stored: git treats | |
| 77 | + /// it as always present, and does not store it when a commit uses it. | |
| 78 | + pub(crate) fn read(&self, oid: &GitOid) -> Result<(GitKind, Vec<u8>), Error> { | |
| 79 | + let mut buf = Vec::new(); | |
| 80 | + let found = self | |
| 81 | + .repo | |
| 82 | + .objects | |
| 83 | + .try_find(&oid.to_gix(), &mut buf) | |
| 84 | + .map_err(|err| Error::git(format!("cannot read git object {oid}"), err))?; | |
| 85 | + let (kind, bytes) = match found { | |
| 86 | + Some(data) => (GitKind::from_gix(data.kind), data.data.to_vec()), | |
| 87 | + None if *oid == EMPTY_TREE => (GitKind::Tree, Vec::new()), | |
| 88 | + None => return Err(Error::MissingObject(*oid)), | |
| 89 | + }; | |
| 90 | + if GitOid::for_object(kind, &bytes)? != *oid { | |
| 91 | + return Err(Error::CorruptObject(*oid)); | |
| 92 | + } | |
| 93 | + Ok((kind, bytes)) | |
| 94 | + } | |
| 95 | + | |
| 96 | + /// Reads an object that must be of `expected` kind. | |
| 97 | + pub(crate) fn read_kind(&self, oid: &GitOid, expected: GitKind) -> Result<Vec<u8>, Error> { | |
| 98 | + let (found, bytes) = self.read(oid)?; | |
| 99 | + if found != expected { | |
| 100 | + return Err(Error::WrongKind { | |
| 101 | + oid: *oid, | |
| 102 | + expected, | |
| 103 | + found, | |
| 104 | + }); | |
| 105 | + } | |
| 106 | + Ok(bytes) | |
| 107 | + } | |
| 108 | + | |
| 109 | + /// The kind of an object, from its header alone. | |
| 110 | + pub(crate) fn kind(&self, oid: &GitOid) -> Result<GitKind, Error> { | |
| 111 | + let header = self | |
| 112 | + .repo | |
| 113 | + .objects | |
| 114 | + .try_header(&oid.to_gix()) | |
| 115 | + .map_err(|err| Error::git(format!("cannot read git object {oid}"), err))?; | |
| 116 | + match header { | |
| 117 | + Some(header) => Ok(GitKind::from_gix(header.kind)), | |
| 118 | + None if *oid == EMPTY_TREE => Ok(GitKind::Tree), | |
| 119 | + None => Err(Error::MissingObject(*oid)), | |
| 120 | + } | |
| 121 | + } | |
| 122 | + | |
| 123 | + /// Whether the object is stored in the repository. Unlike git, this does | |
| 124 | + /// not count the empty tree as always present, so that a copy gets it. | |
| 125 | + pub(crate) fn contains(&self, oid: &GitOid) -> bool { | |
| 126 | + self.repo.objects.exists(&oid.to_gix()) | |
| 127 | + } | |
| 128 | + | |
| 129 | + /// Writes an object and returns the id gitoxide computed for it. | |
| 130 | + pub(crate) fn write(&self, kind: GitKind, bytes: &[u8]) -> Result<GitOid, Error> { | |
| 131 | + let id = self | |
| 132 | + .repo | |
| 133 | + .objects | |
| 134 | + .write_buf(kind.to_gix(), bytes) | |
| 135 | + .map_err(|err| Error::git(format!("cannot write a git {kind}"), err))?; | |
| 136 | + GitOid::from_gix(&id).ok_or(Error::Sha256) | |
| 137 | + } | |
| 138 | + | |
| 139 | + /// The refs to import, sorted by name, each with the object it points to | |
| 140 | + /// after following symbolic refs (an annotated tag stays a tag). | |
| 141 | + /// | |
| 142 | + /// With no `names`, every branch (`refs/heads/`) and tag (`refs/tags/`). | |
| 143 | + /// Otherwise the named refs, which must exist; a short name is looked up | |
| 144 | + /// the way git does, and reported under its full name. | |
| 145 | + pub(crate) fn refs(&self, names: &[Vec<u8>]) -> Result<Vec<(Vec<u8>, GitOid)>, Error> { | |
| 146 | + let mut found = Vec::new(); | |
| 147 | + let mut add = |reference: &mut gix::Reference<'_>| -> Result<(), Error> { | |
| 148 | + let name = reference.name().as_bstr().to_vec(); | |
| 149 | + let id = reference.follow_to_object().map_err(|err| { | |
| 150 | + Error::git(format!("cannot resolve ref {}", ShowBytes(&name)), err) | |
| 151 | + })?; | |
| 152 | + found.push((name, GitOid::from_gix(&id).ok_or(Error::Sha256)?)); | |
| 153 | + Ok(()) | |
| 154 | + }; | |
| 155 | + if names.is_empty() { | |
| 156 | + let platform = self | |
| 157 | + .repo | |
| 158 | + .references() | |
| 159 | + .map_err(|err| Error::git("cannot list refs", err))?; | |
| 160 | + let branches = platform | |
| 161 | + .local_branches() | |
| 162 | + .map_err(|err| Error::git("cannot list branches", err))?; | |
| 163 | + let tags = platform | |
| 164 | + .tags() | |
| 165 | + .map_err(|err| Error::git("cannot list tags", err))?; | |
| 166 | + for reference in branches.chain(tags) { | |
| 167 | + let mut reference = | |
| 168 | + reference.map_err(|err| Error::git("cannot read a ref", err))?; | |
| 169 | + add(&mut reference)?; | |
| 170 | + } | |
| 171 | + } else { | |
| 172 | + for name in names { | |
| 173 | + let mut reference = self | |
| 174 | + .repo | |
| 175 | + .try_find_reference(BStr::new(name.as_slice())) | |
| 176 | + .map_err(|err| Error::git(format!("cannot read ref {}", ShowBytes(name)), err))? | |
| 177 | + .ok_or_else(|| Error::MissingRef(name.clone()))?; | |
| 178 | + add(&mut reference)?; | |
| 179 | + } | |
| 180 | + } | |
| 181 | + found.sort(); | |
| 182 | + found.dedup(); | |
| 183 | + Ok(found) | |
| 184 | + } | |
| 185 | + | |
| 186 | + /// The object a ref points to, after following symbolic refs. | |
| 187 | + pub(crate) fn resolve_ref(&self, name: &[u8]) -> Result<Option<GitOid>, Error> { | |
| 188 | + let Some(mut reference) = self | |
| 189 | + .repo | |
| 190 | + .try_find_reference(BStr::new(name)) | |
| 191 | + .map_err(|err| Error::git(format!("cannot read ref {}", ShowBytes(name)), err))? | |
| 192 | + else { | |
| 193 | + return Ok(None); | |
| 194 | + }; | |
| 195 | + let id = reference | |
| 196 | + .follow_to_object() | |
| 197 | + .map_err(|err| Error::git(format!("cannot resolve ref {}", ShowBytes(name)), err))?; | |
| 198 | + Ok(Some(GitOid::from_gix(&id).ok_or(Error::Sha256)?)) | |
| 199 | + } | |
| 200 | + | |
| 201 | + /// Points each ref at its object in one transaction, whatever it pointed | |
| 202 | + /// to before. Reflogs, where the repository keeps them, name the | |
| 203 | + /// configured committer, or a generic one when there is none. | |
| 204 | + pub(crate) fn set_refs( | |
| 205 | + &mut self, | |
| 206 | + refs: &[(Vec<u8>, GitOid)], | |
| 207 | + message: &str, | |
| 208 | + ) -> Result<(), Error> { | |
| 209 | + use gix::refs::transaction::{Change, LogChange, PreviousValue, RefEdit, RefLog}; | |
| 210 | + | |
| 211 | + let mut edits = Vec::with_capacity(refs.len()); | |
| 212 | + for (name, oid) in refs { | |
| 213 | + let full_name = gix::refs::FullName::try_from(name.as_bstr()) | |
| 214 | + .map_err(|err| Error::git(format!("invalid ref name {}", ShowBytes(name)), err))?; | |
| 215 | + edits.push(RefEdit { | |
| 216 | + change: Change::Update { | |
| 217 | + log: LogChange { | |
| 218 | + mode: RefLog::AndReference, | |
| 219 | + force_create_reflog: false, | |
| 220 | + message: message.into(), | |
| 221 | + }, | |
| 222 | + expected: PreviousValue::Any, | |
| 223 | + new: gix::refs::Target::Object(oid.to_gix()), | |
| 224 | + }, | |
| 225 | + name: full_name, | |
| 226 | + deref: false, | |
| 227 | + }); | |
| 228 | + } | |
| 229 | + self.repo | |
| 230 | + .committer_or_set_generic_fallback() | |
| 231 | + .map_err(|err| Error::git("cannot set up a reflog identity", err))?; | |
| 232 | + self.repo | |
| 233 | + .edit_references(edits) | |
| 234 | + .map_err(|err| Error::git("cannot update refs", err))?; | |
| 235 | + Ok(()) | |
| 236 | + } | |
| 237 | +} |
added crates/git/src/roundtrip.rs +147 −0
| @@ -0,0 +1,147 @@ | ||
| 1 | +// SPDX-License-Identifier: Apache-2.0 | |
| 2 | +// Copyright (c) 2026 UtopiaIA | |
| 3 | + | |
| 4 | +//! The round trip: git to braid and back, compared object by object. | |
| 5 | + | |
| 6 | +use std::collections::{BTreeMap, HashSet}; | |
| 7 | +use std::path::Path; | |
| 8 | + | |
| 9 | +use braid_format::MemoryObjects; | |
| 10 | + | |
| 11 | +use crate::error::Error; | |
| 12 | +use crate::export::{RefTarget, RefUpdate, reached, write_to_repo}; | |
| 13 | +use crate::import::{ImportOptions, import}; | |
| 14 | +use crate::map::GitMap; | |
| 15 | +use crate::oid::{GitKind, GitOid}; | |
| 16 | +use crate::repo::GitRepo; | |
| 17 | + | |
| 18 | +/// What a round trip compared. | |
| 19 | +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] | |
| 20 | +pub struct RoundTripReport { | |
| 21 | + /// Commits, identical on both sides. | |
| 22 | + pub commits: usize, | |
| 23 | + /// Trees, identical on both sides. | |
| 24 | + pub trees: usize, | |
| 25 | + /// Of those trees, the ones the export kept as raw bytes. | |
| 26 | + pub raw_trees: usize, | |
| 27 | + /// Blobs, identical on both sides. | |
| 28 | + pub blobs: usize, | |
| 29 | + /// Annotated tags, identical on both sides. | |
| 30 | + pub tags: usize, | |
| 31 | + /// Refs pointing to the same objects on both sides. | |
| 32 | + pub refs: usize, | |
| 33 | +} | |
| 34 | + | |
| 35 | +/// Imports every branch and tag of `src_repo` into memory, exports | |
| 36 | +/// everything into a fresh bare repository under `tmp_dir`, and checks that | |
| 37 | +/// both repositories hold exactly the same commits, trees, blobs and tags, | |
| 38 | +/// with the same ids, and the same refs. | |
| 39 | +/// | |
| 40 | +/// The refs are read once, at import, so commits added to the source while | |
| 41 | +/// the round trip runs do not disturb it. Every object read on either side is | |
| 42 | +/// checked to hash to its id. | |
| 43 | +pub fn verify_round_trip(src_repo: &Path, tmp_dir: &Path) -> Result<RoundTripReport, Error> { | |
| 44 | + verify_round_trip_with(src_repo, tmp_dir, &ImportOptions::default()) | |
| 45 | +} | |
| 46 | + | |
| 47 | +/// [`verify_round_trip`] for the refs that `options` selects, such as `HEAD` | |
| 48 | +/// in a checkout without branches. | |
| 49 | +pub fn verify_round_trip_with( | |
| 50 | + src_repo: &Path, | |
| 51 | + tmp_dir: &Path, | |
| 52 | + options: &ImportOptions, | |
| 53 | +) -> Result<RoundTripReport, Error> { | |
| 54 | + let objects = MemoryObjects::new(); | |
| 55 | + let mut map = GitMap::new(); | |
| 56 | + let imported = import(src_repo, &objects, &mut map, options)?; | |
| 57 | + | |
| 58 | + let copy_path = tmp_dir.join("round-trip.git"); | |
| 59 | + GitRepo::init_bare(©_path)?; | |
| 60 | + let updates: Vec<RefUpdate> = imported | |
| 61 | + .refs | |
| 62 | + .iter() | |
| 63 | + .map(|r| RefUpdate { | |
| 64 | + name: r.name.clone(), | |
| 65 | + target: RefTarget::Git(r.oid), | |
| 66 | + }) | |
| 67 | + .collect(); | |
| 68 | + write_to_repo(©_path, &objects, &map, &updates)?; | |
| 69 | + | |
| 70 | + let source = GitRepo::open(src_repo)?; | |
| 71 | + let copy = GitRepo::open(©_path)?; | |
| 72 | + let tips: Vec<GitOid> = imported.refs.iter().map(|r| r.oid).collect(); | |
| 73 | + let expected = reachable(&source, &tips)?; | |
| 74 | + let found = reachable(©, &tips) | |
| 75 | + .map_err(|err| Error::RoundTrip(format!("the copy is incomplete: {err}")))?; | |
| 76 | + if expected != found { | |
| 77 | + return Err(Error::RoundTrip(describe_difference(&expected, &found))); | |
| 78 | + } | |
| 79 | + for r in &imported.refs { | |
| 80 | + let target = copy.resolve_ref(&r.name)?; | |
| 81 | + if target != Some(r.oid) { | |
| 82 | + return Err(Error::RoundTrip(format!( | |
| 83 | + "ref {} points to {target:?} in the copy, {} in the source", | |
| 84 | + String::from_utf8_lossy(&r.name), | |
| 85 | + r.oid | |
| 86 | + ))); | |
| 87 | + } | |
| 88 | + } | |
| 89 | + | |
| 90 | + let mut report = RoundTripReport { | |
| 91 | + refs: imported.refs.len(), | |
| 92 | + raw_trees: map.counts().raw_trees, | |
| 93 | + ..RoundTripReport::default() | |
| 94 | + }; | |
| 95 | + for kind in expected.values() { | |
| 96 | + match kind { | |
| 97 | + GitKind::Commit => report.commits += 1, | |
| 98 | + GitKind::Tree => report.trees += 1, | |
| 99 | + GitKind::Blob => report.blobs += 1, | |
| 100 | + GitKind::Tag => report.tags += 1, | |
| 101 | + } | |
| 102 | + } | |
| 103 | + Ok(report) | |
| 104 | +} | |
| 105 | + | |
| 106 | +/// Every object reachable from `tips`, with its kind. Submodule commits are | |
| 107 | +/// not followed: they live in another repository. | |
| 108 | +fn reachable(repo: &GitRepo, tips: &[GitOid]) -> Result<BTreeMap<GitOid, GitKind>, Error> { | |
| 109 | + let mut found = BTreeMap::new(); | |
| 110 | + let mut queued: HashSet<GitOid> = tips.iter().copied().collect(); | |
| 111 | + let mut pending: Vec<GitOid> = tips.to_vec(); | |
| 112 | + while let Some(oid) = pending.pop() { | |
| 113 | + let (kind, bytes) = repo.read(&oid)?; | |
| 114 | + for next in reached(oid, kind, &bytes)? { | |
| 115 | + if queued.insert(next) { | |
| 116 | + pending.push(next); | |
| 117 | + } | |
| 118 | + } | |
| 119 | + found.insert(oid, kind); | |
| 120 | + } | |
| 121 | + Ok(found) | |
| 122 | +} | |
| 123 | + | |
| 124 | +fn describe_difference( | |
| 125 | + expected: &BTreeMap<GitOid, GitKind>, | |
| 126 | + found: &BTreeMap<GitOid, GitKind>, | |
| 127 | +) -> String { | |
| 128 | + let missing: Vec<String> = expected | |
| 129 | + .iter() | |
| 130 | + .filter(|(oid, kind)| found.get(oid) != Some(kind)) | |
| 131 | + .take(5) | |
| 132 | + .map(|(oid, kind)| format!("{kind} {oid}")) | |
| 133 | + .collect(); | |
| 134 | + let extra: Vec<String> = found | |
| 135 | + .iter() | |
| 136 | + .filter(|(oid, kind)| expected.get(oid) != Some(kind)) | |
| 137 | + .take(5) | |
| 138 | + .map(|(oid, kind)| format!("{kind} {oid}")) | |
| 139 | + .collect(); | |
| 140 | + format!( | |
| 141 | + "{} objects in the source, {} in the copy; missing from the copy: [{}]; only in the copy: [{}]", | |
| 142 | + expected.len(), | |
| 143 | + found.len(), | |
| 144 | + missing.join(", "), | |
| 145 | + extra.join(", ") | |
| 146 | + ) | |
| 147 | +} |
added crates/git/tests/common/mod.rs +418 −0
| @@ -0,0 +1,418 @@ | ||
| 1 | +// SPDX-License-Identifier: Apache-2.0 | |
| 2 | +// Copyright (c) 2026 UtopiaIA | |
| 3 | + | |
| 4 | +//! Git repositories for the tests, built with the git command line. | |
| 5 | +//! | |
| 6 | +//! Every repository is bare and built with plumbing only, so a test never | |
| 7 | +//! depends on how a file system treats names, modes or symlinks. Commands run | |
| 8 | +//! without the user's or the system's configuration, with fixed identities | |
| 9 | +//! and a clock that ticks once per commit or tag, so every id is reproducible. | |
| 10 | + | |
| 11 | +#![allow(dead_code)] | |
| 12 | + | |
| 13 | +use std::collections::BTreeMap; | |
| 14 | +use std::io::Write; | |
| 15 | +use std::path::{Path, PathBuf}; | |
| 16 | +use std::process::{Command, Stdio}; | |
| 17 | + | |
| 18 | +use tempfile::TempDir; | |
| 19 | + | |
| 20 | +/// What a path holds in a tree. | |
| 21 | +#[derive(Clone, Debug)] | |
| 22 | +pub enum Item { | |
| 23 | + /// A regular file. | |
| 24 | + File(Vec<u8>), | |
| 25 | + /// An executable file. | |
| 26 | + Exec(Vec<u8>), | |
| 27 | + /// A symlink to this target. | |
| 28 | + Link(Vec<u8>), | |
| 29 | + /// A submodule at this commit. | |
| 30 | + Submodule(String), | |
| 31 | +} | |
| 32 | + | |
| 33 | +/// A path and what it holds. | |
| 34 | +pub type Entry = (Vec<u8>, Item); | |
| 35 | + | |
| 36 | +/// A path, what it holds, and the id of its blob once stored. | |
| 37 | +type Stored = (Vec<u8>, Item, Option<String>); | |
| 38 | + | |
| 39 | +pub fn file(path: impl AsRef<[u8]>, content: impl AsRef<[u8]>) -> Entry { | |
| 40 | + ( | |
| 41 | + path.as_ref().to_vec(), | |
| 42 | + Item::File(content.as_ref().to_vec()), | |
| 43 | + ) | |
| 44 | +} | |
| 45 | + | |
| 46 | +pub fn exec(path: impl AsRef<[u8]>, content: impl AsRef<[u8]>) -> Entry { | |
| 47 | + ( | |
| 48 | + path.as_ref().to_vec(), | |
| 49 | + Item::Exec(content.as_ref().to_vec()), | |
| 50 | + ) | |
| 51 | +} | |
| 52 | + | |
| 53 | +pub fn link(path: impl AsRef<[u8]>, target: impl AsRef<[u8]>) -> Entry { | |
| 54 | + (path.as_ref().to_vec(), Item::Link(target.as_ref().to_vec())) | |
| 55 | +} | |
| 56 | + | |
| 57 | +pub fn submodule(path: impl AsRef<[u8]>, commit: &str) -> Entry { | |
| 58 | + (path.as_ref().to_vec(), Item::Submodule(commit.to_string())) | |
| 59 | +} | |
| 60 | + | |
| 61 | +/// Raw tree bytes from `(mode, name, id)` entries, written as given: any | |
| 62 | +/// mode, any order, duplicates allowed. | |
| 63 | +pub fn raw_tree(entries: &[(&str, &[u8], &str)]) -> Vec<u8> { | |
| 64 | + let mut out = Vec::new(); | |
| 65 | + for (mode, name, id) in entries { | |
| 66 | + out.extend_from_slice(mode.as_bytes()); | |
| 67 | + out.push(b' '); | |
| 68 | + out.extend_from_slice(name); | |
| 69 | + out.push(0); | |
| 70 | + out.extend_from_slice(&hex(id)); | |
| 71 | + } | |
| 72 | + out | |
| 73 | +} | |
| 74 | + | |
| 75 | +fn hex(text: &str) -> Vec<u8> { | |
| 76 | + (0..text.len()) | |
| 77 | + .step_by(2) | |
| 78 | + .map(|i| u8::from_str_radix(&text[i..i + 2], 16).unwrap()) | |
| 79 | + .collect() | |
| 80 | +} | |
| 81 | + | |
| 82 | +/// The first commit time; each commit or tag adds a minute. | |
| 83 | +const EPOCH: i64 = 1_700_000_000; | |
| 84 | + | |
| 85 | +/// Variables that would point git somewhere else, or change what it reads. | |
| 86 | +const LEAKY_VARIABLES: [&str; 12] = [ | |
| 87 | + "GIT_DIR", | |
| 88 | + "GIT_WORK_TREE", | |
| 89 | + "GIT_INDEX_FILE", | |
| 90 | + "GIT_OBJECT_DIRECTORY", | |
| 91 | + "GIT_ALTERNATE_OBJECT_DIRECTORIES", | |
| 92 | + "GIT_COMMON_DIR", | |
| 93 | + "GIT_NAMESPACE", | |
| 94 | + "GIT_CEILING_DIRECTORIES", | |
| 95 | + "GIT_REPLACE_REF_BASE", | |
| 96 | + "GIT_NO_REPLACE_OBJECTS", | |
| 97 | + "GIT_GRAFT_FILE", | |
| 98 | + "GIT_SHALLOW_FILE", | |
| 99 | +]; | |
| 100 | + | |
| 101 | +/// A bare repository in a temporary directory. | |
| 102 | +pub struct Repo { | |
| 103 | + dir: TempDir, | |
| 104 | + path: PathBuf, | |
| 105 | + clock: i64, | |
| 106 | +} | |
| 107 | + | |
| 108 | +impl Repo { | |
| 109 | + /// An empty SHA-1 repository whose default branch is `main`. | |
| 110 | + pub fn new() -> Self { | |
| 111 | + Self::init(&[]) | |
| 112 | + } | |
| 113 | + | |
| 114 | + /// An empty repository created with extra `git init` arguments. | |
| 115 | + pub fn init(args: &[&str]) -> Self { | |
| 116 | + let dir = tempfile::tempdir().unwrap(); | |
| 117 | + let path = dir.path().join("repo.git"); | |
| 118 | + let mut init = git_command(dir.path(), EPOCH); | |
| 119 | + init.args(["init", "--quiet", "--bare"]) | |
| 120 | + .args(args) | |
| 121 | + .arg(&path); | |
| 122 | + run(init, None); | |
| 123 | + Self { | |
| 124 | + dir, | |
| 125 | + path, | |
| 126 | + clock: EPOCH, | |
| 127 | + } | |
| 128 | + } | |
| 129 | + | |
| 130 | + pub fn path(&self) -> &Path { | |
| 131 | + &self.path | |
| 132 | + } | |
| 133 | + | |
| 134 | + /// A scratch directory next to the repository. | |
| 135 | + pub fn scratch(&self) -> PathBuf { | |
| 136 | + let path = self.dir.path().join("scratch"); | |
| 137 | + std::fs::create_dir_all(&path).unwrap(); | |
| 138 | + path | |
| 139 | + } | |
| 140 | + | |
| 141 | + /// A git command that runs in the repository. | |
| 142 | + pub fn command(&self) -> Command { | |
| 143 | + git_command(&self.path, self.clock) | |
| 144 | + } | |
| 145 | + | |
| 146 | + /// Runs git and returns its output, trimmed. | |
| 147 | + pub fn git(&self, args: &[&str]) -> String { | |
| 148 | + let mut command = self.command(); | |
| 149 | + command.args(args); | |
| 150 | + trimmed(run(command, None)) | |
| 151 | + } | |
| 152 | + | |
| 153 | + /// Runs git with `input` on its standard input. | |
| 154 | + pub fn git_input(&self, args: &[&str], input: &[u8]) -> String { | |
| 155 | + let mut command = self.command(); | |
| 156 | + command.args(args); | |
| 157 | + trimmed(run(command, Some(input))) | |
| 158 | + } | |
| 159 | + | |
| 160 | + /// Runs git and returns its raw output. | |
| 161 | + pub fn git_bytes(&self, args: &[&str]) -> Vec<u8> { | |
| 162 | + let mut command = self.command(); | |
| 163 | + command.args(args); | |
| 164 | + run(command, None) | |
| 165 | + } | |
| 166 | + | |
| 167 | + pub fn blob(&self, content: &[u8]) -> String { | |
| 168 | + self.git_input(&["hash-object", "-w", "--stdin"], content) | |
| 169 | + } | |
| 170 | + | |
| 171 | + /// Writes many blobs with one git process, in order. | |
| 172 | + pub fn blobs(&self, contents: &[&[u8]]) -> Vec<String> { | |
| 173 | + if contents.is_empty() { | |
| 174 | + return Vec::new(); | |
| 175 | + } | |
| 176 | + let scratch = self.scratch(); | |
| 177 | + let mut paths = String::new(); | |
| 178 | + for (index, content) in contents.iter().enumerate() { | |
| 179 | + let path = scratch.join(format!("blob-{index}")); | |
| 180 | + std::fs::write(&path, content).unwrap(); | |
| 181 | + paths.push_str(path.to_str().unwrap()); | |
| 182 | + paths.push('\n'); | |
| 183 | + } | |
| 184 | + let out = self.git_input(&["hash-object", "-w", "--stdin-paths"], paths.as_bytes()); | |
| 185 | + let ids: Vec<String> = out.lines().map(str::to_string).collect(); | |
| 186 | + assert_eq!(ids.len(), contents.len()); | |
| 187 | + ids | |
| 188 | + } | |
| 189 | + | |
| 190 | + /// Stores any bytes as an object of `kind`, without git's checks. | |
| 191 | + pub fn literally(&self, kind: &str, bytes: &[u8]) -> String { | |
| 192 | + self.git_input( | |
| 193 | + &["hash-object", "-t", kind, "-w", "--literally", "--stdin"], | |
| 194 | + bytes, | |
| 195 | + ) | |
| 196 | + } | |
| 197 | + | |
| 198 | + /// A tree from `(mode, type, id, name)` entries, written by `git mktree`. | |
| 199 | + pub fn mktree(&self, entries: &[(&str, &str, &str, &[u8])]) -> String { | |
| 200 | + let mut input = Vec::new(); | |
| 201 | + for (mode, kind, id, name) in entries { | |
| 202 | + write!(input, "{mode} {kind} {id}\t").unwrap(); | |
| 203 | + input.extend_from_slice(name); | |
| 204 | + input.push(0); | |
| 205 | + } | |
| 206 | + self.git_input(&["mktree", "-z", "--missing"], &input) | |
| 207 | + } | |
| 208 | + | |
| 209 | + /// The tree holding exactly `entries`, with directories made from the | |
| 210 | + /// paths. | |
| 211 | + pub fn tree(&self, entries: &[Entry]) -> String { | |
| 212 | + let contents: Vec<&[u8]> = entries | |
| 213 | + .iter() | |
| 214 | + .filter_map(|(_, item)| match item { | |
| 215 | + Item::File(content) | Item::Exec(content) | Item::Link(content) => { | |
| 216 | + Some(content.as_slice()) | |
| 217 | + } | |
| 218 | + Item::Submodule(_) => None, | |
| 219 | + }) | |
| 220 | + .collect(); | |
| 221 | + let mut ids = self.blobs(&contents).into_iter(); | |
| 222 | + let with_ids: Vec<Stored> = entries | |
| 223 | + .iter() | |
| 224 | + .map(|(path, item)| { | |
| 225 | + let id = match item { | |
| 226 | + Item::Submodule(_) => None, | |
| 227 | + _ => ids.next(), | |
| 228 | + }; | |
| 229 | + (path.clone(), item.clone(), id) | |
| 230 | + }) | |
| 231 | + .collect(); | |
| 232 | + self.tree_level(&with_ids) | |
| 233 | + } | |
| 234 | + | |
| 235 | + fn tree_level(&self, entries: &[Stored]) -> String { | |
| 236 | + let mut dirs: BTreeMap<Vec<u8>, Vec<Stored>> = BTreeMap::new(); | |
| 237 | + let mut input = Vec::new(); | |
| 238 | + for (path, item, id) in entries { | |
| 239 | + if let Some(slash) = path.iter().position(|byte| *byte == b'/') { | |
| 240 | + dirs.entry(path[..slash].to_vec()).or_default().push(( | |
| 241 | + path[slash + 1..].to_vec(), | |
| 242 | + item.clone(), | |
| 243 | + id.clone(), | |
| 244 | + )); | |
| 245 | + continue; | |
| 246 | + } | |
| 247 | + let (mode, kind, id) = match item { | |
| 248 | + Item::File(_) => ("100644", "blob", id.clone().unwrap()), | |
| 249 | + Item::Exec(_) => ("100755", "blob", id.clone().unwrap()), | |
| 250 | + Item::Link(_) => ("120000", "blob", id.clone().unwrap()), | |
| 251 | + Item::Submodule(commit) => ("160000", "commit", commit.clone()), | |
| 252 | + }; | |
| 253 | + write!(input, "{mode} {kind} {id}\t").unwrap(); | |
| 254 | + input.extend_from_slice(path); | |
| 255 | + input.push(0); | |
| 256 | + } | |
| 257 | + for (name, children) in &dirs { | |
| 258 | + let id = self.tree_level(children); | |
| 259 | + write!(input, "040000 tree {id}\t").unwrap(); | |
| 260 | + input.extend_from_slice(name); | |
| 261 | + input.push(0); | |
| 262 | + } | |
| 263 | + self.git_input(&["mktree", "-z", "--missing"], &input) | |
| 264 | + } | |
| 265 | + | |
| 266 | + /// The tree `git write-tree` writes from a fresh index filled with | |
| 267 | + /// `git update-index --add --cacheinfo <mode>,<id>,<path>` for each entry. | |
| 268 | + pub fn index_tree(&self, cacheinfo: &[String]) -> String { | |
| 269 | + let index = self.scratch().join("index"); | |
| 270 | + let _ = std::fs::remove_file(&index); | |
| 271 | + for info in cacheinfo { | |
| 272 | + let mut command = self.command(); | |
| 273 | + command.env("GIT_INDEX_FILE", &index); | |
| 274 | + command.args(["update-index", "--add", "--cacheinfo", info]); | |
| 275 | + run(command, None); | |
| 276 | + } | |
| 277 | + let mut command = self.command(); | |
| 278 | + command.env("GIT_INDEX_FILE", &index).arg("write-tree"); | |
| 279 | + trimmed(run(command, None)) | |
| 280 | + } | |
| 281 | + | |
| 282 | + fn tick(&mut self) { | |
| 283 | + self.clock += 60; | |
| 284 | + } | |
| 285 | + | |
| 286 | + /// A commit of `tree` with these parents and message. | |
| 287 | + pub fn commit(&mut self, tree: &str, parents: &[&str], message: &str) -> String { | |
| 288 | + self.tick(); | |
| 289 | + let mut args = vec!["commit-tree", tree]; | |
| 290 | + for parent in parents { | |
| 291 | + args.extend(["-p", parent]); | |
| 292 | + } | |
| 293 | + args.extend(["-m", message]); | |
| 294 | + self.git(&args) | |
| 295 | + } | |
| 296 | + | |
| 297 | + /// The commit a branch points to, if the branch exists. | |
| 298 | + pub fn head(&self, branch: &str) -> Option<String> { | |
| 299 | + let mut command = self.command(); | |
| 300 | + command.args(["rev-parse", "--verify", "--quiet"]); | |
| 301 | + command.arg(format!("refs/heads/{branch}")); | |
| 302 | + let output = command.output().unwrap(); | |
| 303 | + output.status.success().then(|| trimmed(output.stdout)) | |
| 304 | + } | |
| 305 | + | |
| 306 | + /// Commits exactly `entries` on `branch`, after its current head. | |
| 307 | + pub fn snapshot(&mut self, branch: &str, entries: &[Entry], message: &str) -> String { | |
| 308 | + self.merge(branch, &[], entries, message) | |
| 309 | + } | |
| 310 | + | |
| 311 | + /// Commits `entries` on `branch` with the heads of `others` as further | |
| 312 | + /// parents. | |
| 313 | + pub fn merge( | |
| 314 | + &mut self, | |
| 315 | + branch: &str, | |
| 316 | + others: &[&str], | |
| 317 | + entries: &[Entry], | |
| 318 | + message: &str, | |
| 319 | + ) -> String { | |
| 320 | + let tree = self.tree(entries); | |
| 321 | + let mut parents: Vec<String> = self.head(branch).into_iter().collect(); | |
| 322 | + for other in others { | |
| 323 | + parents.push(self.head(other).unwrap()); | |
| 324 | + } | |
| 325 | + let parents: Vec<&str> = parents.iter().map(String::as_str).collect(); | |
| 326 | + let commit = self.commit(&tree, &parents, message); | |
| 327 | + self.set_ref(&format!("refs/heads/{branch}"), &commit); | |
| 328 | + commit | |
| 329 | + } | |
| 330 | + | |
| 331 | + pub fn set_ref(&self, name: &str, id: &str) { | |
| 332 | + self.git(&["update-ref", name, id]); | |
| 333 | + } | |
| 334 | + | |
| 335 | + /// An annotated tag named `name` on `target`; returns the tag object. | |
| 336 | + pub fn annotated_tag(&mut self, name: &str, target: &str, message: &str) -> String { | |
| 337 | + self.tick(); | |
| 338 | + self.git(&["tag", "--annotate", "-m", message, name, target]); | |
| 339 | + self.git(&["rev-parse", &format!("refs/tags/{name}")]) | |
| 340 | + } | |
| 341 | + | |
| 342 | + /// Commits reachable from branches and tags, as git counts them without | |
| 343 | + /// replacement objects or grafts. | |
| 344 | + pub fn count_commits(&self) -> usize { | |
| 345 | + self.git(&[ | |
| 346 | + "--no-replace-objects", | |
| 347 | + "rev-list", | |
| 348 | + "--count", | |
| 349 | + "--branches", | |
| 350 | + "--tags", | |
| 351 | + ]) | |
| 352 | + .parse() | |
| 353 | + .unwrap() | |
| 354 | + } | |
| 355 | +} | |
| 356 | + | |
| 357 | +/// A git command with a fixed environment, run in `dir`. | |
| 358 | +fn git_command(dir: &Path, clock: i64) -> Command { | |
| 359 | + let mut command = Command::new("git"); | |
| 360 | + command.current_dir(dir); | |
| 361 | + for variable in LEAKY_VARIABLES { | |
| 362 | + command.env_remove(variable); | |
| 363 | + } | |
| 364 | + let date = format!("{clock} +0100"); | |
| 365 | + command | |
| 366 | + .env("GIT_CONFIG_GLOBAL", "/dev/null") | |
| 367 | + .env("GIT_CONFIG_NOSYSTEM", "1") | |
| 368 | + .env("GIT_GRAFT_FILE", dir.join("no-grafts")) | |
| 369 | + .env("GIT_AUTHOR_NAME", "Ada Lovelace") | |
| 370 | + .env("GIT_AUTHOR_EMAIL", "ada@example.org") | |
| 371 | + .env("GIT_AUTHOR_DATE", &date) | |
| 372 | + .env("GIT_COMMITTER_NAME", "Charles Babbage") | |
| 373 | + .env("GIT_COMMITTER_EMAIL", "charles@example.org") | |
| 374 | + .env("GIT_COMMITTER_DATE", &date) | |
| 375 | + .args([ | |
| 376 | + "-c", | |
| 377 | + "init.defaultBranch=main", | |
| 378 | + "-c", | |
| 379 | + "commit.gpgSign=false", | |
| 380 | + "-c", | |
| 381 | + "tag.gpgSign=false", | |
| 382 | + "-c", | |
| 383 | + "gc.auto=0", | |
| 384 | + "-c", | |
| 385 | + "core.autocrlf=false", | |
| 386 | + "-c", | |
| 387 | + "advice.nestedTag=false", | |
| 388 | + ]); | |
| 389 | + command | |
| 390 | +} | |
| 391 | + | |
| 392 | +fn run(mut command: Command, input: Option<&[u8]>) -> Vec<u8> { | |
| 393 | + command | |
| 394 | + .stdin(if input.is_some() { | |
| 395 | + Stdio::piped() | |
| 396 | + } else { | |
| 397 | + Stdio::null() | |
| 398 | + }) | |
| 399 | + .stdout(Stdio::piped()) | |
| 400 | + .stderr(Stdio::piped()); | |
| 401 | + let mut child = command | |
| 402 | + .spawn() | |
| 403 | + .expect("git must be installed to run these tests"); | |
| 404 | + if let Some(input) = input { | |
| 405 | + child.stdin.take().unwrap().write_all(input).unwrap(); | |
| 406 | + } | |
| 407 | + let output = child.wait_with_output().unwrap(); | |
| 408 | + assert!( | |
| 409 | + output.status.success(), | |
| 410 | + "{command:?} failed: {}", | |
| 411 | + String::from_utf8_lossy(&output.stderr) | |
| 412 | + ); | |
| 413 | + output.stdout | |
| 414 | +} | |
| 415 | + | |
| 416 | +fn trimmed(bytes: Vec<u8>) -> String { | |
| 417 | + String::from_utf8(bytes).unwrap().trim().to_string() | |
| 418 | +} |
added crates/git/tests/fixtures.rs +1291 −0
| @@ -0,0 +1,1291 @@ | ||
| 1 | +// SPDX-License-Identifier: Apache-2.0 | |
| 2 | +// Copyright (c) 2026 UtopiaIA | |
| 3 | + | |
| 4 | +//! Round trips of repositories built for one feature each, the import's | |
| 5 | +//! refusals, and the export of changesets made in braid. | |
| 6 | + | |
| 7 | +mod common; | |
| 8 | + | |
| 9 | +use std::collections::BTreeMap; | |
| 10 | + | |
| 11 | +use braid_format::changeset::decode_change_list; | |
| 12 | +use braid_format::{ | |
| 13 | + Change, ChangeOp, Changes, Changeset, ChangesetParts, Entry, EntryKind, GitId, Kind, | |
| 14 | + MemoryObjects, ObjectId, Objects, Signature, build_directory, read_directory, | |
| 15 | +}; | |
| 16 | +use braid_git::{ | |
| 17 | + Error, GitKind, GitMap, GitOid, ImportOptions, RefTarget, RefUpdate, RoundTripReport, | |
| 18 | + export_commit, export_object, import, verify_round_trip, write_to_repo, | |
| 19 | +}; | |
| 20 | +use common::{Repo, exec, file, link, raw_tree, submodule}; | |
| 21 | + | |
| 22 | +fn oid(text: &str) -> GitOid { | |
| 23 | + text.parse().unwrap() | |
| 24 | +} | |
| 25 | + | |
| 26 | +fn round_trip(repo: &Repo) -> RoundTripReport { | |
| 27 | + let tmp = tempfile::tempdir().unwrap(); | |
| 28 | + let report = verify_round_trip(repo.path(), tmp.path()).unwrap_or_else(|err| panic!("{err}")); | |
| 29 | + assert_eq!(report.commits, repo.count_commits()); | |
| 30 | + report | |
| 31 | +} | |
| 32 | + | |
| 33 | +fn import_all(repo: &Repo, objects: &MemoryObjects, map: &mut GitMap) -> braid_git::ImportReport { | |
| 34 | + import(repo.path(), objects, map, &ImportOptions::default()) | |
| 35 | + .unwrap_or_else(|err| panic!("{err}")) | |
| 36 | +} | |
| 37 | + | |
| 38 | +/// The checks every fixture goes through: the round trip holds; importing | |
| 39 | +/// imports every commit; importing again with the saved map imports nothing; | |
| 40 | +/// after `extend` adds commits, importing brings in exactly those; the round | |
| 41 | +/// trip still holds; and every imported changeset passes admission. | |
| 42 | +fn check(repo: &mut Repo, extend: impl FnOnce(&mut Repo) -> usize) -> (MemoryObjects, GitMap) { | |
| 43 | + round_trip(repo); | |
| 44 | + let objects = MemoryObjects::new(); | |
| 45 | + let mut map = GitMap::new(); | |
| 46 | + let first = import_all(repo, &objects, &mut map); | |
| 47 | + assert_eq!(first.commits, repo.count_commits()); | |
| 48 | + assert_eq!(map.counts().commits, first.commits); | |
| 49 | + | |
| 50 | + let mut map = GitMap::from_bytes(&map.to_bytes()).unwrap(); | |
| 51 | + let again = import_all(repo, &objects, &mut map); | |
| 52 | + assert_eq!( | |
| 53 | + (again.commits, again.trees, again.blobs, again.tags), | |
| 54 | + (0, 0, 0, 0), | |
| 55 | + "nothing is new" | |
| 56 | + ); | |
| 57 | + assert_eq!(again.refs, first.refs); | |
| 58 | + | |
| 59 | + let added = extend(repo); | |
| 60 | + assert!(added > 0); | |
| 61 | + let next = import_all(repo, &objects, &mut map); | |
| 62 | + assert_eq!(next.commits, added, "only the new commits are imported"); | |
| 63 | + assert_eq!(map.counts().commits, repo.count_commits()); | |
| 64 | + round_trip(repo); | |
| 65 | + assert_admissible(&objects, &map); | |
| 66 | + (objects, map) | |
| 67 | +} | |
| 68 | + | |
| 69 | +fn decode(objects: &MemoryObjects, id: &ObjectId) -> Changeset { | |
| 70 | + let (kind, bytes) = objects.get(id).unwrap().unwrap(); | |
| 71 | + assert_eq!(kind, Kind::Changeset); | |
| 72 | + Changeset::decode(&bytes).unwrap() | |
| 73 | +} | |
| 74 | + | |
| 75 | +fn changeset(objects: &MemoryObjects, map: &GitMap, commit: &str) -> Changeset { | |
| 76 | + decode( | |
| 77 | + objects, | |
| 78 | + &map.changeset(&oid(commit)).expect("commit imported"), | |
| 79 | + ) | |
| 80 | +} | |
| 81 | + | |
| 82 | +fn change_list(objects: &MemoryObjects, changeset: &Changeset) -> Vec<Change> { | |
| 83 | + match &changeset.changes { | |
| 84 | + Changes::Inline(list) => list.clone(), | |
| 85 | + Changes::External { list, .. } => { | |
| 86 | + decode_change_list(&objects.get(list).unwrap().unwrap().1).unwrap() | |
| 87 | + } | |
| 88 | + } | |
| 89 | +} | |
| 90 | + | |
| 91 | +/// A directory held in memory, to apply change lists to. | |
| 92 | +type Dir = BTreeMap<Vec<u8>, Node>; | |
| 93 | + | |
| 94 | +#[derive(Clone, Debug)] | |
| 95 | +enum Node { | |
| 96 | + Leaf(EntryKind), | |
| 97 | + Dir(Dir), | |
| 98 | +} | |
| 99 | + | |
| 100 | +/// Reads a braid directory and everything below it, and checks that no | |
| 101 | +/// subdirectory is empty: braid trees never hold one. | |
| 102 | +fn load(objects: &MemoryObjects, tree: ObjectId) -> Dir { | |
| 103 | + let entries = | |
| 104 | + read_directory(tree, |id| objects.get(id).unwrap().map(|(_, bytes)| bytes)).unwrap(); | |
| 105 | + entries | |
| 106 | + .into_iter() | |
| 107 | + .map(|entry| { | |
| 108 | + let node = match entry.kind { | |
| 109 | + EntryKind::Tree { tree } => { | |
| 110 | + let below = load(objects, tree); | |
| 111 | + assert!( | |
| 112 | + !below.is_empty(), | |
| 113 | + "{:?} is an empty subdirectory", | |
| 114 | + String::from_utf8_lossy(&entry.name) | |
| 115 | + ); | |
| 116 | + Node::Dir(below) | |
| 117 | + } | |
| 118 | + kind => Node::Leaf(kind), | |
| 119 | + }; | |
| 120 | + (entry.name, node) | |
| 121 | + }) | |
| 122 | + .collect() | |
| 123 | +} | |
| 124 | + | |
| 125 | +/// The braid id of a directory held in memory. | |
| 126 | +fn tree_id(dir: &Dir) -> ObjectId { | |
| 127 | + let entries = dir | |
| 128 | + .iter() | |
| 129 | + .map(|(name, node)| Entry { | |
| 130 | + name: name.clone(), | |
| 131 | + kind: match node { | |
| 132 | + Node::Leaf(kind) => kind.clone(), | |
| 133 | + Node::Dir(below) => EntryKind::Tree { | |
| 134 | + tree: tree_id(below), | |
| 135 | + }, | |
| 136 | + }, | |
| 137 | + }) | |
| 138 | + .collect(); | |
| 139 | + build_directory(entries).unwrap().root() | |
| 140 | +} | |
| 141 | + | |
| 142 | +/// Applies a change list as the store's admission check does. Each change | |
| 143 | +/// gives a file's final value, so deletes go first; a directory goes with its | |
| 144 | +/// last entry, and setting a file creates the directories above it. | |
| 145 | +fn apply(dir: &mut Dir, changes: &[Change]) { | |
| 146 | + let split = |path: &[u8]| -> Vec<Vec<u8>> { | |
| 147 | + path.split(|byte| *byte == b'/') | |
| 148 | + .map(<[u8]>::to_vec) | |
| 149 | + .collect() | |
| 150 | + }; | |
| 151 | + for change in changes.iter().filter(|c| c.op == ChangeOp::Delete) { | |
| 152 | + delete(dir, &split(&change.path)); | |
| 153 | + } | |
| 154 | + for change in changes.iter().filter(|c| c.op != ChangeOp::Delete) { | |
| 155 | + set(dir, &split(&change.path), change.op.to_entry().unwrap()); | |
| 156 | + } | |
| 157 | +} | |
| 158 | + | |
| 159 | +fn delete(dir: &mut Dir, path: &[Vec<u8>]) { | |
| 160 | + match path { | |
| 161 | + [name] => assert!( | |
| 162 | + matches!(dir.remove(name), Some(Node::Leaf(_))), | |
| 163 | + "deleting a file that is not there" | |
| 164 | + ), | |
| 165 | + [name, rest @ ..] => { | |
| 166 | + let Some(Node::Dir(below)) = dir.get_mut(name) else { | |
| 167 | + panic!("deleting below a directory that is not there") | |
| 168 | + }; | |
| 169 | + delete(below, rest); | |
| 170 | + if below.is_empty() { | |
| 171 | + dir.remove(name); | |
| 172 | + } | |
| 173 | + } | |
| 174 | + [] => unreachable!("paths are never empty"), | |
| 175 | + } | |
| 176 | +} | |
| 177 | + | |
| 178 | +fn set(dir: &mut Dir, path: &[Vec<u8>], kind: EntryKind) { | |
| 179 | + match path { | |
| 180 | + [name] => { | |
| 181 | + let previous = dir.insert(name.clone(), Node::Leaf(kind)); | |
| 182 | + assert!( | |
| 183 | + !matches!(previous, Some(Node::Dir(_))), | |
| 184 | + "a file over a directory that still has entries" | |
| 185 | + ); | |
| 186 | + } | |
| 187 | + [name, rest @ ..] => { | |
| 188 | + let node = dir | |
| 189 | + .entry(name.clone()) | |
| 190 | + .or_insert_with(|| Node::Dir(Dir::new())); | |
| 191 | + let Node::Dir(below) = node else { | |
| 192 | + panic!("a directory over a file that was not deleted") | |
| 193 | + }; | |
| 194 | + set(below, rest, kind); | |
| 195 | + } | |
| 196 | + [] => unreachable!("paths are never empty"), | |
| 197 | + } | |
| 198 | +} | |
| 199 | + | |
| 200 | +/// Every imported changeset passes admission: its change list, applied to | |
| 201 | +/// the root of its first parent (or to nothing), gives its own root, and no | |
| 202 | +/// tree it holds has an empty subdirectory. | |
| 203 | +fn assert_admissible(objects: &MemoryObjects, map: &GitMap) { | |
| 204 | + for (commit, id) in map.commits() { | |
| 205 | + let changeset = decode(objects, &id); | |
| 206 | + let mut dir = match changeset.parents.first() { | |
| 207 | + Some(parent) => load(objects, decode(objects, parent).root), | |
| 208 | + None => Dir::new(), | |
| 209 | + }; | |
| 210 | + apply(&mut dir, &change_list(objects, &changeset)); | |
| 211 | + assert_eq!(tree_id(&dir), changeset.root, "commit {commit}"); | |
| 212 | + load(objects, changeset.root); | |
| 213 | + } | |
| 214 | +} | |
| 215 | + | |
| 216 | +/// The change list of an imported commit, as path and operation. | |
| 217 | +fn changes(objects: &MemoryObjects, map: &GitMap, commit: &str) -> Vec<(String, &'static str)> { | |
| 218 | + let list = change_list(objects, &changeset(objects, map, commit)); | |
| 219 | + list.into_iter() | |
| 220 | + .map(|change| { | |
| 221 | + let op = match change.op { | |
| 222 | + ChangeOp::Delete => "delete", | |
| 223 | + ChangeOp::File { .. } => "file", | |
| 224 | + ChangeOp::Executable { .. } => "executable", | |
| 225 | + ChangeOp::Symlink { .. } => "symlink", | |
| 226 | + ChangeOp::Gitlink { .. } => "gitlink", | |
| 227 | + }; | |
| 228 | + (String::from_utf8_lossy(&change.path).into_owned(), op) | |
| 229 | + }) | |
| 230 | + .collect() | |
| 231 | +} | |
| 232 | + | |
| 233 | +fn pairs(list: &[(&str, &'static str)]) -> Vec<(String, &'static str)> { | |
| 234 | + list.iter() | |
| 235 | + .map(|(path, op)| (path.to_string(), *op)) | |
| 236 | + .collect() | |
| 237 | +} | |
| 238 | + | |
| 239 | +#[test] | |
| 240 | +fn linear_history() { | |
| 241 | + let mut repo = Repo::new(); | |
| 242 | + let first = repo.snapshot( | |
| 243 | + "main", | |
| 244 | + &[ | |
| 245 | + file("README.md", "hello\n"), | |
| 246 | + file("src/lib.rs", "pub fn f() {}\n"), | |
| 247 | + file("src/util/mod.rs", ""), | |
| 248 | + ], | |
| 249 | + "first", | |
| 250 | + ); | |
| 251 | + let second = repo.snapshot( | |
| 252 | + "main", | |
| 253 | + &[ | |
| 254 | + file("README.md", "hello again\n"), | |
| 255 | + file("src/lib.rs", "pub fn f() {}\n"), | |
| 256 | + file("src/util/mod.rs", ""), | |
| 257 | + file("docs/guide.md", "guide\n"), | |
| 258 | + ], | |
| 259 | + "second", | |
| 260 | + ); | |
| 261 | + let third = repo.snapshot( | |
| 262 | + "main", | |
| 263 | + &[ | |
| 264 | + file("README.md", "hello again\n"), | |
| 265 | + file("docs/guide.md", "guide\n"), | |
| 266 | + ], | |
| 267 | + "third: drop src", | |
| 268 | + ); | |
| 269 | + let empty = repo.snapshot("main", &[], "everything deleted"); | |
| 270 | + let (objects, map) = check(&mut repo, |repo| { | |
| 271 | + repo.snapshot("main", &[file("README.md", "back\n")], "fourth"); | |
| 272 | + repo.snapshot("main", &[file("README.md", "and again\n")], "fifth"); | |
| 273 | + 2 | |
| 274 | + }); | |
| 275 | + assert_eq!( | |
| 276 | + changes(&objects, &map, &first), | |
| 277 | + pairs(&[ | |
| 278 | + ("README.md", "file"), | |
| 279 | + ("src/lib.rs", "file"), | |
| 280 | + ("src/util/mod.rs", "file") | |
| 281 | + ]) | |
| 282 | + ); | |
| 283 | + assert_eq!( | |
| 284 | + changes(&objects, &map, &second), | |
| 285 | + pairs(&[("README.md", "file"), ("docs/guide.md", "file")]) | |
| 286 | + ); | |
| 287 | + assert_eq!( | |
| 288 | + changes(&objects, &map, &third), | |
| 289 | + pairs(&[("src/lib.rs", "delete"), ("src/util/mod.rs", "delete")]) | |
| 290 | + ); | |
| 291 | + assert_eq!( | |
| 292 | + changes(&objects, &map, &empty), | |
| 293 | + pairs(&[("README.md", "delete"), ("docs/guide.md", "delete")]) | |
| 294 | + ); | |
| 295 | + let first_changeset = changeset(&objects, &map, &first); | |
| 296 | + assert!(first_changeset.parents.is_empty()); | |
| 297 | + assert_eq!(first_changeset.message, b"first\n"); | |
| 298 | + assert_eq!(first_changeset.author.name, b"Ada Lovelace"); | |
| 299 | + assert_eq!(first_changeset.author.email, b"ada@example.org"); | |
| 300 | + assert_eq!(first_changeset.author.offset_minutes, 60); | |
| 301 | + assert_eq!(first_changeset.committer.name, b"Charles Babbage"); | |
| 302 | + assert!(first_changeset.extras.is_empty()); | |
| 303 | + assert_eq!( | |
| 304 | + changeset(&objects, &map, &second).parents, | |
| 305 | + [map.changeset(&oid(&first)).unwrap()] | |
| 306 | + ); | |
| 307 | +} | |
| 308 | + | |
| 309 | +#[test] | |
| 310 | +fn branches_and_merges() { | |
| 311 | + let mut repo = Repo::new(); | |
| 312 | + let base = repo.snapshot("main", &[file("a", "1")], "base"); | |
| 313 | + for branch in ["left", "right", "third"] { | |
| 314 | + repo.set_ref(&format!("refs/heads/{branch}"), &base); | |
| 315 | + } | |
| 316 | + let left = repo.snapshot("left", &[file("a", "1"), file("l", "left")], "left"); | |
| 317 | + let right = repo.snapshot("right", &[file("a", "1"), file("r", "right")], "right"); | |
| 318 | + let third = repo.snapshot("third", &[file("a", "1"), file("t", "third")], "third"); | |
| 319 | + repo.snapshot("main", &[file("a", "2")], "main moves on"); | |
| 320 | + let merge = repo.merge( | |
| 321 | + "main", | |
| 322 | + &["left"], | |
| 323 | + &[file("a", "2"), file("l", "left")], | |
| 324 | + "merge left", | |
| 325 | + ); | |
| 326 | + let octopus = repo.merge( | |
| 327 | + "main", | |
| 328 | + &["right", "third"], | |
| 329 | + &[ | |
| 330 | + file("a", "2"), | |
| 331 | + file("l", "left"), | |
| 332 | + file("r", "right"), | |
| 333 | + file("t", "third"), | |
| 334 | + ], | |
| 335 | + "octopus", | |
| 336 | + ); | |
| 337 | + let (objects, map) = check(&mut repo, |repo| { | |
| 338 | + repo.snapshot("left", &[file("a", "1"), file("l", "more")], "left again"); | |
| 339 | + 1 | |
| 340 | + }); | |
| 341 | + assert_eq!(changes(&objects, &map, &merge), pairs(&[("l", "file")])); | |
| 342 | + assert_eq!( | |
| 343 | + changes(&objects, &map, &octopus), | |
| 344 | + pairs(&[("r", "file"), ("t", "file")]) | |
| 345 | + ); | |
| 346 | + let parents = changeset(&objects, &map, &octopus).parents; | |
| 347 | + assert_eq!(parents.len(), 3); | |
| 348 | + assert_eq!(parents[1], map.changeset(&oid(&right)).unwrap()); | |
| 349 | + assert_eq!(parents[2], map.changeset(&oid(&third)).unwrap()); | |
| 350 | + assert_eq!( | |
| 351 | + changeset(&objects, &map, &merge).parents[1], | |
| 352 | + map.changeset(&oid(&left)).unwrap() | |
| 353 | + ); | |
| 354 | +} | |
| 355 | + | |
| 356 | +#[test] | |
| 357 | +fn renames_and_a_directory_replaced_by_a_file() { | |
| 358 | + let mut repo = Repo::new(); | |
| 359 | + repo.snapshot( | |
| 360 | + "main", | |
| 361 | + &[ | |
| 362 | + file("old.txt", "content\n"), | |
| 363 | + file("dir/a", "a"), | |
| 364 | + file("dir/b/c", "c"), | |
| 365 | + ], | |
| 366 | + "start", | |
| 367 | + ); | |
| 368 | + let rename = repo.snapshot( | |
| 369 | + "main", | |
| 370 | + &[ | |
| 371 | + file("new.txt", "content\n"), | |
| 372 | + file("dir/a", "a"), | |
| 373 | + file("dir/b/c", "c"), | |
| 374 | + ], | |
| 375 | + "rename", | |
| 376 | + ); | |
| 377 | + let to_file = repo.snapshot( | |
| 378 | + "main", | |
| 379 | + &[file("new.txt", "content\n"), file("dir", "now a file\n")], | |
| 380 | + "directory to file", | |
| 381 | + ); | |
| 382 | + let to_dir = repo.snapshot( | |
| 383 | + "main", | |
| 384 | + &[file("new.txt", "content\n"), file("dir/x", "x")], | |
| 385 | + "file to directory", | |
| 386 | + ); | |
| 387 | + let (objects, map) = check(&mut repo, |repo| { | |
| 388 | + repo.snapshot("main", &[file("newer.txt", "content\n")], "rename again"); | |
| 389 | + 1 | |
| 390 | + }); | |
| 391 | + assert_eq!( | |
| 392 | + changes(&objects, &map, &rename), | |
| 393 | + pairs(&[("new.txt", "file"), ("old.txt", "delete")]) | |
| 394 | + ); | |
| 395 | + assert_eq!( | |
| 396 | + changes(&objects, &map, &to_file), | |
| 397 | + pairs(&[("dir", "file"), ("dir/a", "delete"), ("dir/b/c", "delete")]) | |
| 398 | + ); | |
| 399 | + assert_eq!( | |
| 400 | + changes(&objects, &map, &to_dir), | |
| 401 | + pairs(&[("dir", "delete"), ("dir/x", "file")]) | |
| 402 | + ); | |
| 403 | +} | |
| 404 | + | |
| 405 | +#[test] | |
| 406 | +fn symlinks_and_executable_bits() { | |
| 407 | + let mut repo = Repo::new(); | |
| 408 | + let links = [ | |
| 409 | + link("latest", "run.sh"), | |
| 410 | + link("dangling", "nowhere/at/all"), | |
| 411 | + link("outside", "../../etc"), | |
| 412 | + link("dir/up", ".."), | |
| 413 | + ]; | |
| 414 | + let mut entries = vec![file("run.sh", "#!/bin/sh\necho hi\n")]; | |
| 415 | + entries.extend(links.iter().cloned()); | |
| 416 | + repo.snapshot("main", &entries, "links"); | |
| 417 | + entries[0] = exec("run.sh", "#!/bin/sh\necho hi\n"); | |
| 418 | + let chmod = repo.snapshot("main", &entries, "make it executable"); | |
| 419 | + entries[1] = file("latest", "run.sh"); | |
| 420 | + let unlink = repo.snapshot("main", &entries, "a link becomes a file"); | |
| 421 | + let (objects, map) = check(&mut repo, |repo| { | |
| 422 | + entries[0] = file("run.sh", "#!/bin/sh\necho hi\n"); | |
| 423 | + repo.snapshot("main", &entries, "not executable any more"); | |
| 424 | + 1 | |
| 425 | + }); | |
| 426 | + assert_eq!( | |
| 427 | + changes(&objects, &map, &chmod), | |
| 428 | + pairs(&[("run.sh", "executable")]) | |
| 429 | + ); | |
| 430 | + assert_eq!( | |
| 431 | + changes(&objects, &map, &unlink), | |
| 432 | + pairs(&[("latest", "file")]) | |
| 433 | + ); | |
| 434 | +} | |
| 435 | + | |
| 436 | +const SUBMODULE_A: &str = "1111111111111111111111111111111111111111"; | |
| 437 | +const SUBMODULE_B: &str = "2222222222222222222222222222222222222222"; | |
| 438 | + | |
| 439 | +#[test] | |
| 440 | +fn submodule_gitlinks() { | |
| 441 | + let mut repo = Repo::new(); | |
| 442 | + let text = "[submodule \"vendor\"]\n\tpath = vendor\n\turl = https://example.org/vendor.git\n"; | |
| 443 | + let modules = file(".gitmodules", text); | |
| 444 | + // The gitlink goes in through the index, as `git submodule add` does. | |
| 445 | + let modules_blob = repo.blob(text.as_bytes()); | |
| 446 | + let tree = repo.index_tree(&[ | |
| 447 | + format!("100644,{modules_blob},.gitmodules"), | |
| 448 | + format!("160000,{SUBMODULE_A},vendor"), | |
| 449 | + ]); | |
| 450 | + assert_eq!( | |
| 451 | + tree, | |
| 452 | + repo.tree(&[modules.clone(), submodule("vendor", SUBMODULE_A)]) | |
| 453 | + ); | |
| 454 | + let add = repo.commit(&tree, &[], "add a submodule"); | |
| 455 | + repo.set_ref("refs/heads/main", &add); | |
| 456 | + let bump = repo.snapshot( | |
| 457 | + "main", | |
| 458 | + &[modules.clone(), submodule("vendor", SUBMODULE_B)], | |
| 459 | + "bump it", | |
| 460 | + ); | |
| 461 | + let (objects, map) = check(&mut repo, |repo| { | |
| 462 | + repo.snapshot("main", &[file(".gitmodules", "")], "remove it"); | |
| 463 | + 1 | |
| 464 | + }); | |
| 465 | + assert_eq!( | |
| 466 | + changes(&objects, &map, &add), | |
| 467 | + pairs(&[(".gitmodules", "file"), ("vendor", "gitlink")]) | |
| 468 | + ); | |
| 469 | + assert_eq!( | |
| 470 | + changes(&objects, &map, &bump), | |
| 471 | + pairs(&[("vendor", "gitlink")]) | |
| 472 | + ); | |
| 473 | +} | |
| 474 | + | |
| 475 | +#[test] | |
| 476 | +fn awkward_names_and_contents() { | |
| 477 | + let mut repo = Repo::new(); | |
| 478 | + let mut entries: Vec<common::Entry> = vec![ | |
| 479 | + file(b"latin1-caf\xe9.txt", "a Latin-1 name\n"), | |
| 480 | + file(b"\xff\xfe\xfd", "not UTF-8 at all\n"), | |
| 481 | + file("café.txt", "precomposed\n"), | |
| 482 | + file("cafe\u{301}.txt", "decomposed\n"), | |
| 483 | + file("🦀.rs", "fn crab() {}\n"), | |
| 484 | + file("日本語/ファイル.txt", "日本語\n"), | |
| 485 | + file("עברית.txt", "right to left\n"), | |
| 486 | + file("zero\u{200d}width.txt", "joiner\n"), | |
| 487 | + file("with space/and tab\there", "x"), | |
| 488 | + file("-leading-dash", "x"), | |
| 489 | + file("#hash", "x"), | |
| 490 | + file(".hidden", "x"), | |
| 491 | + file("a:b", "a colon"), | |
| 492 | + file("back\\slash", "x"), | |
| 493 | + file("x".repeat(255), "a long name"), | |
| 494 | + file("empty", ""), | |
| 495 | + file("no-newline", "last line"), | |
| 496 | + file("crlf.txt", "a\r\nb\r\n"), | |
| 497 | + file("binary.bin", [0u8, 1, 2, 255, 0, 10, 13]), | |
| 498 | + ]; | |
| 499 | + let first = repo.snapshot("main", &entries, "awkward"); | |
| 500 | + let (objects, map) = check(&mut repo, |repo| { | |
| 501 | + entries[1] = file(b"\xff\xfe\xfd", "still not UTF-8\n"); | |
| 502 | + entries.push(file(b"dir-\xc0/inner", "under a non-UTF-8 directory")); | |
| 503 | + repo.snapshot("main", &entries, "more"); | |
| 504 | + 1 | |
| 505 | + }); | |
| 506 | + let listed = changes(&objects, &map, &first); | |
| 507 | + assert_eq!(listed.len(), 19); | |
| 508 | + let changeset = changeset(&objects, &map, &first); | |
| 509 | + let Changes::Inline(list) = changeset.changes else { | |
| 510 | + panic!("a short list is inline") | |
| 511 | + }; | |
| 512 | + assert!( | |
| 513 | + list.iter() | |
| 514 | + .any(|change| change.path == b"latin1-caf\xe9.txt") | |
| 515 | + ); | |
| 516 | + assert!( | |
| 517 | + list.iter() | |
| 518 | + .any(|change| change.path == "cafe\u{301}.txt".as_bytes()) | |
| 519 | + ); | |
| 520 | +} | |
| 521 | + | |
| 522 | +#[test] | |
| 523 | +fn crafted_commits_keep_their_bytes() { | |
| 524 | + let mut repo = Repo::new(); | |
| 525 | + let base = repo.snapshot("main", &[file("a", "1")], "base"); | |
| 526 | + let tree = repo.tree(&[file("a", "1")]); | |
| 527 | + let headers = |parent: &str, author: &str, committer: &str| { | |
| 528 | + format!("tree {tree}\nparent {parent}\nauthor {author}\ncommitter {committer}\n") | |
| 529 | + }; | |
| 530 | + let ada = "Ada Lovelace <ada@example.org> 1700000000 +0100"; | |
| 531 | + | |
| 532 | + let mut latin1 = headers(&base, ada, ada).into_bytes(); | |
| 533 | + latin1.extend_from_slice(b"encoding ISO-8859-1\n\nCaf\xe9 cr\xe8me\n"); | |
| 534 | + let latin1 = repo.literally("commit", &latin1); | |
| 535 | + | |
| 536 | + let extra = format!( | |
| 537 | + "{}x-custom value\nmulti first\n continued\n \n after a blank line\n\ | |
| 538 | + gpgsig -----BEGIN PGP SIGNATURE-----\n \n iQEzBAABCAAdFiEE\n -----END PGP SIGNATURE-----\n\ | |
| 539 | + \nlooks signed\n", | |
| 540 | + headers(&latin1, ada, ada) | |
| 541 | + ); | |
| 542 | + let extra = repo.literally("commit", extra.as_bytes()); | |
| 543 | + | |
| 544 | + let odd = format!( | |
| 545 | + "{}\nno trailing newline", | |
| 546 | + headers( | |
| 547 | + &extra, | |
| 548 | + "Odd<odd@example.org>1700000123 -0000", | |
| 549 | + " <> 0 +0000" | |
| 550 | + ) | |
| 551 | + ); | |
| 552 | + let odd = repo.literally("commit", odd.as_bytes()); | |
| 553 | + | |
| 554 | + let bare = headers(&odd, ada, "Strange Zone <z@example.org> 1700000000 +1560"); | |
| 555 | + let bare = repo.literally("commit", bare.as_bytes()); | |
| 556 | + | |
| 557 | + let uppercase = format!( | |
| 558 | + "tree {}\nparent {bare}\nauthor {ada}\ncommitter {ada}\n\nupper-case tree id\n", | |
| 559 | + tree.to_uppercase() | |
| 560 | + ); | |
| 561 | + let uppercase = repo.literally("commit", uppercase.as_bytes()); | |
| 562 | + repo.set_ref("refs/heads/crafted", &uppercase); | |
| 563 | + | |
| 564 | + let (objects, map) = check(&mut repo, |repo| { | |
| 565 | + repo.snapshot("crafted", &[file("a", "2")], "ordinary again"); | |
| 566 | + 1 | |
| 567 | + }); | |
| 568 | + | |
| 569 | + for commit in [&latin1, &extra, &odd, &bare, &uppercase] { | |
| 570 | + let changeset = changeset(&objects, &map, commit); | |
| 571 | + let origin = objects | |
| 572 | + .get(&changeset.git_origin.unwrap()) | |
| 573 | + .unwrap() | |
| 574 | + .unwrap() | |
| 575 | + .1; | |
| 576 | + assert_eq!(origin, repo.git_bytes(&["cat-file", "commit", commit])); | |
| 577 | + assert!(changeset.extras.is_empty()); | |
| 578 | + } | |
| 579 | + assert_eq!( | |
| 580 | + changeset(&objects, &map, &latin1).message, | |
| 581 | + b"Caf\xe9 cr\xe8me\n" | |
| 582 | + ); | |
| 583 | + assert_eq!(changeset(&objects, &map, &extra).message, b"looks signed\n"); | |
| 584 | + let odd = changeset(&objects, &map, &odd); | |
| 585 | + assert_eq!(odd.message, b"no trailing newline"); | |
| 586 | + assert_eq!( | |
| 587 | + (odd.author.name.as_slice(), odd.author.email.as_slice()), | |
| 588 | + (&b"Odd"[..], &b"odd@example.org"[..]) | |
| 589 | + ); | |
| 590 | + assert_eq!( | |
| 591 | + (odd.author.seconds, odd.author.offset_minutes), | |
| 592 | + (1_700_000_123, 0) | |
| 593 | + ); | |
| 594 | + assert_eq!(odd.committer.name, b""); | |
| 595 | + assert_eq!(odd.committer.seconds, 0); | |
| 596 | + let bare = changeset(&objects, &map, &bare); | |
| 597 | + assert_eq!(bare.message, b""); | |
| 598 | + assert_eq!(bare.committer.offset_minutes, 15 * 60 + 60); | |
| 599 | + assert_eq!(changes(&objects, &map, &uppercase), pairs(&[])); | |
| 600 | +} | |
| 601 | + | |
| 602 | +#[test] | |
| 603 | +fn non_canonical_trees_keep_their_raw_bytes() { | |
| 604 | + let mut repo = Repo::new(); | |
| 605 | + let x = repo.blob(b"x\n"); | |
| 606 | + let y = repo.blob(b"y\n"); | |
| 607 | + let inner = repo.tree(&[file("inner", "x\n")]); | |
| 608 | + let group_writable = repo.literally("tree", &raw_tree(&[("100664", b"group-writable", &x)])); | |
| 609 | + let padded = repo.literally("tree", &raw_tree(&[("040000", b"dir", &inner)])); | |
| 610 | + let padded_file = repo.literally("tree", &raw_tree(&[("0100644", b"f", &x)])); | |
| 611 | + let unsorted = repo.literally( | |
| 612 | + "tree", | |
| 613 | + &raw_tree(&[("100644", b"b", &x), ("100644", b"a", &y)]), | |
| 614 | + ); | |
| 615 | + let duplicate = repo.literally( | |
| 616 | + "tree", | |
| 617 | + &raw_tree(&[("100644", b"same", &x), ("100644", b"same", &y)]), | |
| 618 | + ); | |
| 619 | + let file_and_dir = repo.literally( | |
| 620 | + "tree", | |
| 621 | + &raw_tree(&[("100644", b"twice", &x), ("40000", b"twice", &inner)]), | |
| 622 | + ); | |
| 623 | + // Canonical on its own, but it names a tree that is not. | |
| 624 | + let holder = repo.mktree(&[("40000", "tree", &group_writable, b"nested")]); | |
| 625 | + let odd_trees = [ | |
| 626 | + ("100664", &group_writable), | |
| 627 | + ("padded", &padded), | |
| 628 | + ("padded-file", &padded_file), | |
| 629 | + ("unsorted", &unsorted), | |
| 630 | + ("duplicate", &duplicate), | |
| 631 | + ("file-and-dir", &file_and_dir), | |
| 632 | + ("holder", &holder), | |
| 633 | + ]; | |
| 634 | + let root_with = |repo: &Repo, plain: &str| { | |
| 635 | + let plain = repo.blob(plain.as_bytes()); | |
| 636 | + let mut entries: Vec<(&str, &str, &str, &[u8])> = odd_trees | |
| 637 | + .iter() | |
| 638 | + .map(|(name, id)| ("40000", "tree", id.as_str(), name.as_bytes())) | |
| 639 | + .collect(); | |
| 640 | + entries.push(("100644", "blob", &plain, b"plain")); | |
| 641 | + entries.push(("40000", "tree", &inner, b"canonical")); | |
| 642 | + repo.mktree(&entries) | |
| 643 | + }; | |
| 644 | + let first_root = root_with(&repo, "one\n"); | |
| 645 | + let first = repo.commit(&first_root, &[], "odd trees"); | |
| 646 | + let second_root = root_with(&repo, "two\n"); | |
| 647 | + let second = repo.commit(&second_root, &[&first], "edit beside them"); | |
| 648 | + repo.set_ref("refs/heads/main", &second); | |
| 649 | + | |
| 650 | + let (objects, map) = check(&mut repo, |repo| { | |
| 651 | + let third_root = root_with(repo, "three\n"); | |
| 652 | + let third = repo.commit(&third_root, &[&second], "again"); | |
| 653 | + repo.set_ref("refs/heads/main", &third); | |
| 654 | + 1 | |
| 655 | + }); | |
| 656 | + for (name, id) in odd_trees { | |
| 657 | + assert!(map.raw_tree(&oid(id)).is_some(), "{name} keeps its bytes"); | |
| 658 | + assert_eq!( | |
| 659 | + export_object(&objects, &map, &oid(id)).unwrap(), | |
| 660 | + (GitKind::Tree, repo.git_bytes(&["cat-file", "tree", id])) | |
| 661 | + ); | |
| 662 | + } | |
| 663 | + assert!( | |
| 664 | + map.raw_tree(&oid(&first_root)).is_some(), | |
| 665 | + "it holds odd trees" | |
| 666 | + ); | |
| 667 | + assert!(map.raw_tree(&oid(&inner)).is_none(), "canonical"); | |
| 668 | + assert_eq!(map.counts().raw_trees, odd_trees.len() + 3); | |
| 669 | + assert_eq!( | |
| 670 | + changes(&objects, &map, &second), | |
| 671 | + pairs(&[("plain", "file")]) | |
| 672 | + ); | |
| 673 | + | |
| 674 | + // Braid reads `100664` as a plain file, keeps the last of duplicate | |
| 675 | + // names as a git checkout does, and sorts by name bytes. | |
| 676 | + let entries = |tree: &str| { | |
| 677 | + let root = map.tree(&oid(tree)).unwrap(); | |
| 678 | + let (_, bytes) = objects.get(&root).unwrap().unwrap(); | |
| 679 | + match braid_format::Node::decode(&bytes).unwrap() { | |
| 680 | + braid_format::Node::Flat(entries) => entries, | |
| 681 | + other => panic!("unexpected node {other:?}"), | |
| 682 | + } | |
| 683 | + }; | |
| 684 | + assert!(matches!( | |
| 685 | + entries(&group_writable)[0].kind, | |
| 686 | + EntryKind::File { size: 2, .. } | |
| 687 | + )); | |
| 688 | + let names: Vec<Vec<u8>> = entries(&unsorted).into_iter().map(|e| e.name).collect(); | |
| 689 | + assert_eq!(names, [b"a".to_vec(), b"b".to_vec()]); | |
| 690 | + let same = entries(&duplicate); | |
| 691 | + assert_eq!(same.len(), 1); | |
| 692 | + assert!(matches!( | |
| 693 | + same[0].kind, | |
| 694 | + EntryKind::File { blob, .. } if blob == ObjectId::hash(Kind::Blob, b"y\n") | |
| 695 | + )); | |
| 696 | + assert!(matches!( | |
| 697 | + entries(&file_and_dir)[0].kind, | |
| 698 | + EntryKind::Tree { .. } | |
| 699 | + )); | |
| 700 | + | |
| 701 | + // Git agrees: reading the duplicates into an index keeps the last one. | |
| 702 | + let index = repo.scratch().join("duplicates-index"); | |
| 703 | + let mut read_tree = repo.command(); | |
| 704 | + read_tree.env("GIT_INDEX_FILE", &index); | |
| 705 | + read_tree.args(["read-tree", &duplicate]); | |
| 706 | + assert!(read_tree.status().unwrap().success()); | |
| 707 | + let mut list = repo.command(); | |
| 708 | + list.env("GIT_INDEX_FILE", &index); | |
| 709 | + list.args(["ls-files", "--stage"]); | |
| 710 | + let listed = String::from_utf8(list.output().unwrap().stdout).unwrap(); | |
| 711 | + assert_eq!(listed, format!("100644 {y} 0\tsame\n")); | |
| 712 | +} | |
| 713 | + | |
| 714 | +#[test] | |
| 715 | +fn annotated_tags() { | |
| 716 | + let mut repo = Repo::new(); | |
| 717 | + let first = repo.snapshot("main", &[file("a", "1")], "first"); | |
| 718 | + let v1 = repo.annotated_tag("v1", &first, "release 1"); | |
| 719 | + repo.git(&["tag", "lightweight", &first]); | |
| 720 | + let nested = repo.annotated_tag("v1-blessed", &v1, "a tag of a tag"); | |
| 721 | + let tree = repo.tree(&[file("only-in-a-tag", "t\n"), file("dir/deeper", "d\n")]); | |
| 722 | + let tree_tag = repo.annotated_tag("tree-tag", &tree, "points to a tree"); | |
| 723 | + let blob = repo.blob(b"a blob on its own\n"); | |
| 724 | + let blob_tag = repo.annotated_tag("blob-tag", &blob, "points to a blob"); | |
| 725 | + repo.git(&["tag", "lightweight-tree", &tree]); | |
| 726 | + let (objects, map) = check(&mut repo, |repo| { | |
| 727 | + let second = repo.snapshot("main", &[file("a", "2")], "second"); | |
| 728 | + repo.annotated_tag("v2", &second, "release 2"); | |
| 729 | + repo.git(&["tag", "--force", "moved", &v1]); | |
| 730 | + 1 | |
| 731 | + }); | |
| 732 | + // A name that pointed to an annotated tag and now is lightweight. | |
| 733 | + let mut map = map; | |
| 734 | + let moved = repo.git(&["rev-parse", "refs/tags/moved"]); | |
| 735 | + assert_eq!(map.tag_by_name(b"refs/tags/moved").unwrap().0, oid(&moved)); | |
| 736 | + repo.git(&["tag", "--force", "moved", &first]); | |
| 737 | + import_all(&repo, &objects, &mut map); | |
| 738 | + assert!(map.tag_by_name(b"refs/tags/moved").is_none()); | |
| 739 | + | |
| 740 | + let (tag, entry) = map.tag_by_name(b"refs/tags/v1").unwrap(); | |
| 741 | + assert_eq!(tag, oid(&v1)); | |
| 742 | + assert_eq!( | |
| 743 | + (entry.target, entry.target_kind), | |
| 744 | + (oid(&first), GitKind::Commit) | |
| 745 | + ); | |
| 746 | + assert_eq!( | |
| 747 | + objects.get(&entry.raw).unwrap().unwrap().1, | |
| 748 | + repo.git_bytes(&["cat-file", "tag", &v1]) | |
| 749 | + ); | |
| 750 | + let (_, entry) = map.tag_by_name(b"refs/tags/v1-blessed").unwrap(); | |
| 751 | + assert_eq!((entry.target, entry.target_kind), (oid(&v1), GitKind::Tag)); | |
| 752 | + let (_, entry) = map.tag_by_name(b"refs/tags/tree-tag").unwrap(); | |
| 753 | + assert_eq!( | |
| 754 | + (entry.target, entry.target_kind), | |
| 755 | + (oid(&tree), GitKind::Tree) | |
| 756 | + ); | |
| 757 | + let (_, entry) = map.tag_by_name(b"refs/tags/blob-tag").unwrap(); | |
| 758 | + assert_eq!( | |
| 759 | + (entry.target, entry.target_kind), | |
| 760 | + (oid(&blob), GitKind::Blob) | |
| 761 | + ); | |
| 762 | + assert!(map.tag_by_name(b"refs/tags/lightweight").is_none()); | |
| 763 | + assert!(map.tag_by_name(b"refs/tags/v2").is_some()); | |
| 764 | + assert_eq!(map.counts().tags, 5); | |
| 765 | + for tag in [&v1, &nested, &tree_tag, &blob_tag] { | |
| 766 | + assert_eq!( | |
| 767 | + map.git_tag(&map.tag(&oid(tag)).unwrap().raw), | |
| 768 | + Some(oid(tag)) | |
| 769 | + ); | |
| 770 | + } | |
| 771 | +} | |
| 772 | + | |
| 773 | +#[test] | |
| 774 | +fn a_directory_with_more_than_1024_files() { | |
| 775 | + let mut repo = Repo::new(); | |
| 776 | + let mut entries: Vec<common::Entry> = (0..1100) | |
| 777 | + .map(|i| file(format!("big/f{i:04}.txt"), format!("{i}\n"))) | |
| 778 | + .collect(); | |
| 779 | + entries.push(file("README", "a big directory\n")); | |
| 780 | + repo.snapshot("main", &entries, "many files"); | |
| 781 | + entries[500] = file("big/f0500.txt", "changed\n"); | |
| 782 | + entries.push(file("big/zz-new", "new\n")); | |
| 783 | + let edit = repo.snapshot("main", &entries, "edit one, add one"); | |
| 784 | + let (objects, map) = check(&mut repo, |repo| { | |
| 785 | + entries.retain(|(path, _)| path != b"big/f0007.txt"); | |
| 786 | + repo.snapshot("main", &entries, "delete one"); | |
| 787 | + 1 | |
| 788 | + }); | |
| 789 | + assert_eq!( | |
| 790 | + changes(&objects, &map, &edit), | |
| 791 | + pairs(&[("big/f0500.txt", "file"), ("big/zz-new", "file")]) | |
| 792 | + ); | |
| 793 | + // The braid side of `big` is split into several nodes. | |
| 794 | + let root = changeset(&objects, &map, &edit).root; | |
| 795 | + let (_, bytes) = objects.get(&root).unwrap().unwrap(); | |
| 796 | + let braid_format::Node::Flat(top) = braid_format::Node::decode(&bytes).unwrap() else { | |
| 797 | + panic!("the root is small") | |
| 798 | + }; | |
| 799 | + let big = top.iter().find(|e| e.name == b"big").unwrap(); | |
| 800 | + let EntryKind::Tree { tree } = big.kind else { | |
| 801 | + panic!("big is a directory") | |
| 802 | + }; | |
| 803 | + let (_, bytes) = objects.get(&tree).unwrap().unwrap(); | |
| 804 | + assert!(matches!( | |
| 805 | + braid_format::Node::decode(&bytes).unwrap(), | |
| 806 | + braid_format::Node::Internal { .. } | |
| 807 | + )); | |
| 808 | +} | |
| 809 | + | |
| 810 | +#[test] | |
| 811 | +fn replacement_objects_and_grafts_are_ignored() { | |
| 812 | + let mut repo = Repo::new(); | |
| 813 | + let first = repo.snapshot("main", &[file("a", "1")], "one"); | |
| 814 | + let second = repo.snapshot("main", &[file("a", "2")], "two"); | |
| 815 | + let fake_tree = repo.tree(&[file("a", "fake")]); | |
| 816 | + let fake = repo.commit(&fake_tree, &[], "a replacement"); | |
| 817 | + repo.git(&["replace", &second, &fake]); | |
| 818 | + std::fs::write(repo.path().join("info/grafts"), format!("{second}\n")).unwrap(); | |
| 819 | + let (objects, map) = check(&mut repo, |repo| { | |
| 820 | + repo.snapshot("main", &[file("a", "3")], "three"); | |
| 821 | + 1 | |
| 822 | + }); | |
| 823 | + assert_eq!( | |
| 824 | + changeset(&objects, &map, &second).parents, | |
| 825 | + [map.changeset(&oid(&first)).unwrap()] | |
| 826 | + ); | |
| 827 | + assert_eq!(changes(&objects, &map, &second), pairs(&[("a", "file")])); | |
| 828 | + assert!(map.changeset(&oid(&fake)).is_none()); | |
| 829 | +} | |
| 830 | + | |
| 831 | +#[test] | |
| 832 | +fn selected_refs_only() { | |
| 833 | + let mut repo = Repo::new(); | |
| 834 | + let base = repo.snapshot("main", &[file("a", "1")], "base"); | |
| 835 | + repo.set_ref("refs/heads/side", &base); | |
| 836 | + repo.snapshot("side", &[file("b", "2")], "side"); | |
| 837 | + let objects = MemoryObjects::new(); | |
| 838 | + let mut map = GitMap::new(); | |
| 839 | + let options = ImportOptions { | |
| 840 | + refs: vec![b"main".to_vec()], | |
| 841 | + }; | |
| 842 | + let report = import(repo.path(), &objects, &mut map, &options).unwrap(); | |
| 843 | + assert_eq!(report.commits, 1); | |
| 844 | + assert_eq!(report.refs.len(), 1); | |
| 845 | + assert_eq!(report.refs[0].name, b"refs/heads/main"); | |
| 846 | + let missing = ImportOptions { | |
| 847 | + refs: vec![b"refs/heads/nope".to_vec()], | |
| 848 | + }; | |
| 849 | + assert!(matches!( | |
| 850 | + import(repo.path(), &objects, &mut map, &missing), | |
| 851 | + Err(Error::MissingRef(_)) | |
| 852 | + )); | |
| 853 | +} | |
| 854 | + | |
| 855 | +#[test] | |
| 856 | +fn shallow_clones_are_refused() { | |
| 857 | + let mut repo = Repo::new(); | |
| 858 | + for i in 0..3 { | |
| 859 | + repo.snapshot("main", &[file("a", format!("{i}"))], "commit"); | |
| 860 | + } | |
| 861 | + let shallow = repo.scratch().join("shallow.git"); | |
| 862 | + let url = format!("file://{}", repo.path().display()); | |
| 863 | + let mut clone = repo.command(); | |
| 864 | + clone.args(["clone", "--quiet", "--bare", "--depth", "1", &url]); | |
| 865 | + clone.arg(&shallow); | |
| 866 | + assert!(clone.status().unwrap().success()); | |
| 867 | + let err = import( | |
| 868 | + &shallow, | |
| 869 | + &MemoryObjects::new(), | |
| 870 | + &mut GitMap::new(), | |
| 871 | + &ImportOptions::default(), | |
| 872 | + ) | |
| 873 | + .unwrap_err(); | |
| 874 | + assert!(matches!(err, Error::Shallow), "{err}"); | |
| 875 | + assert!(err.to_string().contains("shallow")); | |
| 876 | +} | |
| 877 | + | |
| 878 | +#[test] | |
| 879 | +fn sha256_repositories_are_refused() { | |
| 880 | + let mut repo = Repo::init(&["--object-format=sha256"]); | |
| 881 | + repo.snapshot("main", &[file("a", "1")], "a SHA-256 commit"); | |
| 882 | + let err = import( | |
| 883 | + repo.path(), | |
| 884 | + &MemoryObjects::new(), | |
| 885 | + &mut GitMap::new(), | |
| 886 | + &ImportOptions::default(), | |
| 887 | + ) | |
| 888 | + .unwrap_err(); | |
| 889 | + assert!(matches!(err, Error::Sha256), "{err}"); | |
| 890 | + assert!(err.to_string().contains("SHA-256")); | |
| 891 | + let tmp = tempfile::tempdir().unwrap(); | |
| 892 | + assert!(matches!( | |
| 893 | + verify_round_trip(repo.path(), tmp.path()), | |
| 894 | + Err(Error::Sha256) | |
| 895 | + )); | |
| 896 | +} | |
| 897 | + | |
| 898 | +/// Builds a commit whose tree holds `evil` (a path of names) as a directory | |
| 899 | +/// with a hook inside, and checks the import refuses it by commit and path. | |
| 900 | +fn refused(evil: &[&[u8]], expected_path: &[u8]) { | |
| 901 | + let mut repo = Repo::new(); | |
| 902 | + let hook = repo.tree(&[exec("hooks/post-checkout", "#!/bin/sh\necho owned\n")]); | |
| 903 | + let mut id = hook; | |
| 904 | + for name in evil.iter().rev() { | |
| 905 | + id = repo.literally("tree", &raw_tree(&[("40000", name, &id)])); | |
| 906 | + } | |
| 907 | + let commit = repo.commit(&id, &[], "evil"); | |
| 908 | + repo.set_ref("refs/heads/main", &commit); | |
| 909 | + let err = import( | |
| 910 | + repo.path(), | |
| 911 | + &MemoryObjects::new(), | |
| 912 | + &mut GitMap::new(), | |
| 913 | + &ImportOptions::default(), | |
| 914 | + ) | |
| 915 | + .unwrap_err(); | |
| 916 | + match &err { | |
| 917 | + Error::RefusedPath { | |
| 918 | + commit: c, path, .. | |
| 919 | + } => { | |
| 920 | + assert_eq!(c, &oid(&commit)); | |
| 921 | + assert_eq!(path, expected_path); | |
| 922 | + } | |
| 923 | + other => panic!("expected a refused path, got {other}"), | |
| 924 | + } | |
| 925 | + assert!(err.to_string().contains(&commit), "{err}"); | |
| 926 | +} | |
| 927 | + | |
| 928 | +#[test] | |
| 929 | +fn names_that_alias_dot_git_are_refused() { | |
| 930 | + refused(&[b".git"], b".git"); | |
| 931 | + refused(&[b".GIT"], b".GIT"); | |
| 932 | + refused(&[b".Git."], b".Git."); | |
| 933 | + refused(&[b"GIT~1"], b"GIT~1"); | |
| 934 | + refused(&[".g\u{200c}it".as_bytes()], ".g\u{200c}it".as_bytes()); | |
| 935 | + refused(&[b".braid"], b".braid"); | |
| 936 | + refused(&[b"sub", b"deeper", b".git"], b"sub/deeper/.git"); | |
| 937 | + refused(&[b".."], b".."); | |
| 938 | + refused(&[b"a/b"], b"a/b"); | |
| 939 | +} | |
| 940 | + | |
| 941 | +#[test] | |
| 942 | +fn symlinks_on_files_git_reads_are_refused() { | |
| 943 | + let mut repo = Repo::new(); | |
| 944 | + let target = repo.blob(b"/etc/passwd"); | |
| 945 | + let tree = repo.literally("tree", &raw_tree(&[("120000", b".gitmodules", &target)])); | |
| 946 | + let commit = repo.commit(&tree, &[], "evil link"); | |
| 947 | + repo.set_ref("refs/heads/main", &commit); | |
| 948 | + let err = import( | |
| 949 | + repo.path(), | |
| 950 | + &MemoryObjects::new(), | |
| 951 | + &mut GitMap::new(), | |
| 952 | + &ImportOptions::default(), | |
| 953 | + ) | |
| 954 | + .unwrap_err(); | |
| 955 | + assert!( | |
| 956 | + matches!(&err, Error::RefusedPath { path, .. } if path == b".gitmodules"), | |
| 957 | + "{err}" | |
| 958 | + ); | |
| 959 | +} | |
| 960 | + | |
| 961 | +#[test] | |
| 962 | +fn unknown_modes_are_refused() { | |
| 963 | + let mut repo = Repo::new(); | |
| 964 | + let x = repo.blob(b"x"); | |
| 965 | + let tree = repo.literally("tree", &raw_tree(&[("20000", b"device", &x)])); | |
| 966 | + let commit = repo.commit(&tree, &[], "odd mode"); | |
| 967 | + repo.set_ref("refs/heads/main", &commit); | |
| 968 | + let err = import( | |
| 969 | + repo.path(), | |
| 970 | + &MemoryObjects::new(), | |
| 971 | + &mut GitMap::new(), | |
| 972 | + &ImportOptions::default(), | |
| 973 | + ) | |
| 974 | + .unwrap_err(); | |
| 975 | + assert!( | |
| 976 | + matches!(&err, Error::UnsupportedMode { path, mode, .. } if path == b"device" && mode == b"20000"), | |
| 977 | + "{err}" | |
| 978 | + ); | |
| 979 | +} | |
| 980 | + | |
| 981 | +fn store_tree(objects: &MemoryObjects, entries: Vec<Entry>) -> ObjectId { | |
| 982 | + let directory = build_directory(entries).unwrap(); | |
| 983 | + for (_, bytes) in &directory.nodes { | |
| 984 | + objects.put(Kind::Tree, bytes).unwrap(); | |
| 985 | + } | |
| 986 | + directory.root() | |
| 987 | +} | |
| 988 | + | |
| 989 | +fn store_blob(objects: &MemoryObjects, content: &[u8]) -> (ObjectId, u64) { | |
| 990 | + ( | |
| 991 | + objects.put(Kind::Blob, content).unwrap(), | |
| 992 | + content.len() as u64, | |
| 993 | + ) | |
| 994 | +} | |
| 995 | + | |
| 996 | +#[test] | |
| 997 | +fn changesets_made_in_braid_export_deterministically() { | |
| 998 | + let mut repo = Repo::new(); | |
| 999 | + let imported = repo.snapshot( | |
| 1000 | + "main", | |
| 1001 | + &[ | |
| 1002 | + file("README", "hi\n"), | |
| 1003 | + exec("run.sh", "#!/bin/sh\n"), | |
| 1004 | + link("latest", "README"), | |
| 1005 | + submodule("vendor", SUBMODULE_A), | |
| 1006 | + ], | |
| 1007 | + "imported", | |
| 1008 | + ); | |
| 1009 | + let objects = MemoryObjects::new(); | |
| 1010 | + let mut map = GitMap::new(); | |
| 1011 | + import_all(&repo, &objects, &mut map); | |
| 1012 | + | |
| 1013 | + // A change made in braid: edit README, add docs/a.md, drop run.sh. | |
| 1014 | + let (readme, readme_size) = store_blob(&objects, b"hello from braid\n"); | |
| 1015 | + let (doc, doc_size) = store_blob(&objects, b"# A\n"); | |
| 1016 | + let (latest, latest_size) = store_blob(&objects, b"README"); | |
| 1017 | + let docs = store_tree( | |
| 1018 | + &objects, | |
| 1019 | + vec![Entry { | |
| 1020 | + name: b"a.md".to_vec(), | |
| 1021 | + kind: EntryKind::File { | |
| 1022 | + blob: doc, | |
| 1023 | + size: doc_size, | |
| 1024 | + }, | |
| 1025 | + }], | |
| 1026 | + ); | |
| 1027 | + let root = store_tree( | |
| 1028 | + &objects, | |
| 1029 | + vec![ | |
| 1030 | + Entry { | |
| 1031 | + name: b"README".to_vec(), | |
| 1032 | + kind: EntryKind::File { | |
| 1033 | + blob: readme, | |
| 1034 | + size: readme_size, | |
| 1035 | + }, | |
| 1036 | + }, | |
| 1037 | + Entry { | |
| 1038 | + name: b"docs".to_vec(), | |
| 1039 | + kind: EntryKind::Tree { tree: docs }, | |
| 1040 | + }, | |
| 1041 | + Entry { | |
| 1042 | + name: b"latest".to_vec(), | |
| 1043 | + kind: EntryKind::Symlink { | |
| 1044 | + blob: latest, | |
| 1045 | + size: latest_size, | |
| 1046 | + }, | |
| 1047 | + }, | |
| 1048 | + Entry { | |
| 1049 | + name: b"vendor".to_vec(), | |
| 1050 | + kind: EntryKind::Gitlink { | |
| 1051 | + commit: GitId::Sha1([0x11; 20]), | |
| 1052 | + }, | |
| 1053 | + }, | |
| 1054 | + ], | |
| 1055 | + ); | |
| 1056 | + let grace = Signature { | |
| 1057 | + name: b"Grace Hopper".to_vec(), | |
| 1058 | + email: b"grace@example.org".to_vec(), | |
| 1059 | + seconds: 1_700_000_500, | |
| 1060 | + offset_minutes: -300, | |
| 1061 | + }; | |
| 1062 | + let assembled = ChangesetParts { | |
| 1063 | + parents: vec![map.changeset(&oid(&imported)).unwrap()], | |
| 1064 | + root, | |
| 1065 | + changes: vec![ | |
| 1066 | + braid_format::Change { | |
| 1067 | + path: b"README".to_vec(), | |
| 1068 | + op: ChangeOp::File { | |
| 1069 | + blob: readme, | |
| 1070 | + size: readme_size, | |
| 1071 | + }, | |
| 1072 | + }, | |
| 1073 | + braid_format::Change { | |
| 1074 | + path: b"docs/a.md".to_vec(), | |
| 1075 | + op: ChangeOp::File { | |
| 1076 | + blob: doc, | |
| 1077 | + size: doc_size, | |
| 1078 | + }, | |
| 1079 | + }, | |
| 1080 | + braid_format::Change { | |
| 1081 | + path: b"run.sh".to_vec(), | |
| 1082 | + op: ChangeOp::Delete, | |
| 1083 | + }, | |
| 1084 | + ], | |
| 1085 | + author: grace.clone(), | |
| 1086 | + committer: grace, | |
| 1087 | + message: b"Made in braid\n".to_vec(), | |
| 1088 | + extras: vec![(b"x-braid-note".to_vec(), b"two\nlines".to_vec())], | |
| 1089 | + git_origin: None, | |
| 1090 | + } | |
| 1091 | + .assemble() | |
| 1092 | + .unwrap(); | |
| 1093 | + let changeset = objects.put(Kind::Changeset, &assembled.encoded).unwrap(); | |
| 1094 | + | |
| 1095 | + let (commit, bytes) = export_commit(&objects, &map, &changeset).unwrap(); | |
| 1096 | + assert_eq!( | |
| 1097 | + export_commit(&objects, &map, &changeset).unwrap(), | |
| 1098 | + (commit, bytes.clone()) | |
| 1099 | + ); | |
| 1100 | + let text = String::from_utf8(bytes).unwrap(); | |
| 1101 | + assert!(text.contains(&format!("\nparent {imported}\n")), "{text}"); | |
| 1102 | + assert!(text.contains("author Grace Hopper <grace@example.org> 1700000500 -0500\n")); | |
| 1103 | + assert!(text.contains("x-braid-note two\n lines\n\nMade in braid\n")); | |
| 1104 | + | |
| 1105 | + let report = write_to_repo( | |
| 1106 | + repo.path(), | |
| 1107 | + &objects, | |
| 1108 | + &map, | |
| 1109 | + &[RefUpdate { | |
| 1110 | + name: b"refs/heads/braid".to_vec(), | |
| 1111 | + target: RefTarget::Changeset(changeset), | |
| 1112 | + }], | |
| 1113 | + ) | |
| 1114 | + .unwrap(); | |
| 1115 | + assert_eq!((report.commits, report.trees, report.blobs), (1, 2, 2)); | |
| 1116 | + assert_eq!( | |
| 1117 | + repo.git(&["rev-parse", "refs/heads/braid"]), | |
| 1118 | + commit.to_hex() | |
| 1119 | + ); | |
| 1120 | + repo.git(&["fsck", "--strict", "--no-dangling"]); | |
| 1121 | + | |
| 1122 | + // Git writes the same tree for the same content. | |
| 1123 | + let same = repo.tree(&[ | |
| 1124 | + file("README", "hello from braid\n"), | |
| 1125 | + file("docs/a.md", "# A\n"), | |
| 1126 | + link("latest", "README"), | |
| 1127 | + submodule("vendor", SUBMODULE_A), | |
| 1128 | + ]); | |
| 1129 | + assert_eq!( | |
| 1130 | + repo.git(&["rev-parse", &format!("{commit}^{{tree}}")]), | |
| 1131 | + same | |
| 1132 | + ); | |
| 1133 | + | |
| 1134 | + // Importing the exported commit gives a changeset with the same root. | |
| 1135 | + let again = import_all(&repo, &objects, &mut map); | |
| 1136 | + assert_eq!(again.commits, 1); | |
| 1137 | + let reimported = changeset_of(&objects, &map, &commit); | |
| 1138 | + assert_eq!(reimported.root, root); | |
| 1139 | + assert!(reimported.git_origin.is_some()); | |
| 1140 | +} | |
| 1141 | + | |
| 1142 | +fn changeset_of(objects: &MemoryObjects, map: &GitMap, commit: &GitOid) -> Changeset { | |
| 1143 | + changeset(objects, map, &commit.to_hex()) | |
| 1144 | +} | |
| 1145 | + | |
| 1146 | +#[test] | |
| 1147 | +fn a_changeset_that_disagrees_with_its_origin_is_not_exported() { | |
| 1148 | + let mut repo = Repo::new(); | |
| 1149 | + let first = repo.snapshot("main", &[file("a", "1")], "one"); | |
| 1150 | + let second = repo.snapshot("main", &[file("a", "2")], "two"); | |
| 1151 | + let objects = MemoryObjects::new(); | |
| 1152 | + let mut map = GitMap::new(); | |
| 1153 | + import_all(&repo, &objects, &mut map); | |
| 1154 | + let genuine = changeset(&objects, &map, &second); | |
| 1155 | + let first_changeset = changeset(&objects, &map, &first); | |
| 1156 | + | |
| 1157 | + let mut wrong_root = genuine.clone(); | |
| 1158 | + wrong_root.root = first_changeset.root; | |
| 1159 | + let mut wrong_parents = genuine.clone(); | |
| 1160 | + wrong_parents.parents = Vec::new(); | |
| 1161 | + for forged in [wrong_root, wrong_parents] { | |
| 1162 | + let id = objects.put(Kind::Changeset, &forged.encode()).unwrap(); | |
| 1163 | + let err = export_commit(&objects, &map, &id).unwrap_err(); | |
| 1164 | + assert!(matches!(err, Error::OriginMismatch { .. }), "{err}"); | |
| 1165 | + } | |
| 1166 | + let genuine_id = map.changeset(&oid(&second)).unwrap(); | |
| 1167 | + assert_eq!( | |
| 1168 | + export_commit(&objects, &map, &genuine_id).unwrap().0, | |
| 1169 | + oid(&second) | |
| 1170 | + ); | |
| 1171 | +} | |
| 1172 | + | |
| 1173 | +/// The git id of the empty tree. | |
| 1174 | +const EMPTY_TREE: &str = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"; | |
| 1175 | + | |
| 1176 | +#[test] | |
| 1177 | +fn the_empty_tree_need_not_be_stored() { | |
| 1178 | + // Git treats the empty tree as always present and does not store it when | |
| 1179 | + // a commit uses it; the import and the round trip must cope. | |
| 1180 | + let mut repo = Repo::new(); | |
| 1181 | + let empty = repo.commit(EMPTY_TREE, &[], "nothing yet"); | |
| 1182 | + repo.set_ref("refs/heads/main", &empty); | |
| 1183 | + let stored = repo | |
| 1184 | + .path() | |
| 1185 | + .join("objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904"); | |
| 1186 | + assert!(!stored.exists(), "git did not store the empty tree"); | |
| 1187 | + let (objects, map) = check(&mut repo, |repo| { | |
| 1188 | + repo.snapshot("main", &[file("a", "1")], "something"); | |
| 1189 | + 1 | |
| 1190 | + }); | |
| 1191 | + assert!(changes(&objects, &map, &empty).is_empty()); | |
| 1192 | + assert!(map.raw_tree(&oid(EMPTY_TREE)).is_none()); | |
| 1193 | +} | |
| 1194 | + | |
| 1195 | +#[test] | |
| 1196 | +fn empty_directories_are_left_out() { | |
| 1197 | + let mut repo = Repo::new(); | |
| 1198 | + let f = repo.blob(b"f\n"); | |
| 1199 | + let g = repo.blob(b"g\n"); | |
| 1200 | + // An empty directory beside a file. | |
| 1201 | + let single = repo.mktree(&[ | |
| 1202 | + ("100644", "blob", &f, b"f"), | |
| 1203 | + ("40000", "tree", EMPTY_TREE, b"empty"), | |
| 1204 | + ]); | |
| 1205 | + // A chain of them: a/b/c, where c is the empty tree. | |
| 1206 | + let b = repo.mktree(&[("40000", "tree", EMPTY_TREE, b"c")]); | |
| 1207 | + let a = repo.mktree(&[("40000", "tree", &b, b"b")]); | |
| 1208 | + // A directory with a file and an empty directory. | |
| 1209 | + let sub = repo.mktree(&[ | |
| 1210 | + ("100644", "blob", &g, b"g"), | |
| 1211 | + ("40000", "tree", EMPTY_TREE, b"hollow"), | |
| 1212 | + ]); | |
| 1213 | + let root = repo.mktree(&[ | |
| 1214 | + ("100644", "blob", &f, b"f"), | |
| 1215 | + ("40000", "tree", &single, b"single"), | |
| 1216 | + ("40000", "tree", &a, b"a"), | |
| 1217 | + ("40000", "tree", &sub, b"sub"), | |
| 1218 | + ]); | |
| 1219 | + let first = repo.commit(&root, &[], "empty directories"); | |
| 1220 | + // A root holding nothing but empty directories is the empty tree. | |
| 1221 | + let hollow_root = repo.mktree(&[ | |
| 1222 | + ("40000", "tree", &a, b"a"), | |
| 1223 | + ("40000", "tree", EMPTY_TREE, b"e"), | |
| 1224 | + ]); | |
| 1225 | + let hollow = repo.commit(&hollow_root, &[&first], "only empty directories"); | |
| 1226 | + repo.set_ref("refs/heads/main", &hollow); | |
| 1227 | + | |
| 1228 | + let (objects, map) = check(&mut repo, |repo| { | |
| 1229 | + let again = repo.mktree(&[("100644", "blob", &g, b"g"), ("40000", "tree", &b, b"b")]); | |
| 1230 | + let next = repo.commit(&again, &[&hollow], "a file again"); | |
| 1231 | + repo.set_ref("refs/heads/main", &next); | |
| 1232 | + 1 | |
| 1233 | + }); | |
| 1234 | + assert_eq!( | |
| 1235 | + changes(&objects, &map, &first), | |
| 1236 | + pairs(&[("f", "file"), ("single/f", "file"), ("sub/g", "file")]) | |
| 1237 | + ); | |
| 1238 | + assert_eq!( | |
| 1239 | + changes(&objects, &map, &hollow), | |
| 1240 | + pairs(&[("f", "delete"), ("single/f", "delete"), ("sub/g", "delete")]) | |
| 1241 | + ); | |
| 1242 | + let empty = map.tree(&oid(EMPTY_TREE)).unwrap(); | |
| 1243 | + assert_eq!(changeset(&objects, &map, &hollow).root, empty); | |
| 1244 | + assert_eq!(map.tree(&oid(&b)), Some(empty)); | |
| 1245 | + assert_eq!(map.tree(&oid(&a)), Some(empty)); | |
| 1246 | + // Every git tree that lost an entry keeps its bytes; the empty tree | |
| 1247 | + // itself is canonical. | |
| 1248 | + for tree in [&single, &b, &a, &sub, &root, &hollow_root] { | |
| 1249 | + assert!(map.raw_tree(&oid(tree)).is_some(), "{tree}"); | |
| 1250 | + } | |
| 1251 | + assert!(map.raw_tree(&oid(EMPTY_TREE)).is_none()); | |
| 1252 | +} | |
| 1253 | + | |
| 1254 | +#[test] | |
| 1255 | +fn a_commit_that_only_adds_or_removes_an_empty_directory() { | |
| 1256 | + let mut repo = Repo::new(); | |
| 1257 | + let f = repo.blob(b"f\n"); | |
| 1258 | + let plain = repo.mktree(&[("100644", "blob", &f, b"f")]); | |
| 1259 | + let base = repo.commit(&plain, &[], "a file"); | |
| 1260 | + let with_empty = repo.mktree(&[ | |
| 1261 | + ("100644", "blob", &f, b"f"), | |
| 1262 | + ("40000", "tree", EMPTY_TREE, b"empty"), | |
| 1263 | + ]); | |
| 1264 | + let add = repo.commit(&with_empty, &[&base], "add an empty directory"); | |
| 1265 | + let inner = repo.mktree(&[("40000", "tree", EMPTY_TREE, b"deeper")]); | |
| 1266 | + let nested = repo.mktree(&[ | |
| 1267 | + ("100644", "blob", &f, b"f"), | |
| 1268 | + ("40000", "tree", &inner, b"empty"), | |
| 1269 | + ]); | |
| 1270 | + let deepen = repo.commit(&nested, &[&add], "nest another one inside"); | |
| 1271 | + let remove = repo.commit(&plain, &[&deepen], "remove it"); | |
| 1272 | + repo.set_ref("refs/heads/main", &remove); | |
| 1273 | + | |
| 1274 | + let (objects, map) = check(&mut repo, |repo| { | |
| 1275 | + let again = repo.commit(&with_empty, &[&remove], "add it again"); | |
| 1276 | + repo.set_ref("refs/heads/main", &again); | |
| 1277 | + 1 | |
| 1278 | + }); | |
| 1279 | + let root = changeset(&objects, &map, &base).root; | |
| 1280 | + for (commit, parent) in [(&add, &base), (&deepen, &add), (&remove, &deepen)] { | |
| 1281 | + assert!(changes(&objects, &map, commit).is_empty(), "{commit}"); | |
| 1282 | + let changeset = changeset(&objects, &map, commit); | |
| 1283 | + assert_eq!(changeset.root, root, "{commit}"); | |
| 1284 | + assert_eq!(changeset.parents, [map.changeset(&oid(parent)).unwrap()]); | |
| 1285 | + // Still bit for bit. | |
| 1286 | + let (exported, bytes) = | |
| 1287 | + export_commit(&objects, &map, &map.changeset(&oid(commit)).unwrap()).unwrap(); | |
| 1288 | + assert_eq!(exported, oid(commit)); | |
| 1289 | + assert_eq!(bytes, repo.git_bytes(&["cat-file", "commit", commit])); | |
| 1290 | + } | |
| 1291 | +} |
added crates/git/tests/this_repository.rs +62 −0
| @@ -0,0 +1,62 @@ | ||
| 1 | +// SPDX-License-Identifier: Apache-2.0 | |
| 2 | +// Copyright (c) 2026 UtopiaIA | |
| 3 | + | |
| 4 | +//! The round trip on a real history: the repository these tests live in. | |
| 5 | + | |
| 6 | +use std::path::Path; | |
| 7 | + | |
| 8 | +use braid_git::{Error, ImportOptions, RoundTripReport, verify_round_trip, verify_round_trip_with}; | |
| 9 | + | |
| 10 | +/// Runs a round trip of this repository, or says why it cannot. | |
| 11 | +fn round_trip(options: &ImportOptions) -> Option<RoundTripReport> { | |
| 12 | + let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../.."); | |
| 13 | + if !root.join(".git").exists() { | |
| 14 | + eprintln!("skipped: the sources are not in a git checkout"); | |
| 15 | + return None; | |
| 16 | + } | |
| 17 | + let tmp = tempfile::tempdir().unwrap(); | |
| 18 | + match verify_round_trip_with(&root, tmp.path(), options) { | |
| 19 | + Ok(report) => Some(report), | |
| 20 | + // A shallow checkout cannot be imported, by design. | |
| 21 | + Err(Error::Shallow) => { | |
| 22 | + eprintln!("skipped: this checkout is shallow"); | |
| 23 | + None | |
| 24 | + } | |
| 25 | + Err(err) => panic!("{err}"), | |
| 26 | + } | |
| 27 | +} | |
| 28 | + | |
| 29 | +#[test] | |
| 30 | +fn the_history_of_head_round_trips() { | |
| 31 | + // A checkout always has HEAD, even when it has no local branch. | |
| 32 | + let options = ImportOptions { | |
| 33 | + refs: vec![b"HEAD".to_vec()], | |
| 34 | + }; | |
| 35 | + if let Some(report) = round_trip(&options) { | |
| 36 | + assert!(report.commits >= 3, "{report:?}"); | |
| 37 | + assert!(report.trees > 0 && report.blobs > 0, "{report:?}"); | |
| 38 | + assert_eq!(report.refs, 1); | |
| 39 | + } | |
| 40 | +} | |
| 41 | + | |
| 42 | +#[test] | |
| 43 | +fn every_branch_and_tag_round_trips() { | |
| 44 | + if let Some(report) = round_trip(&ImportOptions::default()) { | |
| 45 | + eprintln!("{report:?}"); | |
| 46 | + } | |
| 47 | +} | |
| 48 | + | |
| 49 | +/// The round trip of any repository, on request: | |
| 50 | +/// `BRAID_ROUND_TRIP_REPO=<path> cargo test -p elffuss-braid-git --release --test this_repository -- --ignored` | |
| 51 | +#[test] | |
| 52 | +#[ignore = "needs BRAID_ROUND_TRIP_REPO"] | |
| 53 | +fn another_repository_round_trips() { | |
| 54 | + let Some(path) = std::env::var_os("BRAID_ROUND_TRIP_REPO") else { | |
| 55 | + eprintln!("set BRAID_ROUND_TRIP_REPO to the repository to check"); | |
| 56 | + return; | |
| 57 | + }; | |
| 58 | + let tmp = tempfile::tempdir().unwrap(); | |
| 59 | + let report = | |
| 60 | + verify_round_trip(Path::new(&path), tmp.path()).unwrap_or_else(|err| panic!("{err}")); | |
| 61 | + eprintln!("{report:?}"); | |
| 62 | +} |
modified docs/spec/format-v1.md +66 −0
| @@ -235,6 +235,72 @@ | ||
| 235 | 235 | - During import, every commit is exported again and its git id compared with |
| 236 | 236 | the original. Any difference stops the import. |
| 237 | 237 | |
| 238 | +These rules decide the braid ids of imported objects, so two importers that | |
| 239 | +follow them give the same ids. They are implemented in `crates/git`. | |
| 240 | + | |
| 241 | +**Trees.** An entry's kind comes from the file type bits of its octal mode: | |
| 242 | +`100000` is a file, executable when the owner may execute it (so `100664` is a | |
| 243 | +file and `100775` an executable); `120000` a symlink, whose blob is the target; | |
| 244 | +`040000` a directory; `160000` a SHA-1 gitlink. Any other type stops the | |
| 245 | +import, and so does a name section 5 refuses, checked before anything the tree | |
| 246 | +names is read. Of entries with the same name, the braid tree keeps the last | |
| 247 | +written, which is the one a git checkout uses. Braid trees never hold an empty | |
| 248 | +subdirectory (only a root can be empty), so an entry for an empty directory, or | |
| 249 | +for a directory holding only empty ones, is left out; changes, being per file, | |
| 250 | +never mention one. | |
| 251 | + | |
| 252 | +The *canonical* git tree of a braid tree lists its entries in git's order with | |
| 253 | +the modes `100644`, `100755`, `120000`, `40000` and `160000`, naming each | |
| 254 | +subdirectory by its own canonical git tree. A git tree equal to the canonical | |
| 255 | +git tree of its braid tree needs nothing more. Any other, including one that | |
| 256 | +lost duplicate names or empty directories, keeps its raw bytes in a blob, | |
| 257 | +recorded against its git id, since several git trees can share one braid tree; | |
| 258 | +a tree that names such a tree is not canonical either. The empty tree is read | |
| 259 | +as present even when git did not store it. | |
| 260 | + | |
| 261 | +**Commits.** The changeset of a commit has: as parents, the changesets of the | |
| 262 | +`parent` headers that follow the first header, `tree`, in their order; as root, | |
| 263 | +the braid tree of `tree`; the change list against the first parent; the | |
| 264 | +message, which is every byte after the first empty line; no extras; and as git | |
| 265 | +origin the blob with the commit's bytes. Author and committer are the first | |
| 266 | +`author` and `committer` headers, read as `Name <email> seconds ±HHMM`: | |
| 267 | + | |
| 268 | +- the name is everything before the first `<`, without surrounding ASCII | |
| 269 | + whitespace, and the email everything between it and the next `>`; | |
| 270 | +- after the `>`, the first word is the time in seconds and the second the | |
| 271 | + offset, `±HHMM` read as a decimal number and turned into minutes; a missing | |
| 272 | + or unreadable value is 0; | |
| 273 | +- a line without a `<` followed by a `>` is all name, with no email and time 0; | |
| 274 | + a missing header gives an empty signature. | |
| 275 | + | |
| 276 | +Annotated tags keep their raw bytes in a blob and record the object they point | |
| 277 | +to. Replacement objects and grafts are ignored, and objects are read raw: | |
| 278 | +no filters, no line-ending conversion, no LFS. Shallow and SHA-256 | |
| 279 | +repositories are refused for now. | |
| 280 | + | |
| 281 | +**Commits made in braid.** A changeset without a git origin is exported as | |
| 282 | +`tree`, one `parent` per parent, `author` and `committer` written as | |
| 283 | +`Name <email> seconds ±HHMM`, then one header per extra in order, a value with | |
| 284 | +newlines continuing on lines that start with a space, an empty line and the | |
| 285 | +message unchanged. A signature holding `<`, `>`, a newline or NUL, an offset | |
| 286 | +beyond ±99 hours, or an extra that cannot be a header has no git form and is | |
| 287 | +refused. | |
| 288 | + | |
| 289 | +**Map record.** The mapping is one derived record, versioned on its own: | |
| 290 | + | |
| 291 | +``` | |
| 292 | +"braid-git-map" u8 version = 1 | |
| 293 | +uv n, n × ([20] commit, [32] changeset) | |
| 294 | +uv n, n × ([20] tree, [32] braid tree) | |
| 295 | +uv n, n × ([20] tree, [32] blob with its raw bytes) trees that are not canonical | |
| 296 | +uv n, n × ([20] blob, [32] braid blob, uv size) | |
| 297 | +uv n, n × ([20] tag, [32] blob with its raw bytes, [20] target, u8 kind) | |
| 298 | +uv n, n × (bytes ref name, [20] tag) tag names | |
| 299 | +``` | |
| 300 | + | |
| 301 | +Each table is sorted by key without duplicates; target kinds are 1 commit, | |
| 302 | +2 tree, 3 blob and 4 tag. The reverse mappings are rebuilt on load. | |
| 303 | + | |
| 238 | 304 | ## 7. Storage (not hashed, versioned on its own) |
| 239 | 305 | |
| 240 | 306 | This is the on-disk layout of the local store as implemented in |
modified fuzz/Cargo.lock +1352 −25
| @@ -2,18 +2,51 @@ | ||
| 2 | 2 | # It is not intended for manual editing. |
| 3 | 3 | version = 4 |
| 4 | 4 | |
| 5 | +[[package]] | |
| 6 | +name = "allocator-api2" | |
| 7 | +version = "0.2.21" | |
| 8 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 9 | +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" | |
| 10 | + | |
| 5 | 11 | [[package]] |
| 6 | 12 | name = "arbitrary" |
| 7 | 13 | version = "1.5.0" |
| 8 | 14 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 9 | 15 | checksum = "3bc62ac97cc33321f50863d514c3bc38a453947a8f9e781137e47c7401020aed" |
| 10 | 16 | |
| 17 | +[[package]] | |
| 18 | +name = "arc-swap" | |
| 19 | +version = "1.9.2" | |
| 20 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 21 | +checksum = "c049c0be4daef0b145cb3555416b3b8ef5b7888a38aea1a3a155801fe7b0810b" | |
| 22 | +dependencies = [ | |
| 23 | + "rustversion", | |
| 24 | +] | |
| 25 | + | |
| 11 | 26 | [[package]] |
| 12 | 27 | name = "arrayvec" |
| 13 | 28 | version = "0.7.8" |
| 14 | 29 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 15 | 30 | checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56" |
| 16 | 31 | |
| 32 | +[[package]] | |
| 33 | +name = "autocfg" | |
| 34 | +version = "1.5.1" | |
| 35 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 36 | +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" | |
| 37 | + | |
| 38 | +[[package]] | |
| 39 | +name = "bitflags" | |
| 40 | +version = "1.3.2" | |
| 41 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 42 | +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" | |
| 43 | + | |
| 44 | +[[package]] | |
| 45 | +name = "bitflags" | |
| 46 | +version = "2.13.2" | |
| 47 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 48 | +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" | |
| 49 | + | |
| 17 | 50 | [[package]] |
| 18 | 51 | name = "blake3" |
| 19 | 52 | version = "1.8.7" |
| @@ -27,6 +60,38 @@ | ||
| 27 | 60 | "cpufeatures", |
| 28 | 61 | ] |
| 29 | 62 | |
| 63 | +[[package]] | |
| 64 | +name = "block-buffer" | |
| 65 | +version = "0.12.1" | |
| 66 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 67 | +checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa" | |
| 68 | +dependencies = [ | |
| 69 | + "hybrid-array", | |
| 70 | +] | |
| 71 | + | |
| 72 | +[[package]] | |
| 73 | +name = "bstr" | |
| 74 | +version = "1.13.1" | |
| 75 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 76 | +checksum = "6bb31b46c14244e20ee9984b11bf5c992b91fb6939fea616e3512c8baecdbe5f" | |
| 77 | +dependencies = [ | |
| 78 | + "memchr", | |
| 79 | + "regex-automata", | |
| 80 | + "serde_core", | |
| 81 | +] | |
| 82 | + | |
| 83 | +[[package]] | |
| 84 | +name = "byteorder" | |
| 85 | +version = "1.5.0" | |
| 86 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 87 | +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" | |
| 88 | + | |
| 89 | +[[package]] | |
| 90 | +name = "bytes" | |
| 91 | +version = "1.12.1" | |
| 92 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 93 | +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" | |
| 94 | + | |
| 30 | 95 | [[package]] |
| 31 | 96 | name = "cc" |
| 32 | 97 | version = "1.8.0" |
| @@ -45,12 +110,27 @@ | ||
| 45 | 110 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 46 | 111 | checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" |
| 47 | 112 | |
| 113 | +[[package]] | |
| 114 | +name = "clru" | |
| 115 | +version = "0.6.3" | |
| 116 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 117 | +checksum = "197fd99cb113a8d5d9b6376f3aa817f32c1078f2343b714fff7d2ca44fdf67d5" | |
| 118 | +dependencies = [ | |
| 119 | + "hashbrown 0.16.1", | |
| 120 | +] | |
| 121 | + | |
| 48 | 122 | [[package]] |
| 49 | 123 | name = "constant_time_eq" |
| 50 | 124 | version = "0.4.2" |
| 51 | 125 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 52 | 126 | checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b" |
| 53 | 127 | |
| 128 | +[[package]] | |
| 129 | +name = "core_detect" | |
| 130 | +version = "1.0.0" | |
| 131 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 132 | +checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48" | |
| 133 | + | |
| 54 | 134 | [[package]] |
| 55 | 135 | name = "cpufeatures" |
| 56 | 136 | version = "0.3.1" |
| @@ -60,6 +140,95 @@ | ||
| 60 | 140 | "libc", |
| 61 | 141 | ] |
| 62 | 142 | |
| 143 | +[[package]] | |
| 144 | +name = "crc32fast" | |
| 145 | +version = "1.5.2" | |
| 146 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 147 | +checksum = "01a7799fd6b852db0e61728dde9a204c423b44d689dbd432522543614b490e78" | |
| 148 | +dependencies = [ | |
| 149 | + "cfg-if", | |
| 150 | +] | |
| 151 | + | |
| 152 | +[[package]] | |
| 153 | +name = "crossbeam-channel" | |
| 154 | +version = "0.5.17" | |
| 155 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 156 | +checksum = "98b0cc327b5bc766e7fda9c9260cc0fa81b43a8e240440422dff70788e3f9ef1" | |
| 157 | +dependencies = [ | |
| 158 | + "crossbeam-utils", | |
| 159 | +] | |
| 160 | + | |
| 161 | +[[package]] | |
| 162 | +name = "crossbeam-utils" | |
| 163 | +version = "0.8.23" | |
| 164 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 165 | +checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6" | |
| 166 | + | |
| 167 | +[[package]] | |
| 168 | +name = "crypto-common" | |
| 169 | +version = "0.2.2" | |
| 170 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 171 | +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" | |
| 172 | +dependencies = [ | |
| 173 | + "hybrid-array", | |
| 174 | +] | |
| 175 | + | |
| 176 | +[[package]] | |
| 177 | +name = "defmt" | |
| 178 | +version = "0.3.101" | |
| 179 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 180 | +checksum = "4deef977660e373c458df605a913d4ab121db0ccd18d1ad6976dff7d37cddb53" | |
| 181 | +dependencies = [ | |
| 182 | + "defmt 1.2.0", | |
| 183 | +] | |
| 184 | + | |
| 185 | +[[package]] | |
| 186 | +name = "defmt" | |
| 187 | +version = "1.2.0" | |
| 188 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 189 | +checksum = "e4a0795ac740cb54d7b3775c9c17345f6aaecf884c01733b39d6017738e0e3e1" | |
| 190 | +dependencies = [ | |
| 191 | + "bitflags 1.3.2", | |
| 192 | + "defmt-macros", | |
| 193 | +] | |
| 194 | + | |
| 195 | +[[package]] | |
| 196 | +name = "defmt-macros" | |
| 197 | +version = "1.2.0" | |
| 198 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 199 | +checksum = "840bb056bd99c495c9188198a258ab787c79f306d864db3e6e8451442d6d8366" | |
| 200 | +dependencies = [ | |
| 201 | + "defmt-parser", | |
| 202 | + "proc-macro2", | |
| 203 | + "quote", | |
| 204 | + "syn 3.0.9", | |
| 205 | +] | |
| 206 | + | |
| 207 | +[[package]] | |
| 208 | +name = "defmt-parser" | |
| 209 | +version = "1.1.0" | |
| 210 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 211 | +checksum = "71958f69fb2de856c5dd51ac9377e986ca1aa5919f931bf5395a807277f889a0" | |
| 212 | +dependencies = [ | |
| 213 | + "thiserror", | |
| 214 | +] | |
| 215 | + | |
| 216 | +[[package]] | |
| 217 | +name = "digest" | |
| 218 | +version = "0.11.3" | |
| 219 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 220 | +checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" | |
| 221 | +dependencies = [ | |
| 222 | + "block-buffer", | |
| 223 | + "crypto-common", | |
| 224 | +] | |
| 225 | + | |
| 226 | +[[package]] | |
| 227 | +name = "dunce" | |
| 228 | +version = "1.0.5" | |
| 229 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 230 | +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" | |
| 231 | + | |
| 63 | 232 | [[package]] |
| 64 | 233 | name = "elffuss-braid-format" |
| 65 | 234 | version = "0.0.1" |
| @@ -73,15 +242,78 @@ | ||
| 73 | 242 | version = "0.0.0" |
| 74 | 243 | dependencies = [ |
| 75 | 244 | "elffuss-braid-format", |
| 245 | + "elffuss-braid-git", | |
| 76 | 246 | "libfuzzer-sys", |
| 77 | 247 | ] |
| 78 | 248 | |
| 249 | +[[package]] | |
| 250 | +name = "elffuss-braid-git" | |
| 251 | +version = "0.0.1" | |
| 252 | +dependencies = [ | |
| 253 | + "elffuss-braid-format", | |
| 254 | + "gix", | |
| 255 | +] | |
| 256 | + | |
| 257 | +[[package]] | |
| 258 | +name = "encoding_rs" | |
| 259 | +version = "0.8.42" | |
| 260 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 261 | +checksum = "8e985e0451871ad22fb8d2b6b076e2028a502a0d3950998c2c5c0a4f9b5d9679" | |
| 262 | +dependencies = [ | |
| 263 | + "cfg-if", | |
| 264 | + "core_detect", | |
| 265 | + "multiversion_no_op", | |
| 266 | + "rustversion", | |
| 267 | + "scopeguard", | |
| 268 | + "simdutf8", | |
| 269 | +] | |
| 270 | + | |
| 271 | +[[package]] | |
| 272 | +name = "equivalent" | |
| 273 | +version = "1.0.3" | |
| 274 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 275 | +checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" | |
| 276 | + | |
| 277 | +[[package]] | |
| 278 | +name = "errno" | |
| 279 | +version = "0.3.14" | |
| 280 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 281 | +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" | |
| 282 | +dependencies = [ | |
| 283 | + "libc", | |
| 284 | + "windows-sys", | |
| 285 | +] | |
| 286 | + | |
| 287 | +[[package]] | |
| 288 | +name = "faster-hex" | |
| 289 | +version = "0.10.1" | |
| 290 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 291 | +checksum = "04839bdf9d8c10f66806fad16b852fc72aab80873aebc3cb69d85b4fa41543ed" | |
| 292 | +dependencies = [ | |
| 293 | + "autocfg", | |
| 294 | + "defmt 0.3.101", | |
| 295 | + "heapless", | |
| 296 | + "serde", | |
| 297 | +] | |
| 298 | + | |
| 299 | +[[package]] | |
| 300 | +name = "fastrand" | |
| 301 | +version = "2.5.0" | |
| 302 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 303 | +checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" | |
| 304 | + | |
| 79 | 305 | [[package]] |
| 80 | 306 | name = "find-msvc-tools" |
| 81 | 307 | version = "0.1.14" |
| 82 | 308 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 83 | 309 | checksum = "aedcfb3409746eddb02b9e19ebda1c3394f759a152e48ee875a0844d1b955484" |
| 84 | 310 | |
| 311 | +[[package]] | |
| 312 | +name = "foldhash" | |
| 313 | +version = "0.2.0" | |
| 314 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 315 | +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" | |
| 316 | + | |
| 85 | 317 | [[package]] |
| 86 | 318 | name = "getrandom" |
| 87 | 319 | version = "0.4.3" |
| @@ -94,54 +326,1149 @@ | ||
| 94 | 326 | ] |
| 95 | 327 | |
| 96 | 328 | [[package]] |
| 97 | -name = "jobserver" | |
| 98 | -version = "0.1.35" | |
| 329 | +name = "gix" | |
| 330 | +version = "0.89.0" | |
| 99 | 331 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 100 | -checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3" | |
| 332 | +checksum = "2156d2e07fc3afa7632a82bf3cb0db91f995645a2852f642105c9ac9b52e1cb2" | |
| 101 | 333 | dependencies = [ |
| 102 | - "getrandom", | |
| 334 | + "gix-actor", | |
| 335 | + "gix-commitgraph", | |
| 336 | + "gix-config", | |
| 337 | + "gix-date", | |
| 338 | + "gix-diff", | |
| 339 | + "gix-discover", | |
| 340 | + "gix-error", | |
| 341 | + "gix-fs", | |
| 342 | + "gix-glob", | |
| 343 | + "gix-hash", | |
| 344 | + "gix-hashtable", | |
| 345 | + "gix-lock", | |
| 346 | + "gix-note", | |
| 347 | + "gix-object", | |
| 348 | + "gix-odb", | |
| 349 | + "gix-pack", | |
| 350 | + "gix-parallel", | |
| 351 | + "gix-path", | |
| 352 | + "gix-protocol", | |
| 353 | + "gix-quote", | |
| 354 | + "gix-ref", | |
| 355 | + "gix-refspec", | |
| 356 | + "gix-revision", | |
| 357 | + "gix-revwalk", | |
| 358 | + "gix-sec", | |
| 359 | + "gix-shallow", | |
| 360 | + "gix-tempfile", | |
| 361 | + "gix-trace", | |
| 362 | + "gix-traverse", | |
| 363 | + "gix-url", | |
| 364 | + "gix-utils", | |
| 365 | + "gix-validate", | |
| 366 | + "gix-worktree-stream", | |
| 367 | + "gix-zlib", | |
| 368 | + "nonempty", | |
| 369 | + "smallvec", | |
| 370 | +] | |
| 371 | + | |
| 372 | +[[package]] | |
| 373 | +name = "gix-actor" | |
| 374 | +version = "0.44.0" | |
| 375 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 376 | +checksum = "2127da41042965ed205568a52443465806944f71c8acd73f48ec94b8cd8e798e" | |
| 377 | +dependencies = [ | |
| 378 | + "bstr", | |
| 379 | + "gix-date", | |
| 380 | + "gix-error", | |
| 381 | +] | |
| 382 | + | |
| 383 | +[[package]] | |
| 384 | +name = "gix-attributes" | |
| 385 | +version = "0.37.0" | |
| 386 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 387 | +checksum = "0feca0b8919aba9f123b75de54062dd61eb37d2a2130f34be520da6ed8b8ef72" | |
| 388 | +dependencies = [ | |
| 389 | + "bstr", | |
| 390 | + "gix-error", | |
| 391 | + "gix-glob", | |
| 392 | + "gix-parallel", | |
| 393 | + "gix-path", | |
| 394 | + "gix-quote", | |
| 395 | + "gix-trace", | |
| 396 | + "smallvec", | |
| 397 | + "unicode-bom", | |
| 398 | +] | |
| 399 | + | |
| 400 | +[[package]] | |
| 401 | +name = "gix-chunk" | |
| 402 | +version = "0.10.0" | |
| 403 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 404 | +checksum = "626335faf30ed235744642c2309aa370683b8bb2757f1c22a807e274dff60074" | |
| 405 | +dependencies = [ | |
| 406 | + "gix-error", | |
| 407 | +] | |
| 408 | + | |
| 409 | +[[package]] | |
| 410 | +name = "gix-command" | |
| 411 | +version = "0.12.0" | |
| 412 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 413 | +checksum = "ac560c05e19455016a4a94b33a77debe59aaed8783da32a73d31c9975947152e" | |
| 414 | +dependencies = [ | |
| 415 | + "bstr", | |
| 416 | + "gix-error", | |
| 417 | + "gix-path", | |
| 418 | + "gix-quote", | |
| 419 | + "gix-trace", | |
| 420 | +] | |
| 421 | + | |
| 422 | +[[package]] | |
| 423 | +name = "gix-commitgraph" | |
| 424 | +version = "0.41.0" | |
| 425 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 426 | +checksum = "dfede9936d4b789867c09722576aea4ceb0e3aacf962eef035ebab0686b41a80" | |
| 427 | +dependencies = [ | |
| 428 | + "bstr", | |
| 429 | + "gix-chunk", | |
| 430 | + "gix-error", | |
| 431 | + "gix-hash", | |
| 432 | + "memmap2", | |
| 433 | + "nonempty", | |
| 434 | +] | |
| 435 | + | |
| 436 | +[[package]] | |
| 437 | +name = "gix-config" | |
| 438 | +version = "0.62.0" | |
| 439 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 440 | +checksum = "65a9c000fa9a9154f22ffc8f8d74426e9300d759c2029e8701e2ba39d5d464ea" | |
| 441 | +dependencies = [ | |
| 442 | + "bstr", | |
| 443 | + "gix-config-value", | |
| 444 | + "gix-error", | |
| 445 | + "gix-glob", | |
| 446 | + "gix-parallel", | |
| 447 | + "gix-path", | |
| 448 | + "gix-ref", | |
| 449 | + "gix-sec", | |
| 450 | + "gix-trace", | |
| 451 | + "gix-utils", | |
| 452 | + "smallvec", | |
| 453 | + "unicode-bom", | |
| 454 | +] | |
| 455 | + | |
| 456 | +[[package]] | |
| 457 | +name = "gix-config-value" | |
| 458 | +version = "0.21.0" | |
| 459 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 460 | +checksum = "ab206c2fccfd35e0de7fb1b424997cfd42912062c66dae024e08a06e22d46674" | |
| 461 | +dependencies = [ | |
| 462 | + "bitflags 2.13.2", | |
| 463 | + "bstr", | |
| 464 | + "gix-error", | |
| 465 | + "gix-path", | |
| 466 | + "gix-utils", | |
| 103 | 467 | "libc", |
| 104 | 468 | ] |
| 105 | 469 | |
| 106 | 470 | [[package]] |
| 107 | -name = "libc" | |
| 108 | -version = "0.2.190" | |
| 471 | +name = "gix-date" | |
| 472 | +version = "0.18.0" | |
| 109 | 473 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 110 | -checksum = "ce5d3ddc6d3fa000eb1536d85e147bfe31aacaba692ed6a876f95cb7c855be78" | |
| 474 | +checksum = "0f7eeeecc599082f32b5ea6a8c4c734e38be9730e2c09e3fe2851bb4692393e9" | |
| 475 | +dependencies = [ | |
| 476 | + "bstr", | |
| 477 | + "gix-error", | |
| 478 | + "itoa", | |
| 479 | + "jiff", | |
| 480 | +] | |
| 111 | 481 | |
| 112 | 482 | [[package]] |
| 113 | -name = "libfuzzer-sys" | |
| 114 | -version = "0.4.13" | |
| 483 | +name = "gix-diff" | |
| 484 | +version = "0.69.0" | |
| 115 | 485 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 116 | -checksum = "a9fd2f41a1cba099f79a0b6b6c35656cf7c03351a7bae8ff0f28f25270f929d2" | |
| 486 | +checksum = "aa640963fdcbc6b4718e48593c3917f5ae764b59fb5a96313cb5a757246d041d" | |
| 117 | 487 | dependencies = [ |
| 118 | - "arbitrary", | |
| 119 | - "cc", | |
| 488 | + "bstr", | |
| 489 | + "gix-error", | |
| 490 | + "gix-hash", | |
| 491 | + "gix-object", | |
| 120 | 492 | ] |
| 121 | 493 | |
| 122 | 494 | [[package]] |
| 123 | -name = "r-efi" | |
| 124 | -version = "6.0.0" | |
| 495 | +name = "gix-discover" | |
| 496 | +version = "0.57.0" | |
| 125 | 497 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 126 | -checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" | |
| 498 | +checksum = "a7d0f8fd2c7e4b458eb3081362d49b54bd0131d23ecd49be802085a11f0d3cee" | |
| 499 | +dependencies = [ | |
| 500 | + "bstr", | |
| 501 | + "dunce", | |
| 502 | + "gix-error", | |
| 503 | + "gix-fs", | |
| 504 | + "gix-path", | |
| 505 | + "gix-ref", | |
| 506 | + "gix-sec", | |
| 507 | +] | |
| 127 | 508 | |
| 128 | 509 | [[package]] |
| 129 | -name = "shlex" | |
| 130 | -version = "2.0.1" | |
| 510 | +name = "gix-error" | |
| 511 | +version = "0.5.1" | |
| 131 | 512 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 132 | -checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" | |
| 513 | +checksum = "bb3308a948a01b94ef13d9ee7a9b28c1303d8d9a9dc33b401ff40c2184d9e04a" | |
| 514 | +dependencies = [ | |
| 515 | + "bstr", | |
| 516 | +] | |
| 133 | 517 | |
| 134 | 518 | [[package]] |
| 135 | -name = "tinyvec" | |
| 136 | -version = "1.13.3" | |
| 519 | +name = "gix-filter" | |
| 520 | +version = "0.36.0" | |
| 137 | 521 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 138 | -checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee" | |
| 522 | +checksum = "9d8d932ee4043f7d77d15ee58d2be2bc95accea5dd1d77fd145de1b7c504551b" | |
| 523 | +dependencies = [ | |
| 524 | + "bstr", | |
| 525 | + "encoding_rs", | |
| 526 | + "gix-attributes", | |
| 527 | + "gix-command", | |
| 528 | + "gix-error", | |
| 529 | + "gix-hash", | |
| 530 | + "gix-object", | |
| 531 | + "gix-packetline", | |
| 532 | + "gix-path", | |
| 533 | + "gix-quote", | |
| 534 | + "gix-trace", | |
| 535 | + "gix-utils", | |
| 536 | + "smallvec", | |
| 537 | +] | |
| 139 | 538 | |
| 140 | 539 | [[package]] |
| 141 | -name = "unicode-normalization" | |
| 142 | -version = "0.1.25" | |
| 540 | +name = "gix-fs" | |
| 541 | +version = "0.24.0" | |
| 143 | 542 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 144 | -checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8" | |
| 543 | +checksum = "44a05d043e670c055cd8b53d078562dc0bc1e322bff6b0376b407d37cf72dcc5" | |
| 145 | 544 | dependencies = [ |
| 146 | - "tinyvec", | |
| 545 | + "bstr", | |
| 546 | + "gix-error", | |
| 547 | + "gix-parallel", | |
| 548 | + "gix-path", | |
| 549 | + "gix-utils", | |
| 550 | + "libc", | |
| 551 | + "walkdir", | |
| 552 | +] | |
| 553 | + | |
| 554 | +[[package]] | |
| 555 | +name = "gix-glob" | |
| 556 | +version = "0.29.0" | |
| 557 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 558 | +checksum = "7b0d03ab50fa841621031960679caf7fe94940968d9a0736d12a580f2c03e525" | |
| 559 | +dependencies = [ | |
| 560 | + "bitflags 2.13.2", | |
| 561 | + "bstr", | |
| 562 | + "gix-fs", | |
| 563 | + "gix-path", | |
| 564 | + "gix-trace", | |
| 565 | + "gix-utils", | |
| 566 | +] | |
| 567 | + | |
| 568 | +[[package]] | |
| 569 | +name = "gix-hash" | |
| 570 | +version = "0.28.0" | |
| 571 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 572 | +checksum = "40ca156064e378d8c657084365846cedb8dc498c6ea4500965a64d74f12af2be" | |
| 573 | +dependencies = [ | |
| 574 | + "faster-hex", | |
| 575 | + "gix-error", | |
| 576 | + "gix-utils", | |
| 577 | + "sha1dc", | |
| 578 | + "sha2", | |
| 579 | +] | |
| 580 | + | |
| 581 | +[[package]] | |
| 582 | +name = "gix-hashtable" | |
| 583 | +version = "0.18.0" | |
| 584 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 585 | +checksum = "916cb6b2ec42ffaca624e7867bb382a4673015cb4ffcd7330b48085d02e4c615" | |
| 586 | +dependencies = [ | |
| 587 | + "gix-hash", | |
| 588 | + "hashbrown 0.17.1", | |
| 589 | + "parking_lot", | |
| 590 | +] | |
| 591 | + | |
| 592 | +[[package]] | |
| 593 | +name = "gix-lock" | |
| 594 | +version = "26.0.0" | |
| 595 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 596 | +checksum = "4b2f7f5bd6b9fcd0b0dc58b0e6a708f3a47c3313876571dfe800c926c069aa5c" | |
| 597 | +dependencies = [ | |
| 598 | + "gix-error", | |
| 599 | + "gix-fs", | |
| 600 | + "gix-tempfile", | |
| 601 | + "gix-utils", | |
| 602 | +] | |
| 603 | + | |
| 604 | +[[package]] | |
| 605 | +name = "gix-macros" | |
| 606 | +version = "0.2.0" | |
| 607 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 608 | +checksum = "f11f5429ca73cc3758c9f53af56a9fba100a8701c5b4bc30e29b8b0b15288991" | |
| 609 | +dependencies = [ | |
| 610 | + "proc-macro2", | |
| 611 | + "quote", | |
| 612 | + "syn 2.0.119", | |
| 613 | +] | |
| 614 | + | |
| 615 | +[[package]] | |
| 616 | +name = "gix-note" | |
| 617 | +version = "0.3.0" | |
| 618 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 619 | +checksum = "bd364f8bdceaed9e7f3ae40f324b16e39f20e9c7e6a6a058f7c6ec66c3e6205c" | |
| 620 | +dependencies = [ | |
| 621 | + "gix-error", | |
| 622 | + "gix-hash", | |
| 623 | + "gix-object", | |
| 624 | +] | |
| 625 | + | |
| 626 | +[[package]] | |
| 627 | +name = "gix-object" | |
| 628 | +version = "0.66.0" | |
| 629 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 630 | +checksum = "f0e38f50177e211642af154f9a7f710b7a3a637e635f9b6adb9d51973b0f9209" | |
| 631 | +dependencies = [ | |
| 632 | + "bstr", | |
| 633 | + "gix-actor", | |
| 634 | + "gix-date", | |
| 635 | + "gix-error", | |
| 636 | + "gix-hash", | |
| 637 | + "gix-hashtable", | |
| 638 | + "gix-utils", | |
| 639 | + "gix-validate", | |
| 640 | + "itoa", | |
| 641 | + "smallvec", | |
| 642 | +] | |
| 643 | + | |
| 644 | +[[package]] | |
| 645 | +name = "gix-odb" | |
| 646 | +version = "0.86.0" | |
| 647 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 648 | +checksum = "ca444f33f2140876ed6b5313c2b550b4af699008193c96f3bff5023afa9ef4ea" | |
| 649 | +dependencies = [ | |
| 650 | + "arc-swap", | |
| 651 | + "crc32fast", | |
| 652 | + "gix-error", | |
| 653 | + "gix-fs", | |
| 654 | + "gix-hash", | |
| 655 | + "gix-hashtable", | |
| 656 | + "gix-object", | |
| 657 | + "gix-pack", | |
| 658 | + "gix-parallel", | |
| 659 | + "gix-path", | |
| 660 | + "gix-quote", | |
| 661 | + "gix-trace", | |
| 662 | + "gix-utils", | |
| 663 | + "gix-zlib", | |
| 664 | + "memmap2", | |
| 665 | + "parking_lot", | |
| 666 | + "tempfile", | |
| 667 | +] | |
| 668 | + | |
| 669 | +[[package]] | |
| 670 | +name = "gix-pack" | |
| 671 | +version = "0.76.0" | |
| 672 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 673 | +checksum = "bc5024cc503cd29461a705ae90b9eae772fa8f0e6fafc1c48513877dc374de05" | |
| 674 | +dependencies = [ | |
| 675 | + "clru", | |
| 676 | + "crc32fast", | |
| 677 | + "gix-chunk", | |
| 678 | + "gix-error", | |
| 679 | + "gix-hash", | |
| 680 | + "gix-hashtable", | |
| 681 | + "gix-object", | |
| 682 | + "gix-parallel", | |
| 683 | + "gix-path", | |
| 684 | + "gix-trace", | |
| 685 | + "gix-utils", | |
| 686 | + "gix-zlib", | |
| 687 | + "memmap2", | |
| 688 | + "smallvec", | |
| 689 | +] | |
| 690 | + | |
| 691 | +[[package]] | |
| 692 | +name = "gix-packetline" | |
| 693 | +version = "0.24.0" | |
| 694 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 695 | +checksum = "830e51b227f6a925fe9308858ac91170dd00fa2880f5480fc81e8a4594fe2c35" | |
| 696 | +dependencies = [ | |
| 697 | + "bstr", | |
| 698 | + "faster-hex", | |
| 699 | + "gix-error", | |
| 700 | + "gix-trace", | |
| 701 | +] | |
| 702 | + | |
| 703 | +[[package]] | |
| 704 | +name = "gix-parallel" | |
| 705 | +version = "0.50.0" | |
| 706 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 707 | +checksum = "e994cf1eec247ba4be7f9e7c0d58cc73f83eecb5fcb9feb595df5ba3d2078546" | |
| 708 | +dependencies = [ | |
| 709 | + "crossbeam-channel", | |
| 710 | + "gix-trace", | |
| 711 | + "once_cell", | |
| 712 | + "parking_lot", | |
| 713 | +] | |
| 714 | + | |
| 715 | +[[package]] | |
| 716 | +name = "gix-path" | |
| 717 | +version = "0.14.0" | |
| 718 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 719 | +checksum = "a6d563d4d0c975ed0df4e853f9ec962a2ba46633b1d324e1a5582541fcae0c6b" | |
| 720 | +dependencies = [ | |
| 721 | + "bstr", | |
| 722 | + "gix-error", | |
| 723 | + "gix-trace", | |
| 724 | + "gix-validate", | |
| 725 | +] | |
| 726 | + | |
| 727 | +[[package]] | |
| 728 | +name = "gix-protocol" | |
| 729 | +version = "0.67.0" | |
| 730 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 731 | +checksum = "832b5dc46a3c0a6f6fa8f8e571c11074add4b545c6789799ae6d6c36ae1a294e" | |
| 732 | +dependencies = [ | |
| 733 | + "bstr", | |
| 734 | + "gix-date", | |
| 735 | + "gix-error", | |
| 736 | + "gix-hash", | |
| 737 | + "gix-macros", | |
| 738 | + "gix-ref", | |
| 739 | + "gix-shallow", | |
| 740 | + "gix-transport", | |
| 741 | + "gix-utils", | |
| 742 | + "nonempty", | |
| 147 | 743 | ] |
| 744 | + | |
| 745 | +[[package]] | |
| 746 | +name = "gix-quote" | |
| 747 | +version = "0.10.0" | |
| 748 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 749 | +checksum = "c7f92bc1b13c09e88388578e8aa1e987ec35f28fca158c13b1baa7ab1a85b124" | |
| 750 | +dependencies = [ | |
| 751 | + "bstr", | |
| 752 | + "gix-error", | |
| 753 | + "gix-utils", | |
| 754 | +] | |
| 755 | + | |
| 756 | +[[package]] | |
| 757 | +name = "gix-ref" | |
| 758 | +version = "0.69.0" | |
| 759 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 760 | +checksum = "073bc0928e1f747823b1eaed94918119dacef4c616532bc3d17e5b7457863471" | |
| 761 | +dependencies = [ | |
| 762 | + "gix-actor", | |
| 763 | + "gix-error", | |
| 764 | + "gix-fs", | |
| 765 | + "gix-hash", | |
| 766 | + "gix-lock", | |
| 767 | + "gix-object", | |
| 768 | + "gix-parallel", | |
| 769 | + "gix-path", | |
| 770 | + "gix-tempfile", | |
| 771 | + "gix-utils", | |
| 772 | + "gix-validate", | |
| 773 | + "memmap2", | |
| 774 | +] | |
| 775 | + | |
| 776 | +[[package]] | |
| 777 | +name = "gix-refspec" | |
| 778 | +version = "0.47.0" | |
| 779 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 780 | +checksum = "ccc7010dae0df2900aa77cc67f8aca042cd80e35938ccc179010d863b1d42a0c" | |
| 781 | +dependencies = [ | |
| 782 | + "bstr", | |
| 783 | + "gix-error", | |
| 784 | + "gix-hash", | |
| 785 | + "gix-validate", | |
| 786 | + "smallvec", | |
| 787 | +] | |
| 788 | + | |
| 789 | +[[package]] | |
| 790 | +name = "gix-revision" | |
| 791 | +version = "0.51.0" | |
| 792 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 793 | +checksum = "63210c1943b67fa700806c3c3486fc16a92b3ea871f5cf092340b8eec10a0ca1" | |
| 794 | +dependencies = [ | |
| 795 | + "bstr", | |
| 796 | + "gix-commitgraph", | |
| 797 | + "gix-date", | |
| 798 | + "gix-error", | |
| 799 | + "gix-hash", | |
| 800 | + "gix-object", | |
| 801 | + "gix-revwalk", | |
| 802 | + "nonempty", | |
| 803 | +] | |
| 804 | + | |
| 805 | +[[package]] | |
| 806 | +name = "gix-revwalk" | |
| 807 | +version = "0.37.0" | |
| 808 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 809 | +checksum = "800479fbbf1e7f94f663e07943a91add5499343e7aac611a81e6a0460fd44af6" | |
| 810 | +dependencies = [ | |
| 811 | + "gix-commitgraph", | |
| 812 | + "gix-date", | |
| 813 | + "gix-error", | |
| 814 | + "gix-hash", | |
| 815 | + "gix-hashtable", | |
| 816 | + "gix-object", | |
| 817 | + "smallvec", | |
| 818 | +] | |
| 819 | + | |
| 820 | +[[package]] | |
| 821 | +name = "gix-sec" | |
| 822 | +version = "0.16.0" | |
| 823 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 824 | +checksum = "5640f642a1b471616d48230b1def7ca743cb30903441ff84800cafbab3c0fddf" | |
| 825 | +dependencies = [ | |
| 826 | + "bitflags 2.13.2", | |
| 827 | + "gix-path", | |
| 828 | + "libc", | |
| 829 | + "windows-sys", | |
| 830 | +] | |
| 831 | + | |
| 832 | +[[package]] | |
| 833 | +name = "gix-shallow" | |
| 834 | +version = "0.15.0" | |
| 835 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 836 | +checksum = "94bc0720a3d6b10f18e3ac382a7780bcfc4c6bee94a8b5857b8e4ec94c50d754" | |
| 837 | +dependencies = [ | |
| 838 | + "bstr", | |
| 839 | + "gix-error", | |
| 840 | + "gix-hash", | |
| 841 | + "gix-lock", | |
| 842 | + "nonempty", | |
| 843 | +] | |
| 844 | + | |
| 845 | +[[package]] | |
| 846 | +name = "gix-tempfile" | |
| 847 | +version = "26.0.0" | |
| 848 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 849 | +checksum = "e9275c8ae0646d840ae0156d3f90d39b7beea6e31a398afb9ee72feb293a269c" | |
| 850 | +dependencies = [ | |
| 851 | + "gix-fs", | |
| 852 | + "libc", | |
| 853 | + "parking_lot", | |
| 854 | + "tempfile", | |
| 855 | + "windows-sys", | |
| 856 | +] | |
| 857 | + | |
| 858 | +[[package]] | |
| 859 | +name = "gix-trace" | |
| 860 | +version = "0.3.0" | |
| 861 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 862 | +checksum = "133f2de116104d637541831b6acb157898556d5eeec363ab2eb1c583adc6bb56" | |
| 863 | + | |
| 864 | +[[package]] | |
| 865 | +name = "gix-transport" | |
| 866 | +version = "0.61.0" | |
| 867 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 868 | +checksum = "2e43d6b0097ea9f2f266d5d6c43b8f615ed3da7c686ec8771cd17c1cb33cb0de" | |
| 869 | +dependencies = [ | |
| 870 | + "bstr", | |
| 871 | + "gix-command", | |
| 872 | + "gix-error", | |
| 873 | + "gix-packetline", | |
| 874 | + "gix-path", | |
| 875 | + "gix-quote", | |
| 876 | + "gix-sec", | |
| 877 | + "gix-trace", | |
| 878 | + "gix-url", | |
| 879 | + "gix-utils", | |
| 880 | +] | |
| 881 | + | |
| 882 | +[[package]] | |
| 883 | +name = "gix-traverse" | |
| 884 | +version = "0.63.0" | |
| 885 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 886 | +checksum = "a668a6e7f7688e5a43eaf161f1471ffc559de1a5fd8471e861c64d59d1699e1e" | |
| 887 | +dependencies = [ | |
| 888 | + "bitflags 2.13.2", | |
| 889 | + "gix-commitgraph", | |
| 890 | + "gix-date", | |
| 891 | + "gix-error", | |
| 892 | + "gix-hash", | |
| 893 | + "gix-hashtable", | |
| 894 | + "gix-object", | |
| 895 | + "gix-revwalk", | |
| 896 | + "smallvec", | |
| 897 | +] | |
| 898 | + | |
| 899 | +[[package]] | |
| 900 | +name = "gix-url" | |
| 901 | +version = "0.40.0" | |
| 902 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 903 | +checksum = "04317dea7a5dd5253bbcab060c230f3de6a57d17cc9600c6cd7030bf4795b414" | |
| 904 | +dependencies = [ | |
| 905 | + "bstr", | |
| 906 | + "gix-error", | |
| 907 | + "gix-path", | |
| 908 | + "gix-utils", | |
| 909 | + "percent-encoding", | |
| 910 | +] | |
| 911 | + | |
| 912 | +[[package]] | |
| 913 | +name = "gix-utils" | |
| 914 | +version = "0.5.1" | |
| 915 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 916 | +checksum = "f8e770b8c34311044d1addc7b18957db0ac27183707e1140dc90e6f674a6354e" | |
| 917 | +dependencies = [ | |
| 918 | + "bstr", | |
| 919 | + "bytes", | |
| 920 | + "fastrand", | |
| 921 | + "getrandom", | |
| 922 | + "gix-error", | |
| 923 | + "prodash", | |
| 924 | + "unicode-normalization", | |
| 925 | +] | |
| 926 | + | |
| 927 | +[[package]] | |
| 928 | +name = "gix-validate" | |
| 929 | +version = "0.13.0" | |
| 930 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 931 | +checksum = "cbcd59cc52742468bc5c8a0e7123390d154f45e6cbd37461b0dcecdc681f2179" | |
| 932 | +dependencies = [ | |
| 933 | + "bstr", | |
| 934 | + "gix-error", | |
| 935 | +] | |
| 936 | + | |
| 937 | +[[package]] | |
| 938 | +name = "gix-worktree-stream" | |
| 939 | +version = "0.38.0" | |
| 940 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 941 | +checksum = "28d2789610e8179d4e0e8e51170a52a66483c103a8ad3c7db4d075b571856cb6" | |
| 942 | +dependencies = [ | |
| 943 | + "gix-attributes", | |
| 944 | + "gix-error", | |
| 945 | + "gix-filter", | |
| 946 | + "gix-fs", | |
| 947 | + "gix-hash", | |
| 948 | + "gix-object", | |
| 949 | + "gix-parallel", | |
| 950 | + "gix-path", | |
| 951 | + "gix-trace", | |
| 952 | + "gix-traverse", | |
| 953 | + "gix-utils", | |
| 954 | + "parking_lot", | |
| 955 | +] | |
| 956 | + | |
| 957 | +[[package]] | |
| 958 | +name = "gix-zlib" | |
| 959 | +version = "0.3.0" | |
| 960 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 961 | +checksum = "8c2edb206bf06f3c801f4f6789c696396171558ab9b4c7f1fe3ba4d39b00b0f4" | |
| 962 | +dependencies = [ | |
| 963 | + "gix-error", | |
| 964 | + "zlib-rs", | |
| 965 | +] | |
| 966 | + | |
| 967 | +[[package]] | |
| 968 | +name = "hash32" | |
| 969 | +version = "0.3.1" | |
| 970 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 971 | +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" | |
| 972 | +dependencies = [ | |
| 973 | + "byteorder", | |
| 974 | +] | |
| 975 | + | |
| 976 | +[[package]] | |
| 977 | +name = "hashbrown" | |
| 978 | +version = "0.16.1" | |
| 979 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 980 | +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" | |
| 981 | +dependencies = [ | |
| 982 | + "allocator-api2", | |
| 983 | + "equivalent", | |
| 984 | + "foldhash", | |
| 985 | +] | |
| 986 | + | |
| 987 | +[[package]] | |
| 988 | +name = "hashbrown" | |
| 989 | +version = "0.17.1" | |
| 990 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 991 | +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" | |
| 992 | + | |
| 993 | +[[package]] | |
| 994 | +name = "heapless" | |
| 995 | +version = "0.8.0" | |
| 996 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 997 | +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" | |
| 998 | +dependencies = [ | |
| 999 | + "hash32", | |
| 1000 | + "stable_deref_trait", | |
| 1001 | +] | |
| 1002 | + | |
| 1003 | +[[package]] | |
| 1004 | +name = "hybrid-array" | |
| 1005 | +version = "0.4.15" | |
| 1006 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1007 | +checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17" | |
| 1008 | +dependencies = [ | |
| 1009 | + "typenum", | |
| 1010 | +] | |
| 1011 | + | |
| 1012 | +[[package]] | |
| 1013 | +name = "itoa" | |
| 1014 | +version = "1.0.18" | |
| 1015 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1016 | +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" | |
| 1017 | + | |
| 1018 | +[[package]] | |
| 1019 | +name = "jiff" | |
| 1020 | +version = "0.2.38" | |
| 1021 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1022 | +checksum = "b2b005715dcbeb0089a3c0dab99f2ff1cc3b2525323552703d648585d342a383" | |
| 1023 | +dependencies = [ | |
| 1024 | + "defmt 1.2.0", | |
| 1025 | + "jiff-core", | |
| 1026 | + "jiff-static", | |
| 1027 | + "jiff-tzdb-platform", | |
| 1028 | + "log", | |
| 1029 | + "portable-atomic", | |
| 1030 | + "portable-atomic-util", | |
| 1031 | + "serde_core", | |
| 1032 | + "windows-link", | |
| 1033 | +] | |
| 1034 | + | |
| 1035 | +[[package]] | |
| 1036 | +name = "jiff-core" | |
| 1037 | +version = "0.1.1" | |
| 1038 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1039 | +checksum = "5e52fe76043ccecc9005d2305ebaadf7d7fc0cc89ca6baa10a94d6bc68c7128c" | |
| 1040 | +dependencies = [ | |
| 1041 | + "defmt 1.2.0", | |
| 1042 | + "log", | |
| 1043 | +] | |
| 1044 | + | |
| 1045 | +[[package]] | |
| 1046 | +name = "jiff-static" | |
| 1047 | +version = "0.2.38" | |
| 1048 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1049 | +checksum = "2cc9817253cf7c7ee4684451bd327e88d6f3658014e54a29198625590650695c" | |
| 1050 | +dependencies = [ | |
| 1051 | + "jiff-core", | |
| 1052 | + "proc-macro2", | |
| 1053 | + "quote", | |
| 1054 | + "syn 2.0.119", | |
| 1055 | +] | |
| 1056 | + | |
| 1057 | +[[package]] | |
| 1058 | +name = "jiff-tzdb" | |
| 1059 | +version = "0.1.9" | |
| 1060 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1061 | +checksum = "fa8377070c6bae868759445e5a77f66d84f0b72f3a054bfb00e6d038b8282da7" | |
| 1062 | + | |
| 1063 | +[[package]] | |
| 1064 | +name = "jiff-tzdb-platform" | |
| 1065 | +version = "0.1.3" | |
| 1066 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1067 | +checksum = "875a5a69ac2bab1a891711cf5eccbec1ce0341ea805560dcd90b7a2e925132e8" | |
| 1068 | +dependencies = [ | |
| 1069 | + "jiff-tzdb", | |
| 1070 | +] | |
| 1071 | + | |
| 1072 | +[[package]] | |
| 1073 | +name = "jobserver" | |
| 1074 | +version = "0.1.35" | |
| 1075 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1076 | +checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3" | |
| 1077 | +dependencies = [ | |
| 1078 | + "getrandom", | |
| 1079 | + "libc", | |
| 1080 | +] | |
| 1081 | + | |
| 1082 | +[[package]] | |
| 1083 | +name = "libc" | |
| 1084 | +version = "0.2.190" | |
| 1085 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1086 | +checksum = "ce5d3ddc6d3fa000eb1536d85e147bfe31aacaba692ed6a876f95cb7c855be78" | |
| 1087 | + | |
| 1088 | +[[package]] | |
| 1089 | +name = "libfuzzer-sys" | |
| 1090 | +version = "0.4.13" | |
| 1091 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1092 | +checksum = "a9fd2f41a1cba099f79a0b6b6c35656cf7c03351a7bae8ff0f28f25270f929d2" | |
| 1093 | +dependencies = [ | |
| 1094 | + "arbitrary", | |
| 1095 | + "cc", | |
| 1096 | +] | |
| 1097 | + | |
| 1098 | +[[package]] | |
| 1099 | +name = "linux-raw-sys" | |
| 1100 | +version = "0.12.1" | |
| 1101 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1102 | +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" | |
| 1103 | + | |
| 1104 | +[[package]] | |
| 1105 | +name = "lock_api" | |
| 1106 | +version = "0.4.14" | |
| 1107 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1108 | +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" | |
| 1109 | +dependencies = [ | |
| 1110 | + "scopeguard", | |
| 1111 | +] | |
| 1112 | + | |
| 1113 | +[[package]] | |
| 1114 | +name = "log" | |
| 1115 | +version = "0.4.34" | |
| 1116 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1117 | +checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" | |
| 1118 | + | |
| 1119 | +[[package]] | |
| 1120 | +name = "memchr" | |
| 1121 | +version = "2.8.3" | |
| 1122 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1123 | +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" | |
| 1124 | + | |
| 1125 | +[[package]] | |
| 1126 | +name = "memmap2" | |
| 1127 | +version = "0.9.11" | |
| 1128 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1129 | +checksum = "d1219ed1b7f229ee7104d281dd01d6802fe28bb6e95d292942c4daacdeb798c0" | |
| 1130 | +dependencies = [ | |
| 1131 | + "libc", | |
| 1132 | +] | |
| 1133 | + | |
| 1134 | +[[package]] | |
| 1135 | +name = "multiversion_no_op" | |
| 1136 | +version = "1.0.0" | |
| 1137 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1138 | +checksum = "743fb55ba31b18fb1ecef6bdc9aa2743314978ac084044301a7eee33fb99a20d" | |
| 1139 | + | |
| 1140 | +[[package]] | |
| 1141 | +name = "nonempty" | |
| 1142 | +version = "0.12.0" | |
| 1143 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1144 | +checksum = "9737e026353e5cd0736f98eddae28665118eb6f6600902a7f50db585621fecb6" | |
| 1145 | + | |
| 1146 | +[[package]] | |
| 1147 | +name = "once_cell" | |
| 1148 | +version = "1.21.4" | |
| 1149 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1150 | +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" | |
| 1151 | + | |
| 1152 | +[[package]] | |
| 1153 | +name = "parking_lot" | |
| 1154 | +version = "0.12.5" | |
| 1155 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1156 | +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" | |
| 1157 | +dependencies = [ | |
| 1158 | + "lock_api", | |
| 1159 | + "parking_lot_core", | |
| 1160 | +] | |
| 1161 | + | |
| 1162 | +[[package]] | |
| 1163 | +name = "parking_lot_core" | |
| 1164 | +version = "0.9.12" | |
| 1165 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1166 | +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" | |
| 1167 | +dependencies = [ | |
| 1168 | + "cfg-if", | |
| 1169 | + "libc", | |
| 1170 | + "redox_syscall", | |
| 1171 | + "smallvec", | |
| 1172 | + "windows-link", | |
| 1173 | +] | |
| 1174 | + | |
| 1175 | +[[package]] | |
| 1176 | +name = "percent-encoding" | |
| 1177 | +version = "2.3.2" | |
| 1178 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1179 | +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" | |
| 1180 | + | |
| 1181 | +[[package]] | |
| 1182 | +name = "portable-atomic" | |
| 1183 | +version = "1.15.0" | |
| 1184 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1185 | +checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85" | |
| 1186 | + | |
| 1187 | +[[package]] | |
| 1188 | +name = "portable-atomic-util" | |
| 1189 | +version = "0.2.8" | |
| 1190 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1191 | +checksum = "10ab3eb7f3becc3a1cbc4f2c6f20267996cfc1a6467a873763411b136a122715" | |
| 1192 | +dependencies = [ | |
| 1193 | + "portable-atomic", | |
| 1194 | +] | |
| 1195 | + | |
| 1196 | +[[package]] | |
| 1197 | +name = "proc-macro2" | |
| 1198 | +version = "1.0.107" | |
| 1199 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1200 | +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" | |
| 1201 | +dependencies = [ | |
| 1202 | + "unicode-ident", | |
| 1203 | +] | |
| 1204 | + | |
| 1205 | +[[package]] | |
| 1206 | +name = "prodash" | |
| 1207 | +version = "31.0.1" | |
| 1208 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1209 | +checksum = "cf52d87428247c5aa3760ac8e7d8b13ec7b3579b955a8c3f311668b6860acba5" | |
| 1210 | +dependencies = [ | |
| 1211 | + "parking_lot", | |
| 1212 | +] | |
| 1213 | + | |
| 1214 | +[[package]] | |
| 1215 | +name = "quote" | |
| 1216 | +version = "1.0.47" | |
| 1217 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1218 | +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" | |
| 1219 | +dependencies = [ | |
| 1220 | + "proc-macro2", | |
| 1221 | +] | |
| 1222 | + | |
| 1223 | +[[package]] | |
| 1224 | +name = "r-efi" | |
| 1225 | +version = "6.0.0" | |
| 1226 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1227 | +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" | |
| 1228 | + | |
| 1229 | +[[package]] | |
| 1230 | +name = "redox_syscall" | |
| 1231 | +version = "0.5.18" | |
| 1232 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1233 | +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" | |
| 1234 | +dependencies = [ | |
| 1235 | + "bitflags 2.13.2", | |
| 1236 | +] | |
| 1237 | + | |
| 1238 | +[[package]] | |
| 1239 | +name = "regex-automata" | |
| 1240 | +version = "0.4.18" | |
| 1241 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1242 | +checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2" | |
| 1243 | + | |
| 1244 | +[[package]] | |
| 1245 | +name = "rustix" | |
| 1246 | +version = "1.1.5" | |
| 1247 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1248 | +checksum = "891efababe418670775f199f0d233d84843c227a0949a883ce15b37c78d6629d" | |
| 1249 | +dependencies = [ | |
| 1250 | + "bitflags 2.13.2", | |
| 1251 | + "errno", | |
| 1252 | + "libc", | |
| 1253 | + "linux-raw-sys", | |
| 1254 | + "windows-sys", | |
| 1255 | +] | |
| 1256 | + | |
| 1257 | +[[package]] | |
| 1258 | +name = "rustversion" | |
| 1259 | +version = "1.0.23" | |
| 1260 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1261 | +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" | |
| 1262 | + | |
| 1263 | +[[package]] | |
| 1264 | +name = "same-file" | |
| 1265 | +version = "1.0.6" | |
| 1266 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1267 | +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" | |
| 1268 | +dependencies = [ | |
| 1269 | + "winapi-util", | |
| 1270 | +] | |
| 1271 | + | |
| 1272 | +[[package]] | |
| 1273 | +name = "scopeguard" | |
| 1274 | +version = "1.2.0" | |
| 1275 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1276 | +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" | |
| 1277 | + | |
| 1278 | +[[package]] | |
| 1279 | +name = "serde" | |
| 1280 | +version = "1.0.229" | |
| 1281 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1282 | +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" | |
| 1283 | +dependencies = [ | |
| 1284 | + "serde_core", | |
| 1285 | +] | |
| 1286 | + | |
| 1287 | +[[package]] | |
| 1288 | +name = "serde_core" | |
| 1289 | +version = "1.0.229" | |
| 1290 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1291 | +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" | |
| 1292 | +dependencies = [ | |
| 1293 | + "serde_derive", | |
| 1294 | +] | |
| 1295 | + | |
| 1296 | +[[package]] | |
| 1297 | +name = "serde_derive" | |
| 1298 | +version = "1.0.229" | |
| 1299 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1300 | +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" | |
| 1301 | +dependencies = [ | |
| 1302 | + "proc-macro2", | |
| 1303 | + "quote", | |
| 1304 | + "syn 3.0.9", | |
| 1305 | +] | |
| 1306 | + | |
| 1307 | +[[package]] | |
| 1308 | +name = "sha1dc" | |
| 1309 | +version = "0.1.5" | |
| 1310 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1311 | +checksum = "c5b0ebf6537e3e8db8bb7d21ecb6d7399738c953c757945c6b95e46c4e95df7b" | |
| 1312 | + | |
| 1313 | +[[package]] | |
| 1314 | +name = "sha2" | |
| 1315 | +version = "0.11.1" | |
| 1316 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1317 | +checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19" | |
| 1318 | +dependencies = [ | |
| 1319 | + "cfg-if", | |
| 1320 | + "cpufeatures", | |
| 1321 | + "digest", | |
| 1322 | +] | |
| 1323 | + | |
| 1324 | +[[package]] | |
| 1325 | +name = "shlex" | |
| 1326 | +version = "2.0.1" | |
| 1327 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1328 | +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" | |
| 1329 | + | |
| 1330 | +[[package]] | |
| 1331 | +name = "simdutf8" | |
| 1332 | +version = "0.1.5" | |
| 1333 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1334 | +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" | |
| 1335 | + | |
| 1336 | +[[package]] | |
| 1337 | +name = "smallvec" | |
| 1338 | +version = "1.16.3" | |
| 1339 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1340 | +checksum = "5b3dc8af474f516a851ff4bd12db780f948b9250ad37211e4eec0bccea54e01b" | |
| 1341 | + | |
| 1342 | +[[package]] | |
| 1343 | +name = "stable_deref_trait" | |
| 1344 | +version = "1.2.1" | |
| 1345 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1346 | +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" | |
| 1347 | + | |
| 1348 | +[[package]] | |
| 1349 | +name = "syn" | |
| 1350 | +version = "2.0.119" | |
| 1351 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1352 | +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" | |
| 1353 | +dependencies = [ | |
| 1354 | + "proc-macro2", | |
| 1355 | + "quote", | |
| 1356 | + "unicode-ident", | |
| 1357 | +] | |
| 1358 | + | |
| 1359 | +[[package]] | |
| 1360 | +name = "syn" | |
| 1361 | +version = "3.0.9" | |
| 1362 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1363 | +checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b" | |
| 1364 | +dependencies = [ | |
| 1365 | + "proc-macro2", | |
| 1366 | + "quote", | |
| 1367 | + "unicode-ident", | |
| 1368 | +] | |
| 1369 | + | |
| 1370 | +[[package]] | |
| 1371 | +name = "tempfile" | |
| 1372 | +version = "3.27.0" | |
| 1373 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1374 | +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" | |
| 1375 | +dependencies = [ | |
| 1376 | + "fastrand", | |
| 1377 | + "getrandom", | |
| 1378 | + "once_cell", | |
| 1379 | + "rustix", | |
| 1380 | + "windows-sys", | |
| 1381 | +] | |
| 1382 | + | |
| 1383 | +[[package]] | |
| 1384 | +name = "thiserror" | |
| 1385 | +version = "2.0.21" | |
| 1386 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1387 | +checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e" | |
| 1388 | +dependencies = [ | |
| 1389 | + "thiserror-impl", | |
| 1390 | +] | |
| 1391 | + | |
| 1392 | +[[package]] | |
| 1393 | +name = "thiserror-impl" | |
| 1394 | +version = "2.0.21" | |
| 1395 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1396 | +checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524" | |
| 1397 | +dependencies = [ | |
| 1398 | + "proc-macro2", | |
| 1399 | + "quote", | |
| 1400 | + "syn 3.0.9", | |
| 1401 | +] | |
| 1402 | + | |
| 1403 | +[[package]] | |
| 1404 | +name = "tinyvec" | |
| 1405 | +version = "1.13.3" | |
| 1406 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1407 | +checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee" | |
| 1408 | + | |
| 1409 | +[[package]] | |
| 1410 | +name = "typenum" | |
| 1411 | +version = "1.20.1" | |
| 1412 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1413 | +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" | |
| 1414 | + | |
| 1415 | +[[package]] | |
| 1416 | +name = "unicode-bom" | |
| 1417 | +version = "2.0.3" | |
| 1418 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1419 | +checksum = "7eec5d1121208364f6793f7d2e222bf75a915c19557537745b195b253dd64217" | |
| 1420 | + | |
| 1421 | +[[package]] | |
| 1422 | +name = "unicode-ident" | |
| 1423 | +version = "1.0.27" | |
| 1424 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1425 | +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" | |
| 1426 | + | |
| 1427 | +[[package]] | |
| 1428 | +name = "unicode-normalization" | |
| 1429 | +version = "0.1.25" | |
| 1430 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1431 | +checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8" | |
| 1432 | +dependencies = [ | |
| 1433 | + "tinyvec", | |
| 1434 | +] | |
| 1435 | + | |
| 1436 | +[[package]] | |
| 1437 | +name = "walkdir" | |
| 1438 | +version = "2.5.0" | |
| 1439 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1440 | +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" | |
| 1441 | +dependencies = [ | |
| 1442 | + "same-file", | |
| 1443 | + "winapi-util", | |
| 1444 | +] | |
| 1445 | + | |
| 1446 | +[[package]] | |
| 1447 | +name = "winapi-util" | |
| 1448 | +version = "0.1.11" | |
| 1449 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1450 | +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" | |
| 1451 | +dependencies = [ | |
| 1452 | + "windows-sys", | |
| 1453 | +] | |
| 1454 | + | |
| 1455 | +[[package]] | |
| 1456 | +name = "windows-link" | |
| 1457 | +version = "0.2.1" | |
| 1458 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1459 | +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" | |
| 1460 | + | |
| 1461 | +[[package]] | |
| 1462 | +name = "windows-sys" | |
| 1463 | +version = "0.61.2" | |
| 1464 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1465 | +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" | |
| 1466 | +dependencies = [ | |
| 1467 | + "windows-link", | |
| 1468 | +] | |
| 1469 | + | |
| 1470 | +[[package]] | |
| 1471 | +name = "zlib-rs" | |
| 1472 | +version = "0.6.8" | |
| 1473 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1474 | +checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112" |
modified fuzz/Cargo.toml +15 −0
| @@ -14,6 +14,7 @@ | ||
| 14 | 14 | [dependencies] |
| 15 | 15 | libfuzzer-sys = "0.4" |
| 16 | 16 | braid-format = { package = "elffuss-braid-format", path = "../crates/format" } |
| 17 | +braid-git = { package = "elffuss-braid-git", path = "../crates/git", features = ["fuzzing"] } | |
| 17 | 18 | |
| 18 | 19 | [[bin]] |
| 19 | 20 | name = "decode_tree" |
| @@ -35,3 +36,17 @@ | ||
| 35 | 36 | test = false |
| 36 | 37 | doc = false |
| 37 | 38 | bench = false |
| 39 | + | |
| 40 | +[[bin]] | |
| 41 | +name = "git_map" | |
| 42 | +path = "fuzz_targets/git_map.rs" | |
| 43 | +test = false | |
| 44 | +doc = false | |
| 45 | +bench = false | |
| 46 | + | |
| 47 | +[[bin]] | |
| 48 | +name = "git_objects" | |
| 49 | +path = "fuzz_targets/git_objects.rs" | |
| 50 | +test = false | |
| 51 | +doc = false | |
| 52 | +bench = false |
added fuzz/fuzz_targets/git_map.rs +29 −0
| @@ -0,0 +1,29 @@ | ||
| 1 | +// SPDX-License-Identifier: Apache-2.0 | |
| 2 | +// Copyright (c) 2026 UtopiaIA | |
| 3 | + | |
| 4 | +//! A git map either fails to decode or re-encodes to exactly its input. | |
| 5 | +//! | |
| 6 | +//! Each input is tried as given and behind a valid header, so the fuzzer | |
| 7 | +//! spends its time on the tables rather than on finding the magic string. | |
| 8 | + | |
| 9 | +#![no_main] | |
| 10 | + | |
| 11 | +use braid_git::GitMap; | |
| 12 | +use libfuzzer_sys::fuzz_target; | |
| 13 | + | |
| 14 | +/// The magic string and version of a version 1 map. | |
| 15 | +const HEADER: &[u8] = b"braid-git-map\x01"; | |
| 16 | + | |
| 17 | +fn check(bytes: &[u8]) { | |
| 18 | + if let Ok(map) = GitMap::from_bytes(bytes) { | |
| 19 | + assert_eq!(map.to_bytes(), bytes); | |
| 20 | + } | |
| 21 | +} | |
| 22 | + | |
| 23 | +fuzz_target!(|data: &[u8]| { | |
| 24 | + assert!(GitMap::new().to_bytes().starts_with(HEADER)); | |
| 25 | + check(data); | |
| 26 | + let mut framed = HEADER.to_vec(); | |
| 27 | + framed.extend_from_slice(data); | |
| 28 | + check(&framed); | |
| 29 | +}); |
added fuzz/fuzz_targets/git_objects.rs +97 −0
| @@ -0,0 +1,97 @@ | ||
| 1 | +// SPDX-License-Identifier: Apache-2.0 | |
| 2 | +// Copyright (c) 2026 UtopiaIA | |
| 3 | + | |
| 4 | +//! The parsers of raw git commits, tags and trees never panic on any input. | |
| 5 | +//! | |
| 6 | +//! - A commit's message is the end of its bytes, and a commit generated from | |
| 7 | +//! what was read, when it can be written at all, reads back the same. | |
| 8 | +//! - A tree's entries, written back as they were read, give exactly its bytes. | |
| 9 | +//! | |
| 10 | +//! Each input is also tried behind a valid first header, and as the author | |
| 11 | +//! and committer lines of a commit, so the fuzzer spends its time on what | |
| 12 | +//! follows rather than on finding the header names. | |
| 13 | + | |
| 14 | +#![no_main] | |
| 15 | + | |
| 16 | +use braid_git::fuzzing::{ | |
| 17 | + EntryType, encode_commit, parse_commit, parse_signature, parse_tag, parse_tree, | |
| 18 | +}; | |
| 19 | +use libfuzzer_sys::fuzz_target; | |
| 20 | + | |
| 21 | +const TREE_HEADER: &[u8] = b"tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904\n"; | |
| 22 | +const OBJECT_HEADER: &[u8] = b"object 4b825dc642cb6eb9a060e54bf8d69288fbee4904\n"; | |
| 23 | + | |
| 24 | +fn commit(data: &[u8]) { | |
| 25 | + let Ok(fields) = parse_commit(data) else { | |
| 26 | + return; | |
| 27 | + }; | |
| 28 | + assert!(data.ends_with(fields.message)); | |
| 29 | + let author = fields.author.map(parse_signature); | |
| 30 | + let committer = fields.committer.map(parse_signature); | |
| 31 | + if let (Some(author), Some(committer)) = (author, committer) | |
| 32 | + && let Ok(bytes) = encode_commit( | |
| 33 | + fields.tree, | |
| 34 | + &fields.parents, | |
| 35 | + &author, | |
| 36 | + &committer, | |
| 37 | + &[], | |
| 38 | + fields.message, | |
| 39 | + ) | |
| 40 | + { | |
| 41 | + let again = parse_commit(&bytes).expect("a generated commit reads back"); | |
| 42 | + assert_eq!(again.tree, fields.tree); | |
| 43 | + assert_eq!(again.parents, fields.parents); | |
| 44 | + assert_eq!(again.author.map(parse_signature), Some(author)); | |
| 45 | + assert_eq!(again.committer.map(parse_signature), Some(committer)); | |
| 46 | + assert_eq!(again.message, fields.message); | |
| 47 | + } | |
| 48 | +} | |
| 49 | + | |
| 50 | +fn tree(data: &[u8]) { | |
| 51 | + let Ok(entries) = parse_tree(data) else { | |
| 52 | + return; | |
| 53 | + }; | |
| 54 | + let mut written = Vec::with_capacity(data.len()); | |
| 55 | + for entry in &entries { | |
| 56 | + let _ = EntryType::from_mode(entry.mode); | |
| 57 | + written.extend_from_slice(entry.mode); | |
| 58 | + written.push(b' '); | |
| 59 | + written.extend_from_slice(entry.name); | |
| 60 | + written.push(0); | |
| 61 | + written.extend_from_slice(entry.oid.as_bytes()); | |
| 62 | + } | |
| 63 | + assert_eq!(written, data); | |
| 64 | +} | |
| 65 | + | |
| 66 | +fn framed(header: &[u8], data: &[u8]) -> Vec<u8> { | |
| 67 | + let mut bytes = header.to_vec(); | |
| 68 | + bytes.extend_from_slice(data); | |
| 69 | + bytes | |
| 70 | +} | |
| 71 | + | |
| 72 | +/// A commit whose author and committer values are the first two lines of | |
| 73 | +/// `data`, followed by the rest of it. | |
| 74 | +fn with_signatures(data: &[u8]) -> Vec<u8> { | |
| 75 | + let mut lines = data.splitn(3, |byte| *byte == b'\n'); | |
| 76 | + let author = lines.next().unwrap_or_default(); | |
| 77 | + let committer = lines.next().unwrap_or_default(); | |
| 78 | + let rest = lines.next().unwrap_or_default(); | |
| 79 | + let mut bytes = TREE_HEADER.to_vec(); | |
| 80 | + bytes.extend_from_slice(b"parent 4b825dc642cb6eb9a060e54bf8d69288fbee4904\n"); | |
| 81 | + bytes.extend_from_slice(b"author "); | |
| 82 | + bytes.extend_from_slice(author); | |
| 83 | + bytes.extend_from_slice(b"\ncommitter "); | |
| 84 | + bytes.extend_from_slice(committer); | |
| 85 | + bytes.push(b'\n'); | |
| 86 | + bytes.extend_from_slice(rest); | |
| 87 | + bytes | |
| 88 | +} | |
| 89 | + | |
| 90 | +fuzz_target!(|data: &[u8]| { | |
| 91 | + commit(data); | |
| 92 | + commit(&framed(TREE_HEADER, data)); | |
| 93 | + commit(&with_signatures(data)); | |
| 94 | + let _ = parse_tag(data); | |
| 95 | + assert!(parse_tag(&framed(OBJECT_HEADER, data)).is_ok()); | |
| 96 | + tree(data); | |
| 97 | +}); |