diff --git a/Cargo.lock b/Cargo.lock index 4da5ab4..4f89688 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,18 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "allocator-api2" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" + [[package]] name = "android_system_properties" version = "0.1.6" @@ -11,6 +23,15 @@ dependencies = [ "libc", ] +[[package]] +name = "arc-swap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380962b3d93b99642e50b9febf72c071e97e8b32d86eae9cf4ef582bb960ae6e" +dependencies = [ + "rustversion", +] + [[package]] name = "arrayvec" version = "0.7.8" @@ -23,6 +44,18 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" +[[package]] +name = "base64" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.13.2" @@ -42,12 +75,35 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "bstr" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb31b46c14244e20ee9984b11bf5c992b91fb6939fea616e3512c8baecdbe5f" +dependencies = [ + "memchr", + "regex-automata", + "serde_core", +] + [[package]] name = "bumpalo" version = "3.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + [[package]] name = "cc" version = "1.9.0" @@ -76,6 +132,15 @@ dependencies = [ "windows-link", ] +[[package]] +name = "clru" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "197fd99cb113a8d5d9b6376f3aa817f32c1078f2343b714fff7d2ca44fdf67d5" +dependencies = [ + "hashbrown 0.16.1", +] + [[package]] name = "constant_time_eq" version = "0.4.2" @@ -88,6 +153,12 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "core_detect" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48" + [[package]] name = "cpufeatures" version = "0.3.1" @@ -97,6 +168,96 @@ dependencies = [ "libc", ] +[[package]] +name = "crc32fast" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ba106e844045ddc02c20768ac4b0b7cb45f2cc2ecbd833ac9f5dacb183c2055" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98b0cc327b5bc766e7fda9c9260cc0fa81b43a8e240440422dff70788e3f9ef1" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6" + +[[package]] +name = "defmt" +version = "0.3.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4deef977660e373c458df605a913d4ab121db0ccd18d1ad6976dff7d37cddb53" +dependencies = [ + "defmt 1.2.0", +] + +[[package]] +name = "defmt" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4a0795ac740cb54d7b3775c9c17345f6aaecf884c01733b39d6017738e0e3e1" +dependencies = [ + "bitflags 1.3.2", + "defmt-macros", +] + +[[package]] +name = "defmt-macros" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "840bb056bd99c495c9188198a258ab787c79f306d864db3e6e8451442d6d8366" +dependencies = [ + "defmt-parser", + "proc-macro2", + "quote", + "syn 3.0.9", +] + +[[package]] +name = "defmt-parser" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71958f69fb2de856c5dd51ac9377e986ca1aa5919f931bf5395a807277f889a0" +dependencies = [ + "thiserror", +] + +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + +[[package]] +name = "encoding_rs" +version = "0.8.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e985e0451871ad22fb8d2b6b076e2028a502a0d3950998c2c5c0a4f9b5d9679" +dependencies = [ + "cfg-if", + "core_detect", + "multiversion_no_op", + "rustversion", + "scopeguard", + "simdutf8", +] + +[[package]] +name = "equivalent" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" + [[package]] name = "errno" version = "0.3.14" @@ -104,7 +265,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -119,6 +280,18 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" +[[package]] +name = "faster-hex" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04839bdf9d8c10f66806fad16b852fc72aab80873aebc3cb69d85b4fa41543ed" +dependencies = [ + "autocfg", + "defmt 0.3.101", + "heapless", + "serde", +] + [[package]] name = "fastrand" version = "2.5.0" @@ -131,12 +304,28 @@ version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" +[[package]] +name = "flate2" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e634e2e0ebac1ee034020da1ca582e17ffe4e0f5e985823721e168928136dcb" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "foldhash" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + [[package]] name = "futures-core" version = "0.3.34" @@ -161,6 +350,17 @@ dependencies = [ "slab", ] +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "getrandom" version = "0.4.3" @@ -172,24 +372,714 @@ dependencies = [ "r-efi", ] +[[package]] +name = "gix" +version = "0.89.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2156d2e07fc3afa7632a82bf3cb0db91f995645a2852f642105c9ac9b52e1cb2" +dependencies = [ + "gix-actor", + "gix-commitgraph", + "gix-config", + "gix-date", + "gix-diff", + "gix-discover", + "gix-error", + "gix-fs", + "gix-glob", + "gix-hash", + "gix-hashtable", + "gix-lock", + "gix-note", + "gix-object", + "gix-odb", + "gix-pack", + "gix-parallel", + "gix-path", + "gix-protocol", + "gix-quote", + "gix-ref", + "gix-refspec", + "gix-revision", + "gix-revwalk", + "gix-sec", + "gix-shallow", + "gix-tempfile", + "gix-trace", + "gix-traverse", + "gix-url", + "gix-utils", + "gix-validate", + "gix-worktree-stream", + "gix-zlib", + "nonempty", + "smallvec", +] + +[[package]] +name = "gix-actor" +version = "0.44.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2127da41042965ed205568a52443465806944f71c8acd73f48ec94b8cd8e798e" +dependencies = [ + "bstr", + "gix-date", + "gix-error", +] + +[[package]] +name = "gix-attributes" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0feca0b8919aba9f123b75de54062dd61eb37d2a2130f34be520da6ed8b8ef72" +dependencies = [ + "bstr", + "gix-error", + "gix-glob", + "gix-parallel", + "gix-path", + "gix-quote", + "gix-trace", + "smallvec", + "unicode-bom", +] + +[[package]] +name = "gix-chunk" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "626335faf30ed235744642c2309aa370683b8bb2757f1c22a807e274dff60074" +dependencies = [ + "gix-error", +] + +[[package]] +name = "gix-command" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac560c05e19455016a4a94b33a77debe59aaed8783da32a73d31c9975947152e" +dependencies = [ + "bstr", + "gix-error", + "gix-path", + "gix-quote", + "gix-trace", +] + +[[package]] +name = "gix-commitgraph" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfede9936d4b789867c09722576aea4ceb0e3aacf962eef035ebab0686b41a80" +dependencies = [ + "bstr", + "gix-chunk", + "gix-error", + "gix-hash", + "memmap2", + "nonempty", +] + +[[package]] +name = "gix-config" +version = "0.62.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65a9c000fa9a9154f22ffc8f8d74426e9300d759c2029e8701e2ba39d5d464ea" +dependencies = [ + "bstr", + "gix-config-value", + "gix-error", + "gix-glob", + "gix-parallel", + "gix-path", + "gix-ref", + "gix-sec", + "gix-trace", + "gix-utils", + "smallvec", + "unicode-bom", +] + +[[package]] +name = "gix-config-value" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab206c2fccfd35e0de7fb1b424997cfd42912062c66dae024e08a06e22d46674" +dependencies = [ + "bitflags 2.13.2", + "bstr", + "gix-error", + "gix-path", + "gix-utils", + "libc", +] + +[[package]] +name = "gix-date" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f7eeeecc599082f32b5ea6a8c4c734e38be9730e2c09e3fe2851bb4692393e9" +dependencies = [ + "bstr", + "gix-error", + "itoa", + "jiff", +] + +[[package]] +name = "gix-diff" +version = "0.69.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa640963fdcbc6b4718e48593c3917f5ae764b59fb5a96313cb5a757246d041d" +dependencies = [ + "bstr", + "gix-error", + "gix-hash", + "gix-object", +] + +[[package]] +name = "gix-discover" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7d0f8fd2c7e4b458eb3081362d49b54bd0131d23ecd49be802085a11f0d3cee" +dependencies = [ + "bstr", + "dunce", + "gix-error", + "gix-fs", + "gix-path", + "gix-ref", + "gix-sec", +] + +[[package]] +name = "gix-error" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb3308a948a01b94ef13d9ee7a9b28c1303d8d9a9dc33b401ff40c2184d9e04a" +dependencies = [ + "bstr", +] + +[[package]] +name = "gix-filter" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d8d932ee4043f7d77d15ee58d2be2bc95accea5dd1d77fd145de1b7c504551b" +dependencies = [ + "bstr", + "encoding_rs", + "gix-attributes", + "gix-command", + "gix-error", + "gix-hash", + "gix-object", + "gix-packetline", + "gix-path", + "gix-quote", + "gix-trace", + "gix-utils", + "smallvec", +] + +[[package]] +name = "gix-fs" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44a05d043e670c055cd8b53d078562dc0bc1e322bff6b0376b407d37cf72dcc5" +dependencies = [ + "bstr", + "gix-error", + "gix-parallel", + "gix-path", + "gix-utils", + "libc", + "walkdir", +] + +[[package]] +name = "gix-glob" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b0d03ab50fa841621031960679caf7fe94940968d9a0736d12a580f2c03e525" +dependencies = [ + "bitflags 2.13.2", + "bstr", + "gix-fs", + "gix-path", + "gix-trace", + "gix-utils", +] + +[[package]] +name = "gix-hash" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ca156064e378d8c657084365846cedb8dc498c6ea4500965a64d74f12af2be" +dependencies = [ + "faster-hex", + "gix-error", + "gix-utils", + "sha1dc", +] + +[[package]] +name = "gix-hashtable" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "916cb6b2ec42ffaca624e7867bb382a4673015cb4ffcd7330b48085d02e4c615" +dependencies = [ + "gix-hash", + "hashbrown 0.17.1", + "parking_lot", +] + +[[package]] +name = "gix-lock" +version = "26.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b2f7f5bd6b9fcd0b0dc58b0e6a708f3a47c3313876571dfe800c926c069aa5c" +dependencies = [ + "gix-error", + "gix-fs", + "gix-tempfile", + "gix-utils", +] + +[[package]] +name = "gix-macros" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f11f5429ca73cc3758c9f53af56a9fba100a8701c5b4bc30e29b8b0b15288991" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "gix-note" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd364f8bdceaed9e7f3ae40f324b16e39f20e9c7e6a6a058f7c6ec66c3e6205c" +dependencies = [ + "gix-error", + "gix-hash", + "gix-object", +] + +[[package]] +name = "gix-object" +version = "0.66.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0e38f50177e211642af154f9a7f710b7a3a637e635f9b6adb9d51973b0f9209" +dependencies = [ + "bstr", + "gix-actor", + "gix-date", + "gix-error", + "gix-hash", + "gix-hashtable", + "gix-utils", + "gix-validate", + "itoa", + "smallvec", +] + +[[package]] +name = "gix-odb" +version = "0.86.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca444f33f2140876ed6b5313c2b550b4af699008193c96f3bff5023afa9ef4ea" +dependencies = [ + "arc-swap", + "crc32fast", + "gix-error", + "gix-fs", + "gix-hash", + "gix-hashtable", + "gix-object", + "gix-pack", + "gix-parallel", + "gix-path", + "gix-quote", + "gix-trace", + "gix-utils", + "gix-zlib", + "memmap2", + "parking_lot", + "tempfile", +] + +[[package]] +name = "gix-pack" +version = "0.76.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5024cc503cd29461a705ae90b9eae772fa8f0e6fafc1c48513877dc374de05" +dependencies = [ + "clru", + "crc32fast", + "gix-chunk", + "gix-error", + "gix-hash", + "gix-hashtable", + "gix-object", + "gix-parallel", + "gix-path", + "gix-trace", + "gix-utils", + "gix-zlib", + "memmap2", + "smallvec", +] + +[[package]] +name = "gix-packetline" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830e51b227f6a925fe9308858ac91170dd00fa2880f5480fc81e8a4594fe2c35" +dependencies = [ + "bstr", + "faster-hex", + "gix-error", + "gix-trace", +] + +[[package]] +name = "gix-parallel" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e994cf1eec247ba4be7f9e7c0d58cc73f83eecb5fcb9feb595df5ba3d2078546" +dependencies = [ + "crossbeam-channel", + "gix-trace", + "once_cell", + "parking_lot", +] + +[[package]] +name = "gix-path" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6d563d4d0c975ed0df4e853f9ec962a2ba46633b1d324e1a5582541fcae0c6b" +dependencies = [ + "bstr", + "gix-error", + "gix-trace", + "gix-validate", +] + +[[package]] +name = "gix-protocol" +version = "0.67.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "832b5dc46a3c0a6f6fa8f8e571c11074add4b545c6789799ae6d6c36ae1a294e" +dependencies = [ + "bstr", + "gix-date", + "gix-error", + "gix-hash", + "gix-macros", + "gix-ref", + "gix-shallow", + "gix-transport", + "gix-utils", + "nonempty", +] + +[[package]] +name = "gix-quote" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f92bc1b13c09e88388578e8aa1e987ec35f28fca158c13b1baa7ab1a85b124" +dependencies = [ + "bstr", + "gix-error", + "gix-utils", +] + +[[package]] +name = "gix-ref" +version = "0.69.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "073bc0928e1f747823b1eaed94918119dacef4c616532bc3d17e5b7457863471" +dependencies = [ + "gix-actor", + "gix-error", + "gix-fs", + "gix-hash", + "gix-lock", + "gix-object", + "gix-parallel", + "gix-path", + "gix-tempfile", + "gix-utils", + "gix-validate", + "memmap2", +] + +[[package]] +name = "gix-refspec" +version = "0.47.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccc7010dae0df2900aa77cc67f8aca042cd80e35938ccc179010d863b1d42a0c" +dependencies = [ + "bstr", + "gix-error", + "gix-hash", + "gix-validate", + "smallvec", +] + +[[package]] +name = "gix-revision" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63210c1943b67fa700806c3c3486fc16a92b3ea871f5cf092340b8eec10a0ca1" +dependencies = [ + "bstr", + "gix-commitgraph", + "gix-date", + "gix-error", + "gix-hash", + "gix-object", + "gix-revwalk", + "nonempty", +] + +[[package]] +name = "gix-revwalk" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "800479fbbf1e7f94f663e07943a91add5499343e7aac611a81e6a0460fd44af6" +dependencies = [ + "gix-commitgraph", + "gix-date", + "gix-error", + "gix-hash", + "gix-hashtable", + "gix-object", + "smallvec", +] + +[[package]] +name = "gix-sec" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5640f642a1b471616d48230b1def7ca743cb30903441ff84800cafbab3c0fddf" +dependencies = [ + "bitflags 2.13.2", + "gix-path", + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "gix-shallow" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94bc0720a3d6b10f18e3ac382a7780bcfc4c6bee94a8b5857b8e4ec94c50d754" +dependencies = [ + "bstr", + "gix-error", + "gix-hash", + "gix-lock", + "nonempty", +] + +[[package]] +name = "gix-tempfile" +version = "26.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9275c8ae0646d840ae0156d3f90d39b7beea6e31a398afb9ee72feb293a269c" +dependencies = [ + "gix-fs", + "libc", + "parking_lot", + "tempfile", + "windows-sys 0.61.2", +] + +[[package]] +name = "gix-trace" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "133f2de116104d637541831b6acb157898556d5eeec363ab2eb1c583adc6bb56" + +[[package]] +name = "gix-transport" +version = "0.61.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e43d6b0097ea9f2f266d5d6c43b8f615ed3da7c686ec8771cd17c1cb33cb0de" +dependencies = [ + "bstr", + "gix-command", + "gix-error", + "gix-packetline", + "gix-path", + "gix-quote", + "gix-sec", + "gix-trace", + "gix-url", + "gix-utils", +] + +[[package]] +name = "gix-traverse" +version = "0.63.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a668a6e7f7688e5a43eaf161f1471ffc559de1a5fd8471e861c64d59d1699e1e" +dependencies = [ + "bitflags 2.13.2", + "gix-commitgraph", + "gix-date", + "gix-error", + "gix-hash", + "gix-hashtable", + "gix-object", + "gix-revwalk", + "smallvec", +] + +[[package]] +name = "gix-url" +version = "0.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04317dea7a5dd5253bbcab060c230f3de6a57d17cc9600c6cd7030bf4795b414" +dependencies = [ + "bstr", + "gix-error", + "gix-path", + "gix-utils", + "percent-encoding", +] + +[[package]] +name = "gix-utils" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8e770b8c34311044d1addc7b18957db0ac27183707e1140dc90e6f674a6354e" +dependencies = [ + "bstr", + "bytes", + "fastrand", + "getrandom 0.4.3", + "gix-error", + "prodash", + "unicode-normalization", +] + +[[package]] +name = "gix-validate" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbcd59cc52742468bc5c8a0e7123390d154f45e6cbd37461b0dcecdc681f2179" +dependencies = [ + "bstr", + "gix-error", +] + +[[package]] +name = "gix-worktree-stream" +version = "0.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d2789610e8179d4e0e8e51170a52a66483c103a8ad3c7db4d075b571856cb6" +dependencies = [ + "gix-attributes", + "gix-error", + "gix-filter", + "gix-fs", + "gix-hash", + "gix-object", + "gix-parallel", + "gix-path", + "gix-trace", + "gix-traverse", + "gix-utils", + "parking_lot", +] + +[[package]] +name = "gix-zlib" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c2edb206bf06f3c801f4f6789c696396171558ab9b4c7f1fe3ba4d39b00b0f4" +dependencies = [ + "gix-error", + "zlib-rs", +] + +[[package]] +name = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +dependencies = [ + "byteorder", +] + [[package]] name = "hashbrown" version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ - "foldhash", + "foldhash 0.1.5", ] +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash 0.2.0", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + [[package]] name = "hashlink" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" dependencies = [ - "hashbrown", + "hashbrown 0.15.5", ] +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "http" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + [[package]] name = "iana-time-zone" version = "0.1.65" @@ -220,6 +1110,60 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" +[[package]] +name = "jiff" +version = "0.2.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2b005715dcbeb0089a3c0dab99f2ff1cc3b2525323552703d648585d342a383" +dependencies = [ + "defmt 1.2.0", + "jiff-core", + "jiff-static", + "jiff-tzdb-platform", + "log", + "portable-atomic", + "portable-atomic-util", + "serde_core", + "windows-link", +] + +[[package]] +name = "jiff-core" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e52fe76043ccecc9005d2305ebaadf7d7fc0cc89ca6baa10a94d6bc68c7128c" +dependencies = [ + "defmt 1.2.0", + "log", +] + +[[package]] +name = "jiff-static" +version = "0.2.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cc9817253cf7c7ee4684451bd327e88d6f3658014e54a29198625590650695c" +dependencies = [ + "jiff-core", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "jiff-tzdb" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa8377070c6bae868759445e5a77f66d84f0b72f3a054bfb00e6d038b8282da7" + +[[package]] +name = "jiff-tzdb-platform" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "875a5a69ac2bab1a891711cf5eccbec1ce0341ea805560dcd90b7a2e925132e8" +dependencies = [ + "jiff-tzdb", +] + [[package]] name = "js-sys" version = "0.3.106" @@ -254,6 +1198,15 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + [[package]] name = "log" version = "0.4.34" @@ -266,6 +1219,37 @@ version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" +[[package]] +name = "memmap2" +version = "0.9.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1219ed1b7f229ee7104d281dd01d6802fe28bb6e95d292942c4daacdeb798c0" +dependencies = [ + "libc", +] + +[[package]] +name = "miniz_oxide" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "multiversion_no_op" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "743fb55ba31b18fb1ecef6bdc9aa2743314978ac084044301a7eee33fb99a20d" + +[[package]] +name = "nonempty" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9737e026353e5cd0736f98eddae28665118eb6f6600902a7f50db585621fecb6" + [[package]] name = "num-traits" version = "0.2.19" @@ -281,6 +1265,35 @@ version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + [[package]] name = "pin-project-lite" version = "0.2.17" @@ -293,6 +1306,21 @@ version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" +[[package]] +name = "portable-atomic" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85" + +[[package]] +name = "portable-atomic-util" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10ab3eb7f3becc3a1cbc4f2c6f20267996cfc1a6467a873763411b136a122715" +dependencies = [ + "portable-atomic", +] + [[package]] name = "proc-macro2" version = "1.0.107" @@ -302,6 +1330,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "prodash" +version = "31.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf52d87428247c5aa3760ac8e7d8b13ec7b3579b955a8c3f311668b6860acba5" +dependencies = [ + "parking_lot", +] + [[package]] name = "quote" version = "1.0.47" @@ -317,13 +1354,42 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags 2.13.2", +] + +[[package]] +name = "regex-automata" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2" + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "rusqlite" version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "165ca6e57b20e1351573e3729b958bc62f0e48025386970b6e4d29e7a7e71f3f" dependencies = [ - "bitflags", + "bitflags 2.13.2", "fallible-iterator", "fallible-streaming-iterator", "hashlink", @@ -337,11 +1403,46 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "891efababe418670775f199f0d233d84843c227a0949a883ce15b37c78d6629d" dependencies = [ - "bitflags", + "bitflags 2.13.2", "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls" +version = "0.23.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf" +dependencies = [ + "log", + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" +dependencies = [ + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", ] [[package]] @@ -350,6 +1451,21 @@ version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "serde" version = "1.0.229" @@ -399,12 +1515,36 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbfa15b3dddfee50a0fff136974b3e1bde555604ba463834a7eb7deb6417705d" +[[package]] +name = "sha1dc" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5b0ebf6537e3e8db8bb7d21ecb6d7399738c953c757945c6b95e46c4e95df7b" + [[package]] name = "shlex" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" +[[package]] +name = "simd-adler32" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" + +[[package]] +name = "simdutf8" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" + +[[package]] +name = "similar" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbbb5d9659141646ae647b42fe094daf6c6192d1620870b449d9557f748b2daa" + [[package]] name = "slab" version = "0.4.12" @@ -417,6 +1557,18 @@ version = "1.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b3dc8af474f516a851ff4bd12db780f948b9250ad37211e4eec0bccea54e01b" +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" version = "2.0.119" @@ -453,6 +1605,23 @@ dependencies = [ "uuid", ] +[[package]] +name = "synapse-history" +version = "0.1.0" +dependencies = [ + "chrono", + "flate2", + "gix", + "rusqlite", + "serde", + "serde_json", + "similar", + "synapse-core", + "tempfile", + "thiserror", + "ureq", +] + [[package]] name = "tempfile" version = "3.27.0" @@ -460,10 +1629,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom", + "getrandom 0.4.3", "once_cell", "rustix", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -486,19 +1655,80 @@ dependencies = [ "syn 3.0.9", ] +[[package]] +name = "tinyvec" +version = "1.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee" + +[[package]] +name = "unicode-bom" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eec5d1121208364f6793f7d2e222bf75a915c19557537745b195b253dd64217" + [[package]] name = "unicode-ident" version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" +[[package]] +name = "unicode-normalization" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75cd3fb03d5288b3ba9a1ee103ac7e9cbb59f0b03d64f8ddfcc04dd42758a85d" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "ureq" +version = "3.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a7ac20be9b7726e0bbdbf974c059676d9acb1cd414961f570a4e8231cacd7fc" +dependencies = [ + "base64", + "log", + "percent-encoding", + "rustls", + "rustls-pki-types", + "ureq-proto", + "utf8-zero", + "webpki-roots", +] + +[[package]] +name = "ureq-proto" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841583fc36089d7d59419568ae157f43a5a03a2e5a81ba87c77d1596ef46e922" +dependencies = [ + "base64", + "http", + "httparse", + "log", +] + +[[package]] +name = "utf8-zero" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8c0a043c9540bae7c578c88f91dda8bd82e59ae27c21baca69c8b191aaf5a6e" + [[package]] name = "uuid" version = "1.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7cc1186384beb7dd8eedea376413fd654937285ea6c9cfbb928dc3043ea4b606" dependencies = [ - "getrandom", + "getrandom 0.4.3", "js-sys", "serde_core", "sha1_smol", @@ -511,6 +1741,22 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + [[package]] name = "wasm-bindgen" version = "0.2.129" @@ -556,6 +1802,24 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "webpki-roots" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c1c8e20c8a38fc7d65abfe74eb7280e4aa667e8eec8bc84996d2874810748d9" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "windows-core" version = "0.62.2" @@ -615,6 +1879,15 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.61.2" @@ -624,6 +1897,82 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zeroize" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" + +[[package]] +name = "zlib-rs" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112" + [[package]] name = "zmij" version = "1.0.23" diff --git a/crates/synapse-history/Cargo.toml b/crates/synapse-history/Cargo.toml new file mode 100644 index 0000000..8a7a657 --- /dev/null +++ b/crates/synapse-history/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "synapse-history" +version = "0.1.0" +edition.workspace = true +license.workspace = true +description = "Automatic git-based backup and version history of a Synapse graph" + +[dependencies] +synapse-core.workspace = true +chrono.workspace = true +rusqlite.workspace = true +serde.workspace = true +serde_json.workspace = true +thiserror.workspace = true +# Pure-Rust git (no C toolchain: builds for Android/Windows). Local repo only; push is ours. +gix = { version = "0.89", default-features = false, features = ["sha1"] } +# Blocking HTTPS client (rustls) for pushing: gix cannot push yet. +ureq = { version = "3", default-features = false, features = ["rustls"] } +# zlib for the pack we send (already in the tree through gix/ureq). +flate2 = { version = "1", default-features = false, features = ["rust_backend"] } +# Unified text diffs for page versions. +similar = "2" + +[dev-dependencies] +tempfile = "3" diff --git a/crates/synapse-history/src/error.rs b/crates/synapse-history/src/error.rs new file mode 100644 index 0000000..2e3cce6 --- /dev/null +++ b/crates/synapse-history/src/error.rs @@ -0,0 +1,25 @@ +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum Error { + #[error("core: {0}")] + Core(#[from] synapse_core::Error), + #[error("sqlite: {0}")] + Sqlite(#[from] rusqlite::Error), + #[error("io: {0}")] + Io(#[from] std::io::Error), + #[error("json: {0}")] + Json(#[from] serde_json::Error), + #[error("git: {0}")] + Git(String), + #[error("not found: {0}")] + NotFound(String), + #[error("push: {0}")] + Push(String), +} + +pub type Result = std::result::Result; + +pub(crate) fn git(e: E) -> Error { + Error::Git(e.to_string()) +} diff --git a/crates/synapse-history/src/export.rs b/crates/synapse-history/src/export.rs new file mode 100644 index 0000000..6583f3a --- /dev/null +++ b/crates/synapse-history/src/export.rs @@ -0,0 +1,248 @@ +//! Deterministic Logseq-compatible Markdown export of pages. +//! +//! Layout: `pages/.md`, `journals/YYYY_MM_DD.md`, `assets.json`. +//! A page file starts with page properties (`key:: value`, aliases as `alias:: a, b`), +//! then one `- ` bullet per block, nested with tabs. Block properties follow the content; +//! blocks referenced by `((uuid))` carry an `id::` property. + +use crate::Result; +use crate::error::Error; +use rusqlite::Connection; +use serde_json::Value; +use std::collections::HashSet; +use synapse_core::{Block, BlockId, Graph, Page, Properties}; + +pub const PAGES_DIR: &str = "pages"; +pub const JOURNALS_DIR: &str = "journals"; +pub const MANIFEST: &str = "assets.json"; + +/// Encodes a page title as a file name (Logseq "triple-lowbar" format: `/` becomes `___`, +/// characters illegal on Windows and `%` are percent-encoded). +pub fn encode_title(title: &str) -> String { + let mut out = String::with_capacity(title.len()); + let mut run = 0usize; + let mut prev_slash = false; + // Underscore runs next to a `/` or of 3+ would read back as `/`, so they are encoded. + let flush = |out: &mut String, run: &mut usize, prev_slash: bool, next_slash: bool| { + let enc = *run >= 3 || prev_slash || next_slash; + for _ in 0..*run { + out.push_str(if enc { "%5F" } else { "_" }); + } + *run = 0; + }; + for c in title.chars() { + if c == '_' { + run += 1; + continue; + } + flush(&mut out, &mut run, prev_slash, c == '/'); + prev_slash = c == '/'; + match c { + '/' => out.push_str("___"), + '%' | '<' | '>' | ':' | '"' | '\\' | '|' | '?' | '*' => { + out.push_str(&format!("%{:02X}", c as u32)) + } + c if (c as u32) < 0x20 => out.push_str(&format!("%{:02X}", c as u32)), + c => out.push(c), + } + } + flush(&mut out, &mut run, prev_slash, false); + // Windows forbids trailing dots/spaces. + while out.ends_with('.') || out.ends_with(' ') { + let c = out.pop().unwrap(); + out.push_str(&format!("%{:02X}", c as u32)); + } + out +} + +/// Inverse of [`encode_title`]. +pub fn decode_title(name: &str) -> String { + let s = name.replace("___", "/"); + let bytes = s.as_bytes(); + let mut raw = Vec::with_capacity(bytes.len()); + let mut i = 0; + while i < bytes.len() { + let hex = (bytes[i] == b'%' && i + 2 < bytes.len()) + .then(|| std::str::from_utf8(&bytes[i + 1..i + 3]).ok()) + .flatten() + .and_then(|h| u8::from_str_radix(h, 16).ok()); + if let Some(v) = hex { + raw.push(v); + i += 3; + } else { + raw.push(bytes[i]); + i += 1; + } + } + String::from_utf8_lossy(&raw).into_owned() +} + +/// Repository-relative path of a page's Markdown file. +pub fn page_path(page: &Page) -> String { + match page.journal_date { + Some(d) => format!("{JOURNALS_DIR}/{}.md", d.format("%Y_%m_%d")), + None => format!("{PAGES_DIR}/{}.md", encode_title(&page.title)), + } +} + +/// Title (or journal date) from a repository path, if it is a page file. +pub fn title_from_path(path: &str) -> Option { + if let Some(n) = path.strip_prefix("pages/") { + return n.strip_suffix(".md").map(decode_title); + } + let n = path.strip_prefix("journals/")?.strip_suffix(".md")?; + Some(n.replace('_', "-")) +} + +pub(crate) fn render_value(v: &Value) -> String { + match v { + Value::String(s) => { + if !s.contains('\n') && parse_value(s) == Value::String(s.clone()) { + s.clone() + } else { + Value::String(s.clone()).to_string() + } + } + other => other.to_string(), + } +} + +/// Parses a property value: JSON for non-strings and quoted strings, raw text otherwise. +pub(crate) fn parse_value(raw: &str) -> Value { + let t = raw.trim(); + match serde_json::from_str::(t) { + Ok(v) => v, + Err(_) => Value::String(t.to_string()), + } +} + +fn push_props(out: &mut String, indent: &str, props: &[(String, String)]) { + for (k, v) in props { + out.push_str(indent); + out.push_str(k); + out.push_str(":: "); + out.push_str(v); + out.push('\n'); + } +} + +fn sorted_props(p: &Properties) -> Vec<(String, String)> { + let mut v: Vec<_> = p + .iter() + .map(|(k, v)| (k.clone(), render_value(v))) + .collect(); + v.sort(); + v +} + +/// Renders one block (without its children) at `depth`. +pub fn render_block(block: &Block, depth: usize, referenced: &HashSet) -> String { + let indent = "\t".repeat(depth); + let mut out = String::new(); + let mut lines = block.content.split('\n'); + let first = lines.next().unwrap_or(""); + out.push_str(&indent); + out.push('-'); + if !first.is_empty() { + out.push(' '); + out.push_str(first); + } + out.push('\n'); + let cont = format!("{indent} "); + for l in lines { + out.push_str(&cont); + out.push_str(l); + out.push('\n'); + } + let mut props = block.properties.clone(); + props.remove("id"); + props.remove("collapsed"); + let mut list = sorted_props(&props); + if block.collapsed { + list.push(("collapsed".into(), "true".into())); + } + if referenced.contains(&block.id) { + list.push(("id".into(), block.id.to_string())); + } + list.sort(); + push_props(&mut out, &cont, &list); + out +} + +/// Renders the full Markdown file of a page. +pub fn render_page(graph: &Graph, page: &Page, referenced: &HashSet) -> Result { + let mut props = page.properties.clone(); + props.remove("alias"); + let mut list = sorted_props(&props); + let aliases = graph.aliases_of(page.id)?; + if !aliases.is_empty() { + list.push(("alias".into(), aliases.join(", "))); + } + list.sort(); + let mut out = String::new(); + push_props(&mut out, "", &list); + if !list.is_empty() { + out.push('\n'); + } + for (depth, b) in graph.page_tree(page.id)? { + out.push_str(&render_block(&b, depth, referenced)); + } + Ok(out) +} + +/// Every block id that is the target of a `((uuid))` reference or embed. +pub fn referenced_blocks(conn: &Connection) -> Result> { + let mut st = conn.prepare("SELECT DISTINCT target_block FROM block_refs")?; + let rows = st.query_map([], |r| r.get::<_, String>(0))?; + let mut set = HashSet::new(); + for r in rows { + if let Ok(id) = r?.parse() { + set.insert(id); + } + } + Ok(set) +} + +/// Asset manifest (`assets.json`): sorted by hash, so it is deterministic. +pub fn render_manifest(conn: &Connection) -> Result { + let mut st = + conn.prepare("SELECT hash, size, mime, original_name FROM assets ORDER BY hash")?; + let rows = st.query_map([], |r| { + Ok(serde_json::json!({ + "hash": r.get::<_, String>(0)?, + "size": r.get::<_, i64>(1)?, + "mime": r.get::<_, Option>(2)?, + "name": r.get::<_, Option>(3)?, + })) + })?; + let list: Vec = rows.collect::>()?; + let mut s = serde_json::to_string_pretty(&list).map_err(Error::from)?; + s.push('\n'); + Ok(s) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn title_encoding_roundtrips() { + for t in [ + "Simple", + "a/b/c", + "100% sure?", + "snake_case", + "a___b", + "x____y/z", + "x_/_y", + "end.", + "q: \"w\" |r| *t*", + "Ünï/cödé 日本", + "trail ", + ] { + let e = encode_title(t); + assert!(!e.contains('/') && !e.contains(':'), "{e}"); + assert_eq!(decode_title(&e), t, "{t} -> {e}"); + } + } +} diff --git a/crates/synapse-history/src/history.rs b/crates/synapse-history/src/history.rs new file mode 100644 index 0000000..741437f --- /dev/null +++ b/crates/synapse-history/src/history.rs @@ -0,0 +1,453 @@ +//! Snapshot engine: incremental Markdown export committed to a bare git repository. + +use crate::Result; +use crate::error::Error; +use crate::export::{self, JOURNALS_DIR, MANIFEST, PAGES_DIR}; +use crate::repo::{CommitInfo, Files, Repo}; +use serde::{Deserialize, Serialize}; +use std::collections::{BTreeSet, HashMap, HashSet}; +use std::path::{Path, PathBuf}; +use std::time::Duration; +use synapse_core::{BlockId, Graph, Op, Page, PageId}; + +const STATE_FILE: &str = "synapse-history.json"; +const OPS_BATCH: u32 = 2000; +const TITLES_IN_MESSAGE: usize = 5; + +/// When [`History::maybe_snapshot`] actually commits. +#[derive(Debug, Clone, Copy)] +pub struct SnapshotPolicy { + /// Never snapshot more often than this. + pub min_interval: Duration, + /// Snapshot at the latest this long after the previous one if anything changed. + pub max_interval: Duration, + /// Snapshot once the graph has been quiet this long (still respecting `min_interval`). + pub on_idle: Option, +} + +impl Default for SnapshotPolicy { + fn default() -> Self { + Self { + min_interval: Duration::from_secs(5 * 60), + max_interval: Duration::from_secs(60 * 60), + on_idle: Some(Duration::from_secs(2 * 60)), + } + } +} + +#[derive(Debug, Clone, Default)] +pub struct HistoryOptions { + pub policy: SnapshotPolicy, + /// Also commit asset bytes (`blobs/`). Off by default: blobs are already + /// content-addressed and only the manifest is versioned. + pub include_blobs: bool, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct SnapshotInfo { + /// Full commit id (hex). + pub id: String, + /// Seconds since epoch. + pub time: i64, + /// First line of the commit message. + pub summary: String, +} + +impl From for SnapshotInfo { + fn from(c: CommitInfo) -> Self { + Self { + id: c.id, + time: c.time, + summary: c.message.lines().next().unwrap_or("").to_string(), + } + } +} + +#[derive(Debug, Default, Serialize, Deserialize)] +struct State { + /// Last op seq covered by the newest snapshot. + last_seq: i64, + /// Graph clock (ms) when the newest snapshot was taken. + snapshot_ms: i64, + /// Blocks that carried an `id::` property in the newest snapshot. + referenced: BTreeSet, +} + +pub struct History { + pub(crate) repo: Repo, + dir: PathBuf, + opts: HistoryOptions, + /// `(last seen graph seq, time we saw it change)` for idle detection. + observed: Option<(i64, i64)>, +} + +impl History { + /// Opens (creating if needed) `/history/`. + pub fn open(graph_dir: impl AsRef, opts: HistoryOptions) -> Result { + Self::open_at(graph_dir.as_ref().join("history"), opts) + } + + pub fn open_at(dir: impl Into, opts: HistoryOptions) -> Result { + let dir = dir.into(); + let repo = Repo::open_or_init(&dir)?; + Ok(Self { + repo, + dir, + opts, + observed: None, + }) + } + + pub fn dir(&self) -> &Path { + &self.dir + } + + fn load_state(&self) -> Option { + serde_json::from_slice(&std::fs::read(self.dir.join(STATE_FILE)).ok()?).ok() + } + + fn save_state(&self, s: &State) -> Result<()> { + let tmp = self.dir.join(format!("{STATE_FILE}.tmp")); + std::fs::write(&tmp, serde_json::to_vec(s)?)?; + std::fs::rename(tmp, self.dir.join(STATE_FILE))?; + Ok(()) + } + + /// True when the graph has changes not yet covered by a snapshot. + pub fn has_pending(&self, graph: &Graph) -> Result { + Ok(match self.load_state() { + Some(s) => graph.last_seq()? != s.last_seq, + None => true, + }) + } + + /// Called periodically by the app; snapshots when the policy says so. + /// `now_ms` is wall-clock milliseconds. + pub fn maybe_snapshot(&mut self, graph: &Graph, now_ms: i64) -> Result> { + let seq = graph.last_seq()?; + let changed_at = match self.observed { + Some((s, t)) if s == seq => t, + _ => now_ms, + }; + self.observed = Some((seq, changed_at)); + let state = self.load_state(); + if state.as_ref().is_some_and(|s| s.last_seq == seq) { + return Ok(None); + } + let p = self.opts.policy; + let ms = |d: Duration| d.as_millis() as i64; + let since_last = match (&state, self.repo.head()?) { + (Some(_), Some(head)) => now_ms - self.repo.commit_info(head)?.time * 1000, + _ => i64::MAX, // first snapshot: take it as soon as there is something + }; + if since_last < ms(p.min_interval) { + return Ok(None); + } + let idle = p.on_idle.is_some_and(|d| now_ms - changed_at >= ms(d)); + if since_last >= ms(p.max_interval) || idle { + return self.snapshot(graph, now_ms); + } + Ok(None) + } + + /// Takes a snapshot now. Returns `None` when nothing changed. + pub fn snapshot(&mut self, graph: &Graph, now_ms: i64) -> Result> { + let state = self.load_state(); + let head = self.repo.head()?; + let seq_now = graph.last_seq()?; + let full = match (&state, head) { + (Some(s), Some(_)) => s.last_seq > seq_now, + _ => true, + }; + if !full && state.as_ref().is_some_and(|s| s.last_seq == seq_now) { + return Ok(None); + } + let old_state = state.unwrap_or_default(); + let old_files = match head { + Some(h) => self.repo.files(h)?, + None => Files::new(), + }; + let mut files = old_files.clone(); + + // 1. Which pages may have changed? + let mut touched: HashSet = HashSet::new(); + let mut everything = full; + if !full { + let mut after = old_state.last_seq; + loop { + let ops = graph.ops_since(after, OPS_BATCH)?; + let Some(last) = ops.last() else { break }; + after = last.seq; + for rec in ops { + match rec.op { + Op::UpsertPage { page } => { + touched.insert(page.id); + } + Op::UpsertBlock { block } => { + touched.insert(block.page_id); + } + // Deletions and moves do not say which page lost a block; those + // pages are caught by the `updated_at` scan below. + Op::DeleteBlock { .. } | Op::DeletePage { .. } | Op::PutAsset { .. } => {} + // The previous owner of an alias is unknown. + Op::SetAlias { .. } => everything = true, + } + } + } + } + let mut current: HashMap = HashMap::new(); + let mut offset = 0; + loop { + let batch = graph.list_pages(true, 500, offset)?; + if batch.is_empty() { + break; + } + offset += batch.len() as u32; + for p in batch { + if p.updated_at >= old_state.snapshot_ms { + touched.insert(p.id); + } + current.insert(export::page_path(&p), p); + } + } + let referenced = export::referenced_blocks(graph.conn())?; + let old_ref: HashSet = old_state.referenced.iter().copied().collect(); + for id in referenced.symmetric_difference(&old_ref) { + if let Some(b) = graph.get_block(*id)? { + touched.insert(b.page_id); + } + } + + // 2. Rewrite touched pages, drop vanished ones. + let (mut created, mut edited, mut deleted) = + (BTreeSet::new(), BTreeSet::new(), BTreeSet::new()); + let mut paths: Vec<&String> = current.keys().collect(); + paths.sort(); + for path in paths { + let page = ¤t[path]; + if !everything && !touched.contains(&page.id) { + continue; + } + let text = export::render_page(graph, page, &referenced)?; + let oid = self.repo.write_blob(text.as_bytes())?; + match old_files.get(path) { + Some(old) if *old == oid => {} + Some(_) => { + edited.insert(page.title.clone()); + } + None => { + created.insert(page.title.clone()); + } + } + files.insert(path.clone(), oid); + } + for path in old_files.keys() { + let is_page = path.starts_with(&format!("{PAGES_DIR}/")) + || path.starts_with(&format!("{JOURNALS_DIR}/")); + if is_page && !current.contains_key(path) { + files.remove(path); + deleted.insert(export::title_from_path(path).unwrap_or_else(|| path.clone())); + } + } + + // 3. Assets. + let manifest = self + .repo + .write_blob(export::render_manifest(graph.conn())?.as_bytes())?; + let assets_changed = old_files.get(MANIFEST) != Some(&manifest); + files.insert(MANIFEST.to_string(), manifest); + if self.opts.include_blobs { + self.add_blobs(graph, &mut files)?; + } + + // 4. Commit. + let new_state = State { + last_seq: seq_now, + snapshot_ms: graph.now_ms(), + referenced: referenced.into_iter().collect(), + }; + if files == old_files && head.is_some() { + self.save_state(&new_state)?; + return Ok(None); + } + let message = commit_message(&created, &edited, &deleted, assets_changed, seq_now); + let id = self.repo.commit(&files, &message, now_ms / 1000)?; + self.save_state(&new_state)?; + Ok(Some(self.repo.commit_info(id)?.into())) + } + + fn add_blobs(&self, graph: &Graph, files: &mut Files) -> Result<()> { + let mut st = graph + .conn() + .prepare("SELECT hash FROM assets ORDER BY hash")?; + let hashes: Vec = st + .query_map([], |r| r.get(0))? + .collect::>()?; + for h in hashes { + let path = format!("blobs/{h}"); + if files.contains_key(&path) || !graph.blobs().contains(&h) { + continue; + } + let bytes = std::fs::read(graph.blobs().path_of(&h))?; + files.insert(path, self.repo.write_blob(&bytes)?); + } + Ok(()) + } + + // ------------------------------------------------------------- queries + + /// Snapshots, newest first. + pub fn snapshots(&self, limit: usize) -> Result> { + Ok(self.repo.log(limit)?.into_iter().map(Into::into).collect()) + } + + /// Resolves a snapshot reference: full or abbreviated commit id, or `HEAD`. + pub fn resolve(&self, rev: &str) -> Result { + if rev == "HEAD" { + return self + .repo + .head()? + .ok_or_else(|| Self::not_found("empty history")); + } + if rev.len() >= 4 { + let hits: Vec<_> = self + .repo + .log(usize::MAX)? + .into_iter() + .filter(|c| c.id.starts_with(rev)) + .collect(); + if let [one] = hits.as_slice() { + return Repo::parse_id(&one.id); + } + } + Err(Self::not_found(&format!("snapshot {rev}"))) + } + + /// Path of a page's file for a title (journals are titled `YYYY-MM-DD`). + pub fn path_for_title(title: &str) -> String { + match chrono::NaiveDate::parse_from_str(title, "%Y-%m-%d") { + Ok(d) => format!("{JOURNALS_DIR}/{}.md", d.format("%Y_%m_%d")), + Err(_) => format!("{PAGES_DIR}/{}.md", export::encode_title(title)), + } + } + + /// File content at a snapshot, `None` if the page did not exist then. + pub fn page_at(&self, rev: &str, title: &str) -> Result> { + self.file_at(self.resolve(rev)?, &Self::path_for_title(title)) + } + + /// Any file of a snapshot by repository path (e.g. `assets.json`). + pub fn file(&self, rev: &str, path: &str) -> Result> { + self.file_at(self.resolve(rev)?, path) + } + + pub(crate) fn file_at(&self, commit: gix::ObjectId, path: &str) -> Result> { + match self.repo.files(commit)?.get(path) { + Some(oid) => Ok(Some( + String::from_utf8_lossy(&self.repo.read_blob(*oid)?).into_owned(), + )), + None => Ok(None), + } + } + + /// Snapshots in which the page's file changed (newest first), including its creation and + /// deletion. `exists` tells whether the page was present after that snapshot. + pub fn page_history(&self, title: &str) -> Result> { + let path = Self::path_for_title(title); + let mut commits = Vec::new(); + let mut cur = self.repo.head()?; + while let Some(id) = cur { + let files = self.repo.files(id)?; + commits.push((id, files.get(&path).copied())); + cur = self.repo.parent(id)?; + } + let mut out = Vec::new(); + for (i, (id, oid)) in commits.iter().enumerate() { + let prev = commits.get(i + 1).and_then(|(_, o)| *o); + if *oid != prev { + out.push(PageVersion { + snapshot: self.repo.commit_info(*id)?.into(), + exists: oid.is_some(), + }); + } + } + Ok(out) + } + + /// Unified diff of a page between two snapshots (`from` may be `None` for "empty"). + pub fn diff_page(&self, title: &str, from: &str, to: &str) -> Result { + let a = self.page_at(from, title)?.unwrap_or_default(); + let b = self.page_at(to, title)?.unwrap_or_default(); + let diff = similar::TextDiff::from_lines(&a, &b); + Ok(diff + .unified_diff() + .context_radius(3) + .header( + &format!("{title}@{}", short(from)), + &format!("{title}@{}", short(to)), + ) + .to_string()) + } + + pub(crate) fn snapshot_files(&self, rev: &str) -> Result { + self.repo.files(self.resolve(rev)?) + } + + pub(crate) fn read_blob(&self, oid: gix::ObjectId) -> Result { + Ok(String::from_utf8_lossy(&self.repo.read_blob(oid)?).into_owned()) + } + + pub(crate) fn not_found(what: &str) -> Error { + Error::NotFound(what.to_string()) + } +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct PageVersion { + pub snapshot: SnapshotInfo, + pub exists: bool, +} + +fn short(rev: &str) -> &str { + &rev[..rev.len().min(8)] +} + +fn commit_message( + created: &BTreeSet, + edited: &BTreeSet, + deleted: &BTreeSet, + assets: bool, + seq: i64, +) -> String { + let plural = |n: usize| if n == 1 { "page" } else { "pages" }; + let mut parts = Vec::new(); + if !edited.is_empty() { + parts.push(format!("{} {} edited", edited.len(), plural(edited.len()))); + } + if !created.is_empty() { + parts.push(format!("{} created", created.len())); + } + if !deleted.is_empty() { + parts.push(format!("{} deleted", deleted.len())); + } + if parts.is_empty() { + parts.push(if assets { "assets updated" } else { "snapshot" }.to_string()); + } + let mut titles: Vec<&String> = edited.iter().chain(created).chain(deleted).collect(); + titles.sort(); + titles.dedup(); + let mut head = parts.join(", "); + if !titles.is_empty() { + let shown: Vec<&str> = titles + .iter() + .take(TITLES_IN_MESSAGE) + .map(|s| s.as_str()) + .collect(); + head.push_str(": "); + head.push_str(&shown.join(", ")); + if titles.len() > TITLES_IN_MESSAGE { + head.push_str(", …"); + } + } + format!("{head}\n\nSynapse-Seq: {seq}\n") +} diff --git a/crates/synapse-history/src/lib.rs b/crates/synapse-history/src/lib.rs new file mode 100644 index 0000000..7333bd1 --- /dev/null +++ b/crates/synapse-history/src/lib.rs @@ -0,0 +1,14 @@ +//! Automatic git-based backup and version history of a Synapse graph. See `docs/history.md`. + +mod error; +pub mod export; +mod history; +pub mod parse; +mod push; +mod repo; +mod restore; + +pub use error::{Error, Result}; +pub use history::{History, HistoryOptions, PageVersion, SnapshotInfo, SnapshotPolicy}; +pub use push::{PushAuth, PushReport}; +pub use restore::RestoreReport; diff --git a/crates/synapse-history/src/parse.rs b/crates/synapse-history/src/parse.rs new file mode 100644 index 0000000..c6cd99a --- /dev/null +++ b/crates/synapse-history/src/parse.rs @@ -0,0 +1,178 @@ +//! Parser for the Markdown files produced by [`crate::export`] (and plain Logseq pages). + +use crate::export::parse_value; +use serde_json::Value; +use synapse_core::{BlockId, Properties, parse::property_split}; + +#[derive(Debug, Clone, PartialEq)] +pub struct ParsedBlock { + pub depth: usize, + /// From an `id::` property. + pub id: Option, + pub content: String, + pub properties: Properties, + pub collapsed: bool, +} + +#[derive(Debug, Clone, Default, PartialEq)] +pub struct ParsedPage { + /// Page properties except `alias`. + pub properties: Properties, + pub aliases: Vec, + pub blocks: Vec, +} + +/// Visual width of leading whitespace (a tab counts as 2 columns) and its byte length. +fn indent_of(line: &str) -> (usize, usize) { + let mut cols = 0; + let mut bytes = 0; + for c in line.chars() { + match c { + '\t' => cols += 2, + ' ' => cols += 1, + _ => break, + } + bytes += 1; + } + (cols, bytes) +} + +fn strip_cols(line: &str, cols: usize) -> &str { + let mut left = cols; + let mut bytes = 0; + for c in line.chars() { + let w = match c { + '\t' => 2, + ' ' => 1, + _ => break, + }; + if w > left { + break; + } + left -= w; + bytes += 1; + if left == 0 { + break; + } + } + &line[bytes..] +} + +fn bullet_text(trimmed: &str) -> Option<&str> { + if trimmed == "-" { + Some("") + } else { + trimmed.strip_prefix("- ") + } +} + +struct Raw { + depth: usize, + lines: Vec, +} + +pub fn parse_page(text: &str) -> ParsedPage { + let mut page = ParsedPage::default(); + let mut raws: Vec = Vec::new(); + let mut stack: Vec = Vec::new(); // bullet columns of open ancestors + let mut col_of_current = 0usize; + + for line in text.split('\n') { + let line = line.strip_suffix('\r').unwrap_or(line); + let (cols, bytes) = indent_of(line); + if let Some(rest) = bullet_text(&line[bytes..]) { + while stack.last().is_some_and(|&c| c >= cols) { + stack.pop(); + } + raws.push(Raw { + depth: stack.len(), + lines: vec![rest.to_string()], + }); + stack.push(cols); + col_of_current = cols; + } else if let Some(cur) = raws.last_mut() { + cur.lines + .push(strip_cols(line, col_of_current + 2).to_string()); + } else if let Some((k, v)) = property_split(line.trim()) { + if k == "alias" { + page.aliases.extend( + v.split(',') + .map(|a| a.trim().trim_matches(['[', ']']).to_string()) + .filter(|a| !a.is_empty()), + ); + } else { + page.properties.insert(k.to_string(), parse_value(v)); + } + } + } + + for raw in raws { + let mut lines = raw.lines; + // Blank separator lines between blocks are not content. + while lines.len() > 1 && lines.last().is_some_and(|l| l.is_empty()) { + lines.pop(); + } + let mut props = Properties::new(); + let mut split = lines.len(); + while split > 1 { + match property_split(&lines[split - 1]) { + Some(_) => split -= 1, + None => break, + } + } + for l in &lines[split..] { + if let Some((k, v)) = property_split(l) { + props.insert(k.to_string(), parse_value(v)); + } + } + lines.truncate(split); + let id = match props.remove("id") { + Some(Value::String(s)) => s.parse().ok(), + _ => None, + }; + let collapsed = matches!(props.remove("collapsed"), Some(Value::Bool(true))); + page.blocks.push(ParsedBlock { + depth: raw.depth, + id, + content: lines.join("\n"), + properties: props, + collapsed, + }); + } + page +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parses_nesting_props_and_multiline() { + let text = "alias:: A, B\ntype:: note\n\n- root\n\tsecond line\n\tcolor:: red\n\t- child\n\t\t- deep\n- next\n"; + let p = parse_page(text); + assert_eq!(p.aliases, ["A", "B"]); + assert_eq!(p.properties["type"], "note"); + let d: Vec<_> = p + .blocks + .iter() + .map(|b| (b.depth, b.content.as_str())) + .collect(); + assert_eq!( + d, + [ + (0, "root\nsecond line"), + (1, "child"), + (2, "deep"), + (0, "next") + ] + ); + assert_eq!(p.blocks[0].properties["color"], "red"); + } + + #[test] + fn logseq_space_indent() { + let p = parse_page("- a\n - b\n - c\n - d\n"); + let d: Vec<_> = p.blocks.iter().map(|b| b.depth).collect(); + assert_eq!(d, [0, 1, 2, 1]); + } +} diff --git a/crates/synapse-history/src/push.rs b/crates/synapse-history/src/push.rs new file mode 100644 index 0000000..cbd509f --- /dev/null +++ b/crates/synapse-history/src/push.rs @@ -0,0 +1,297 @@ +//! Push the history branch to any Git smart-HTTP(S) remote. +//! +//! gix cannot push yet, so this speaks the `git-receive-pack` protocol directly: it advertises +//! refs, sends one un-deltified pack with the objects the remote lacks and reads the report. +//! Credentials are used for the HTTP `Authorization` header of this call only; nothing is +//! written to the repository or its config. + +use crate::Result; +use crate::error::{Error, git}; +use crate::history::History; +use gix::ObjectId; +use std::collections::HashSet; +use std::io::Write; + +#[derive(Clone)] +pub struct PushAuth { + pub username: String, + /// Password or access token. + pub secret: String, +} + +impl std::fmt::Debug for PushAuth { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("PushAuth") + .field("username", &self.username) + .field("secret", &"***") + .finish() + } +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct PushReport { + /// Objects sent in the pack. + pub objects: usize, + /// False when the remote already had our tip. + pub updated: bool, +} + +fn push_err(msg: impl Into) -> Error { + Error::Push(msg.into()) +} + +fn pkt(out: &mut Vec, data: &[u8]) { + out.extend_from_slice(format!("{:04x}", data.len() + 4).as_bytes()); + out.extend_from_slice(data); +} + +/// Splits pkt-lines; `None` is a flush packet. +fn parse_pkts(mut b: &[u8]) -> Result>>> { + let mut out = Vec::new(); + while b.len() >= 4 { + let n = usize::from_str_radix(std::str::from_utf8(&b[..4]).map_err(git)?, 16) + .map_err(|_| push_err("bad pkt-line"))?; + if n == 0 { + out.push(None); + b = &b[4..]; + } else { + if n < 4 || b.len() < n { + return Err(push_err("truncated pkt-line")); + } + out.push(Some(b[4..n].to_vec())); + b = &b[n..]; + } + } + Ok(out) +} + +fn basic(auth: &PushAuth) -> String { + const T: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + let raw = format!("{}:{}", auth.username, auth.secret); + let mut out = String::from("Basic "); + for c in raw.as_bytes().chunks(3) { + let n = (c[0] as u32) << 16 + | (*c.get(1).unwrap_or(&0) as u32) << 8 + | *c.get(2).unwrap_or(&0) as u32; + for i in 0..4 { + if i <= c.len() { + out.push(T[(n >> (18 - 6 * i) & 63) as usize] as char); + } else { + out.push('='); + } + } + } + out +} + +impl History { + /// Pushes the history branch to `url` (an `http(s)://` Git remote) as `branch`. + /// Fast-forward only unless `force`. + pub fn push( + &self, + url: &str, + branch: &str, + auth: Option<&PushAuth>, + force: bool, + ) -> Result { + if !(url.starts_with("https://") || url.starts_with("http://")) { + return Err(push_err("only http(s) remotes are supported")); + } + let base = url.trim_end_matches('/'); + let tip = self + .repo + .head()? + .ok_or_else(|| push_err("nothing to push: no snapshots yet"))?; + let target = format!("refs/heads/{branch}"); + let agent: ureq::Agent = ureq::Agent::config_builder() + .http_status_as_error(false) + .build() + .into(); + + // 1. Ref advertisement. + let mut req = agent.get(&format!("{base}/info/refs?service=git-receive-pack")); + if let Some(a) = auth { + req = req.header("Authorization", &basic(a)); + } + let mut resp = req.call().map_err(|e| push_err(e.to_string()))?; + if !resp.status().is_success() { + return Err(push_err(format!("remote answered {}", resp.status()))); + } + let body = resp + .body_mut() + .read_to_vec() + .map_err(|e| push_err(e.to_string()))?; + let mut old = ObjectId::null(gix::hash::Kind::Sha1); + for line in parse_pkts(&body)?.into_iter().flatten() { + let text = String::from_utf8_lossy(&line); + let first = text.split('\0').next().unwrap_or("").trim_end(); + if let Some((oid, name)) = first.split_once(' ') + && name == target + { + old = ObjectId::from_hex(oid.as_bytes()).map_err(git)?; + } + } + if old == tip { + return Ok(PushReport { + objects: 0, + updated: false, + }); + } + + // 2. Objects the remote lacks. + let mut have = HashSet::new(); + if !old.is_null() { + if self.repo.repo.find_object(old).is_ok() { + self.collect(old, &HashSet::new(), &mut have)?; + } else if !force { + return Err(push_err("remote has commits we do not have (diverged)")); + } + if !force && !self.is_ancestor(old, tip)? { + return Err(push_err("not a fast-forward (diverged)")); + } + } + let mut send = HashSet::new(); + self.collect(tip, &have, &mut send)?; + let pack = self.build_pack(&send)?; + + // 3. Send commands + pack. + let mut payload = Vec::new(); + pkt( + &mut payload, + format!("{old} {tip} {target}\0 report-status agent=synapse-history\n").as_bytes(), + ); + payload.extend_from_slice(b"0000"); + payload.extend_from_slice(&pack); + let mut req = agent + .post(&format!("{base}/git-receive-pack")) + .header("Content-Type", "application/x-git-receive-pack-request"); + if let Some(a) = auth { + req = req.header("Authorization", &basic(a)); + } + let mut resp = req.send(&payload).map_err(|e| push_err(e.to_string()))?; + if !resp.status().is_success() { + return Err(push_err(format!("remote answered {}", resp.status()))); + } + let body = resp + .body_mut() + .read_to_vec() + .map_err(|e| push_err(e.to_string()))?; + let mut unpack_ok = false; + for line in parse_pkts(&body)?.into_iter().flatten() { + let t = String::from_utf8_lossy(&line); + let t = t.trim_end(); + if t == "unpack ok" { + unpack_ok = true; + } else if t.starts_with("ng ") || t.starts_with("unpack ") { + return Err(push_err(format!("rejected: {t}"))); + } + } + if !unpack_ok { + return Err(push_err("remote did not confirm the push")); + } + Ok(PushReport { + objects: send.len(), + updated: true, + }) + } + + fn is_ancestor(&self, ancestor: ObjectId, mut cur: ObjectId) -> Result { + loop { + if cur == ancestor { + return Ok(true); + } + match self.repo.parent(cur)? { + Some(p) => cur = p, + None => return Ok(false), + } + } + } + + /// Adds every object reachable from `commit` (stopping at `skip`) to `out`. + fn collect( + &self, + commit: ObjectId, + skip: &HashSet, + out: &mut HashSet, + ) -> Result<()> { + let mut cur = Some(commit); + while let Some(id) = cur { + if skip.contains(&id) || !out.insert(id) { + break; + } + let c = self + .repo + .repo + .find_object(id) + .map_err(git)? + .try_into_commit() + .map_err(git)?; + self.collect_tree(c.tree_id().map_err(git)?.detach(), skip, out)?; + cur = c.parent_ids().next().map(|p| p.detach()); + } + Ok(()) + } + + fn collect_tree( + &self, + tree: ObjectId, + skip: &HashSet, + out: &mut HashSet, + ) -> Result<()> { + if skip.contains(&tree) || !out.insert(tree) { + return Ok(()); + } + let obj = self.repo.repo.find_object(tree).map_err(git)?; + let t = obj.try_into_tree().map_err(git)?; + for e in t.decode().map_err(git)?.entries.iter() { + let oid = e.oid.to_owned(); + if e.mode.is_tree() { + self.collect_tree(oid, skip, out)?; + } else if !skip.contains(&oid) { + out.insert(oid); + } + } + Ok(()) + } + + fn build_pack(&self, objects: &HashSet) -> Result> { + let mut ids: Vec<_> = objects.iter().copied().collect(); + ids.sort(); + let mut pack = Vec::new(); + pack.extend_from_slice(b"PACK"); + pack.extend_from_slice(&2u32.to_be_bytes()); + pack.extend_from_slice(&(ids.len() as u32).to_be_bytes()); + for id in ids { + let obj = self.repo.repo.find_object(id).map_err(git)?; + let ty: u8 = match obj.kind { + gix::object::Kind::Commit => 1, + gix::object::Kind::Tree => 2, + gix::object::Kind::Blob => 3, + gix::object::Kind::Tag => 4, + }; + let mut size = obj.data.len(); + let mut first = (ty << 4) | (size & 0x0f) as u8; + size >>= 4; + if size > 0 { + first |= 0x80; + } + pack.push(first); + while size > 0 { + let mut b = (size & 0x7f) as u8; + size >>= 7; + if size > 0 { + b |= 0x80; + } + pack.push(b); + } + let mut z = flate2::write::ZlibEncoder::new(Vec::new(), flate2::Compression::default()); + z.write_all(&obj.data)?; + pack.extend_from_slice(&z.finish()?); + } + let mut h = gix::hash::hasher(gix::hash::Kind::Sha1); + h.update(&pack); + let digest = h.try_finalize().map_err(git)?; + pack.extend_from_slice(digest.as_bytes()); + Ok(pack) + } +} diff --git a/crates/synapse-history/src/repo.rs b/crates/synapse-history/src/repo.rs new file mode 100644 index 0000000..ccd4a7a --- /dev/null +++ b/crates/synapse-history/src/repo.rs @@ -0,0 +1,182 @@ +//! Thin wrapper over a bare gix repository: whole-tree commits from a `path → blob` map. + +use crate::Result; +use crate::error::git; +use gix::ObjectId; +use gix::objs::{Tree, tree}; +use std::collections::BTreeMap; +use std::path::Path; + +pub const BRANCH: &str = "refs/heads/main"; + +pub type Files = BTreeMap; + +#[derive(Debug, Clone)] +pub struct CommitInfo { + pub id: String, + /// Seconds since epoch. + pub time: i64, + pub message: String, +} + +pub struct Repo { + pub(crate) repo: gix::Repository, +} + +impl Repo { + pub fn open_or_init(dir: &Path) -> Result { + let repo = if dir.join("HEAD").exists() { + gix::open(dir).map_err(git)? + } else { + std::fs::create_dir_all(dir)?; + let repo = gix::init_bare(dir).map_err(git)?; + std::fs::write(dir.join("HEAD"), format!("ref: {BRANCH}\n"))?; + repo + }; + Ok(Self { repo }) + } + + pub fn head(&self) -> Result> { + self.repo + .try_find_reference(BRANCH) + .map_err(git)? + .map(|mut r| r.peel_to_id().map(|i| i.detach())) + .transpose() + .map_err(git) + } + + /// All files of a commit's tree, as `path → blob id`. + pub fn files(&self, commit: ObjectId) -> Result { + let c = self + .repo + .find_object(commit) + .map_err(git)? + .try_into_commit() + .map_err(git)?; + let mut out = Files::new(); + self.walk(c.tree_id().map_err(git)?.detach(), "", &mut out)?; + Ok(out) + } + + fn walk(&self, tree: ObjectId, prefix: &str, out: &mut Files) -> Result<()> { + let obj = self.repo.find_object(tree).map_err(git)?; + let t = obj.try_into_tree().map_err(git)?; + let decoded = t.decode().map_err(git)?; + for e in decoded.entries.iter() { + let name = format!("{prefix}{}", e.filename); + if e.mode.is_tree() { + self.walk(e.oid.to_owned(), &format!("{name}/"), out)?; + } else { + out.insert(name, e.oid.to_owned()); + } + } + Ok(()) + } + + pub fn write_blob(&self, bytes: &[u8]) -> Result { + Ok(self.repo.write_blob(bytes).map_err(git)?.detach()) + } + + pub fn read_blob(&self, id: ObjectId) -> Result> { + Ok(self.repo.find_object(id).map_err(git)?.detach().data) + } + + fn write_tree(&self, files: &Files, dir: &str) -> Result { + let mut entries = Vec::new(); + let mut subdirs: BTreeMap<&str, ()> = BTreeMap::new(); + for (path, oid) in files.range(dir.to_string()..) { + let Some(rest) = path.strip_prefix(dir) else { + break; + }; + match rest.split_once('/') { + None => entries.push(tree::Entry { + mode: tree::EntryKind::Blob.into(), + filename: rest.into(), + oid: *oid, + }), + Some((d, _)) => { + subdirs.insert(d, ()); + } + } + } + for d in subdirs.keys() { + let oid = self.write_tree(files, &format!("{dir}{d}/"))?; + entries.push(tree::Entry { + mode: tree::EntryKind::Tree.into(), + filename: (*d).into(), + oid, + }); + } + entries.sort(); + Ok(self + .repo + .write_object(Tree { entries }) + .map_err(git)? + .detach()) + } + + /// Commits the full file set on top of the current branch tip. `time` is epoch seconds. + pub fn commit(&self, files: &Files, message: &str, time: i64) -> Result { + let tree = self.write_tree(files, "")?; + let parents: Vec = self.head()?.into_iter().collect(); + let stamp = format!("{time} +0000"); + let sig = gix::actor::SignatureRef { + name: "Synapse".into(), + email: "synapse@localhost".into(), + time: &stamp, + }; + Ok(self + .repo + .commit_as(sig, sig, BRANCH, message, tree, parents) + .map_err(git)? + .detach()) + } + + pub fn commit_info(&self, id: ObjectId) -> Result { + let c = self + .repo + .find_object(id) + .map_err(git)? + .try_into_commit() + .map_err(git)?; + Ok(CommitInfo { + id: id.to_string(), + time: c.time().map_err(git)?.seconds, + message: c.message_raw_sloppy().to_string(), + }) + } + + /// Commits from the branch tip backwards (newest first). + pub fn log(&self, limit: usize) -> Result> { + let mut out = Vec::new(); + let mut cur = self.head()?; + while let Some(id) = cur { + if out.len() >= limit { + break; + } + let c = self + .repo + .find_object(id) + .map_err(git)? + .try_into_commit() + .map_err(git)?; + cur = c.parent_ids().next().map(|p| p.detach()); + out.push(self.commit_info(id)?); + } + Ok(out) + } + + pub fn parent(&self, id: ObjectId) -> Result> { + let c = self + .repo + .find_object(id) + .map_err(git)? + .try_into_commit() + .map_err(git)?; + Ok(c.parent_ids().next().map(|p| p.detach())) + } + + pub fn parse_id(s: &str) -> Result { + ObjectId::from_hex(s.as_bytes()).map_err(git) + } +} diff --git a/crates/synapse-history/src/restore.rs b/crates/synapse-history/src/restore.rs new file mode 100644 index 0000000..5b15fb2 --- /dev/null +++ b/crates/synapse-history/src/restore.rs @@ -0,0 +1,264 @@ +//! Restore pages (or the whole graph) from a snapshot by re-importing the Markdown through the +//! `Graph` API. Restoring appends new ops; git history is never rewritten. + +use crate::Result; +use crate::export; +use crate::history::{History, SnapshotInfo}; +use crate::parse::{ParsedPage, parse_page}; +use std::collections::{HashMap, HashSet}; +use synapse_core::position::between; +use synapse_core::{Block, BlockId, Graph, NewPage, Page, new_id}; + +#[derive(Debug, Clone, Default, PartialEq, Eq)] +pub struct RestoreReport { + /// Pages whose content was (re)written from the snapshot. + pub restored: usize, + /// Pages removed because they did not exist in the snapshot. + pub removed: usize, + /// Snapshot of the pre-restore state, taken so the restore itself is undoable. + pub safety_snapshot: Option, +} + +struct Plan { + blocks: Vec, + delete: Vec, +} + +fn find_or_create(graph: &Graph, title: &str) -> Result { + if let Ok(d) = chrono::NaiveDate::parse_from_str(title, "%Y-%m-%d") { + return Ok(graph.journal(d)?); + } + match graph.page_by_title(title)? { + Some(p) => Ok(p), + None => Ok(graph.create_page(NewPage::titled(title))?), + } +} + +/// Matches parsed blocks to existing ones and decides what to write and delete. +fn plan(graph: &Graph, title: &str, parsed: &ParsedPage, steal: bool) -> Result { + let page = find_or_create(graph, title)?; + let now = graph.now_ms(); + + if page.properties != parsed.properties { + graph.set_page_properties(page.id, parsed.properties.clone())?; + } + let current: HashSet = graph.aliases_of(page.id)?.into_iter().collect(); + let wanted: HashSet = parsed.aliases.iter().cloned().collect(); + for a in current.difference(&wanted) { + graph.set_alias(a, None)?; + } + for a in wanted.difference(¤t) { + graph.set_alias(a, Some(page.id))?; + } + + let existing: Vec = graph + .page_tree(page.id)? + .into_iter() + .map(|(_, b)| b) + .collect(); + let by_id: HashMap = existing.iter().map(|b| (b.id, b)).collect(); + let mut claimed: HashSet = HashSet::new(); + let mut ids: Vec> = vec![None; parsed.blocks.len()]; + + for (i, pb) in parsed.blocks.iter().enumerate() { + let Some(id) = pb.id else { continue }; + let usable = by_id.contains_key(&id) + || match graph.get_block(id)? { + None => true, + Some(_) => steal, + }; + if usable && claimed.insert(id) { + ids[i] = Some(id); + } + } + for (i, pb) in parsed.blocks.iter().enumerate() { + if ids[i].is_some() { + continue; + } + let hit = existing + .iter() + .find(|b| !claimed.contains(&b.id) && b.content == pb.content); + let id = hit.map(|b| b.id).unwrap_or_else(new_id); + claimed.insert(id); + ids[i] = Some(id); + } + + // Build the tree: parents from depth, positions kept when still ordered. + let mut blocks: Vec = Vec::with_capacity(parsed.blocks.len()); + let mut stack: Vec = Vec::new(); + let mut last_pos: HashMap, String> = HashMap::new(); + for (i, pb) in parsed.blocks.iter().enumerate() { + let id = ids[i].unwrap(); + stack.truncate(pb.depth); + let parent = stack.last().copied(); + let prev = last_pos.get(&parent).cloned(); + let old = by_id.get(&id); + let keep = old + .filter(|o| { + o.parent_id == parent && prev.as_deref().is_none_or(|p| o.position.as_str() > p) + }) + .map(|o| o.position.clone()); + let position = keep.unwrap_or_else(|| between(prev.as_deref(), None)); + last_pos.insert(parent, position.clone()); + blocks.push(Block { + id, + page_id: page.id, + parent_id: parent, + position, + content: pb.content.clone(), + properties: pb.properties.clone(), + collapsed: pb.collapsed, + created_at: old.map_or(now, |o| o.created_at), + updated_at: now, + }); + stack.push(id); + } + let delete = existing + .iter() + .filter(|b| !claimed.contains(&b.id)) + .map(|b| b.id) + .collect(); + Ok(Plan { blocks, delete }) +} + +fn same(a: &Block, b: &Block) -> bool { + a.page_id == b.page_id + && a.parent_id == b.parent_id + && a.position == b.position + && a.content == b.content + && a.properties == b.properties + && a.collapsed == b.collapsed +} + +fn apply_deletes(graph: &Graph, plan: &Plan) -> Result<()> { + for id in &plan.delete { + // Deleting a parent already removed its subtree. + if graph.get_block(*id)?.is_some() { + graph.delete_block(*id)?; + } + } + Ok(()) +} + +/// Writes changed blocks; returns whether anything was written. +fn apply_puts(graph: &Graph, plan: &Plan) -> Result { + let mut wrote = false; + for b in &plan.blocks { + if graph.get_block(b.id)?.is_some_and(|cur| same(&cur, b)) { + continue; + } + graph.put_block(b)?; + wrote = true; + } + Ok(wrote || !plan.delete.is_empty()) +} + +fn clear_or_delete(graph: &Graph, page: &Page) -> Result { + if page.is_journal() { + let roots: Vec<_> = graph + .page_tree(page.id)? + .into_iter() + .filter(|(d, _)| *d == 0) + .map(|(_, b)| b.id) + .collect(); + let had = !roots.is_empty(); + for id in roots { + graph.delete_block(id)?; + } + Ok(had) + } else { + graph.delete_page(page.id)?; + Ok(true) + } +} + +impl History { + /// Restores one page to its state at `rev`. A page that did not exist then is removed + /// (a journal is emptied instead). + pub fn restore_page( + &mut self, + graph: &Graph, + title: &str, + rev: &str, + now_ms: i64, + ) -> Result { + let commit = self.resolve(rev)?; + let text = self.file_at(commit, &Self::path_for_title(title))?; + let safety = self.snapshot(graph, now_ms)?; + let mut report = RestoreReport { + safety_snapshot: safety, + ..Default::default() + }; + match text { + Some(text) => { + let p = plan(graph, title, &parse_page(&text), false)?; + apply_deletes(graph, &p)?; + apply_puts(graph, &p)?; + report.restored = 1; + } + None => { + let page = graph + .page_by_title(title)? + .ok_or_else(|| Self::not_found(title))?; + if clear_or_delete(graph, &page)? { + report.removed = 1; + } + } + } + Ok(report) + } + + /// Restores every page to its state at `rev`; pages created since are removed. + pub fn restore_graph( + &mut self, + graph: &Graph, + rev: &str, + now_ms: i64, + ) -> Result { + let files = self.snapshot_files(rev)?; + let safety = self.snapshot(graph, now_ms)?; + let mut report = RestoreReport { + safety_snapshot: safety, + ..Default::default() + }; + let mut plans = Vec::new(); + let mut wanted: HashSet = HashSet::new(); + for (path, oid) in &files { + let Some(title) = export::title_from_path(path) else { + continue; + }; + wanted.insert(synapse_core::title_key(&title)); + let text = self.read_blob(*oid)?; + plans.push(plan(graph, &title, &parse_page(&text), true)?); + } + // Delete first so blocks moved between pages can be re-created where they belong. + for p in &plans { + apply_deletes(graph, p)?; + } + for p in &plans { + if apply_puts(graph, p)? { + report.restored += 1; + } + } + let mut offset = 0; + let mut extra = Vec::new(); + loop { + let batch = graph.list_pages(true, 500, offset)?; + if batch.is_empty() { + break; + } + offset += batch.len() as u32; + extra.extend( + batch + .into_iter() + .filter(|p| !wanted.contains(&synapse_core::title_key(&p.title))), + ); + } + for page in extra { + if clear_or_delete(graph, &page)? { + report.removed += 1; + } + } + Ok(report) + } +} diff --git a/crates/synapse-history/tests/history.rs b/crates/synapse-history/tests/history.rs new file mode 100644 index 0000000..54e66f7 --- /dev/null +++ b/crates/synapse-history/tests/history.rs @@ -0,0 +1,299 @@ +use std::time::Duration; +use synapse_core::{Graph, NewPage, Placement}; +use synapse_history::{History, HistoryOptions, SnapshotPolicy, export}; + +const T0: i64 = 1_700_000_000_000; + +fn setup() -> (tempfile::TempDir, Graph, History) { + let dir = tempfile::tempdir().unwrap(); + let g = Graph::open(dir.path()).unwrap(); + g.set_now(Some(T0)); + let h = History::open(dir.path(), HistoryOptions::default()).unwrap(); + (dir, g, h) +} + +fn add(g: &Graph, title: &str, blocks: &[&str]) -> synapse_core::Page { + let p = g.ensure_page(title, None).unwrap(); + for b in blocks { + g.insert_block(p.id, Placement::LastChildOf(None), b) + .unwrap(); + } + p +} + +fn at(g: &Graph, ms: i64) { + g.set_now(Some(ms)); +} + +#[test] +fn export_is_deterministic_and_logseq_shaped() { + let (_d, g, _h) = setup(); + let p = add(&g, "Project/Alpha", &["first", "second"]); + let first = g.page_tree(p.id).unwrap()[0].1.clone(); + g.insert_block(p.id, Placement::LastChildOf(Some(first.id)), "child\nmore") + .unwrap(); + let t = add(&g, "Target", &["target block"]); + let tb = g.page_tree(t.id).unwrap()[0].1.id; + g.insert_block(p.id, Placement::LastChildOf(None), &format!("see (({tb}))")) + .unwrap(); + g.set_alias("Alpha", Some(p.id)).unwrap(); + let refs = export::referenced_blocks(g.conn()).unwrap(); + assert!(refs.contains(&tb)); + + let a = export::render_page(&g, &p, &refs).unwrap(); + let b = export::render_page(&g, &p, &refs).unwrap(); + assert_eq!(a, b); + assert!( + a.starts_with("alias:: Alpha\n\n- first\n\t- child\n\t more\n- second\n"), + "{a}" + ); + let tt = export::render_page(&g, &g.get_page(t.id).unwrap().unwrap(), &refs).unwrap(); + assert!(tt.contains(&format!("id:: {tb}")), "{tt}"); + assert_eq!(export::page_path(&p), "pages/Project___Alpha.md"); +} + +#[test] +fn incremental_snapshot_only_rewrites_touched_pages() { + let (_d, g, mut h) = setup(); + add(&g, "A", &["a1"]); + add(&g, "B", &["b1"]); + let s1 = h.snapshot(&g, T0).unwrap().unwrap(); + assert!(s1.summary.contains("created"), "{}", s1.summary); + assert!( + h.snapshot(&g, T0 + 1000).unwrap().is_none(), + "nothing changed" + ); + + at(&g, T0 + 10_000); + let a = g.page_by_title("A").unwrap().unwrap(); + g.insert_block(a.id, Placement::LastChildOf(None), "a2") + .unwrap(); + let s2 = h.snapshot(&g, T0 + 20_000).unwrap().unwrap(); + assert_eq!(s2.summary, "1 page edited: A"); + // B's blob is unchanged between snapshots. + assert_eq!( + h.page_at(&s1.id, "B").unwrap(), + h.page_at(&s2.id, "B").unwrap() + ); + assert_eq!(h.snapshots(10).unwrap().len(), 2); + + // Deleting a block (no page op) is still noticed. + at(&g, T0 + 30_000); + let b = g.page_by_title("B").unwrap().unwrap(); + let blk = g.page_tree(b.id).unwrap()[0].1.id; + g.delete_block(blk).unwrap(); + let s3 = h.snapshot(&g, T0 + 40_000).unwrap().unwrap(); + assert_eq!(s3.summary, "1 page edited: B"); + assert_eq!(h.page_at(&s3.id, "B").unwrap().unwrap(), ""); + + // Deleting and renaming pages updates the tree. + at(&g, T0 + 50_000); + g.rename_page(a.id, "A2").unwrap(); + g.delete_page(b.id).unwrap(); + let s4 = h.snapshot(&g, T0 + 60_000).unwrap().unwrap(); + assert!(s4.summary.contains("2 deleted"), "{}", s4.summary); + assert!(h.page_at(&s4.id, "A").unwrap().is_none()); + assert!(h.page_at(&s4.id, "A2").unwrap().unwrap().contains("a2")); +} + +#[test] +fn incremental_equals_full_export() { + let (_d, g, mut h) = setup(); + let a = add(&g, "A", &["a1"]); + let t = add(&g, "T", &["t1"]); + h.snapshot(&g, T0).unwrap(); + at(&g, T0 + 1000); + let tb = g.page_tree(t.id).unwrap()[0].1.id; + g.insert_block(a.id, Placement::LastChildOf(None), &format!("(({tb}))")) + .unwrap(); + let s = h.snapshot(&g, T0 + 2000).unwrap().unwrap(); + // Page T (untouched by ops) gained an `id::` because it is now referenced. + assert!( + h.page_at(&s.id, "T") + .unwrap() + .unwrap() + .contains(&format!("id:: {tb}")) + ); + + // A fresh history over the same graph produces identical files. + let dir2 = tempfile::tempdir().unwrap(); + let mut h2 = History::open_at(dir2.path(), HistoryOptions::default()).unwrap(); + let s2 = h2.snapshot(&g, T0 + 2000).unwrap().unwrap(); + for title in ["A", "T"] { + assert_eq!( + h.page_at("HEAD", title).unwrap(), + h2.page_at(&s2.id, title).unwrap() + ); + } +} + +#[test] +fn policy_controls_maybe_snapshot() { + let dir = tempfile::tempdir().unwrap(); + let g = Graph::open(dir.path()).unwrap(); + g.set_now(Some(T0)); + let opts = HistoryOptions { + policy: SnapshotPolicy { + min_interval: Duration::from_secs(60), + max_interval: Duration::from_secs(600), + on_idle: Some(Duration::from_secs(30)), + }, + include_blobs: false, + }; + let mut h = History::open(dir.path(), opts).unwrap(); + add(&g, "A", &["x"]); + let first = h.maybe_snapshot(&g, T0).unwrap(); + assert!(first.is_some(), "first snapshot is immediate"); + + let a = g.page_by_title("A").unwrap().unwrap(); + g.insert_block(a.id, Placement::LastChildOf(None), "y") + .unwrap(); + // Too soon (min_interval). + assert!(h.maybe_snapshot(&g, T0 + 10_000).unwrap().is_none()); + // Past min_interval and idle for 60s (>= 30s) since the change was first observed. + assert!(h.maybe_snapshot(&g, T0 + 70_000).unwrap().is_some()); + assert!( + h.maybe_snapshot(&g, T0 + 80_000).unwrap().is_none(), + "nothing pending" + ); + + // Continuous editing still snapshots at max_interval. + for i in 0..30 { + g.insert_block(a.id, Placement::LastChildOf(None), "z") + .unwrap(); + let t = T0 + 120_000 + i * 20_000; + let r = h.maybe_snapshot(&g, t).unwrap(); + if r.is_some() { + assert!(t - (T0 + 70_000) >= 600_000); + return; + } + } + panic!("max_interval never fired"); +} + +#[test] +fn page_history_and_diff() { + let (_d, g, mut h) = setup(); + let p = add(&g, "Notes", &["one"]); + let s1 = h.snapshot(&g, T0).unwrap().unwrap(); + add(&g, "Other", &["noise"]); + h.snapshot(&g, T0 + 1000).unwrap(); + at(&g, T0 + 5000); + g.insert_block(p.id, Placement::LastChildOf(None), "two") + .unwrap(); + let s3 = h.snapshot(&g, T0 + 6000).unwrap().unwrap(); + + let versions = h.page_history("Notes").unwrap(); + assert_eq!(versions.len(), 2, "only snapshots that changed the page"); + assert_eq!(versions[0].snapshot.id, s3.id); + assert_eq!(versions[1].snapshot.id, s1.id); + let d = h.diff_page("Notes", &s1.id, &s3.id).unwrap(); + assert!(d.contains("+- two"), "{d}"); + assert!(!d.contains("noise")); + // Abbreviated ids work. + assert_eq!(h.page_at(&s1.id[..8], "Notes").unwrap().unwrap(), "- one\n"); +} + +#[test] +fn restore_page_and_graph_keep_block_ids_and_never_rewrite_history() { + let (_d, g, mut h) = setup(); + let p = add(&g, "Doc", &["keep me", "will change"]); + let tree = g.page_tree(p.id).unwrap(); + let (keep, change) = (tree[0].1.id, tree[1].1.id); + let other = add(&g, "Gone", &["bye"]); + let s1 = h.snapshot(&g, T0).unwrap().unwrap(); + let n_snaps = h.snapshots(100).unwrap().len(); + + at(&g, T0 + 1000); + g.update_block(change, "changed!").unwrap(); + g.insert_block(p.id, Placement::LastChildOf(Some(keep)), "extra child") + .unwrap(); + g.delete_page(other.id).unwrap(); + add(&g, "New page", &["fresh"]); + + let r = h.restore_page(&g, "Doc", &s1.id, T0 + 2000).unwrap(); + assert_eq!(r.restored, 1); + assert!(r.safety_snapshot.is_some()); + let texts: Vec<_> = g + .page_tree(p.id) + .unwrap() + .into_iter() + .map(|(d, b)| (d, b.content, b.id)) + .collect(); + assert_eq!(texts.len(), 2); + assert_eq!(texts[0].1, "keep me"); + assert_eq!(texts[0].2, keep, "unchanged block keeps its id"); + assert_eq!(texts[1].1, "will change"); + // History only grew. + assert!(h.snapshots(100).unwrap().len() > n_snaps); + + // Whole graph: deleted page returns, new page disappears. + let r = h.restore_graph(&g, &s1.id, T0 + 3000).unwrap(); + assert!(r.removed >= 1); + let gone = g.page_by_title("Gone").unwrap().expect("page restored"); + assert_eq!(g.page_tree(gone.id).unwrap()[0].1.content, "bye"); + assert!(g.page_by_title("New page").unwrap().is_none()); + + // After restoring, the next snapshot has the same page content as s1. + let s = h + .snapshot(&g, T0 + 4000) + .unwrap() + .unwrap_or_else(|| h.snapshots(1).unwrap().remove(0)); + assert_eq!( + h.page_at(&s.id, "Doc").unwrap(), + h.page_at(&s1.id, "Doc").unwrap() + ); + assert_eq!( + h.page_at(&s.id, "Gone").unwrap(), + h.page_at(&s1.id, "Gone").unwrap() + ); +} + +#[test] +fn restore_preserves_referenced_block_ids_and_aliases() { + let (_d, g, mut h) = setup(); + let t = add(&g, "Target", &["answer"]); + let tb = g.page_tree(t.id).unwrap()[0].1.id; + let r = add(&g, "Ref", &[&format!("(({tb}))")]); + g.set_alias("Tgt", Some(t.id)).unwrap(); + g.set_page_properties( + t.id, + serde_json::from_str(r#"{"type":"note","n":3,"done":true,"s":"true"}"#).unwrap(), + ) + .unwrap(); + let s1 = h.snapshot(&g, T0).unwrap().unwrap(); + at(&g, T0 + 10); + g.delete_block(tb).unwrap(); + g.set_alias("Tgt", None).unwrap(); + g.set_page_properties(t.id, Default::default()).unwrap(); + h.restore_page(&g, "Target", &s1.id, T0 + 20).unwrap(); + assert_eq!(g.get_block(tb).unwrap().unwrap().content, "answer"); + assert_eq!(g.aliases_of(t.id).unwrap(), ["Tgt"]); + let props = g.get_page(t.id).unwrap().unwrap().properties; + assert_eq!(props["n"], 3); + assert_eq!(props["done"], true); + assert_eq!(props["s"], "true"); + assert_eq!(g.block_backrefs(tb).unwrap()[0].page_id, r.id); +} + +#[test] +fn journals_and_assets() { + let (dir, g, mut h) = setup(); + let day = chrono::NaiveDate::from_ymd_opt(2024, 3, 9).unwrap(); + let j = g.journal(day).unwrap(); + g.insert_block(j.id, Placement::LastChildOf(None), "met [[Someone]]") + .unwrap(); + let src = dir.path().join("pic.png"); + std::fs::write(&src, b"not really a png").unwrap(); + let asset = g.put_asset_file(&src, Some("image/png")).unwrap(); + let s = h.snapshot(&g, T0).unwrap().unwrap(); + assert!( + h.page_at(&s.id, "2024-03-09") + .unwrap() + .unwrap() + .contains("met [[Someone]]") + ); + let files = h.file(&s.id, "assets.json").unwrap().unwrap(); + assert!(files.contains(&asset.hash) && files.contains("image/png")); + let _ = NewPage::default(); +} diff --git a/crates/synapse-history/tests/push.rs b/crates/synapse-history/tests/push.rs new file mode 100644 index 0000000..c3a4bcf --- /dev/null +++ b/crates/synapse-history/tests/push.rs @@ -0,0 +1,140 @@ +//! Pushes to a real `git receive-pack` behind a tiny smart-HTTP shim. + +use std::io::{BufRead, BufReader, Read, Write}; +use std::net::TcpListener; +use std::path::Path; +use std::process::{Command, Stdio}; +use synapse_core::{Graph, Placement}; +use synapse_history::{History, HistoryOptions, PushAuth}; + +fn git(dir: &Path, args: &[&str]) -> String { + let out = Command::new("git") + .arg("-C") + .arg(dir) + .args(args) + .output() + .unwrap(); + assert!( + out.status.success(), + "{args:?}: {}", + String::from_utf8_lossy(&out.stderr) + ); + String::from_utf8_lossy(&out.stdout).into_owned() +} + +fn serve( + remote: std::path::PathBuf, + requests: usize, +) -> (String, std::thread::JoinHandle>) { + let listener = TcpListener::bind("127.0.0.1:0").unwrap(); + let url = format!("http://{}/repo.git", listener.local_addr().unwrap()); + let h = std::thread::spawn(move || { + let mut auths = Vec::new(); + for _ in 0..requests { + let (mut s, _) = listener.accept().unwrap(); + let mut r = BufReader::new(s.try_clone().unwrap()); + let mut line = String::new(); + r.read_line(&mut line).unwrap(); + let is_get = line.starts_with("GET"); + let mut len = 0usize; + loop { + let mut h = String::new(); + r.read_line(&mut h).unwrap(); + let h = h.trim_end().to_string(); + if h.is_empty() { + break; + } + let lower = h.to_lowercase(); + if let Some(v) = lower.strip_prefix("content-length:") { + len = v.trim().parse().unwrap(); + } + if lower.starts_with("authorization:") { + auths.push(h.clone()); + } + } + let mut body = vec![0; len]; + r.read_exact(&mut body).unwrap(); + let mut cmd = Command::new("git"); + cmd.arg("receive-pack").arg("--stateless-rpc"); + if is_get { + cmd.arg("--advertise-refs"); + } + let mut child = cmd + .arg(&remote) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn() + .unwrap(); + child.stdin.take().unwrap().write_all(&body).unwrap(); + let out = child.wait_with_output().unwrap().stdout; + let mut payload = Vec::new(); + let ct = if is_get { + payload.extend_from_slice(b"001f# service=git-receive-pack\n0000"); + "application/x-git-receive-pack-advertisement" + } else { + "application/x-git-receive-pack-result" + }; + payload.extend_from_slice(&out); + write!(s, "HTTP/1.1 200 OK\r\nContent-Type: {ct}\r\nContent-Length: {}\r\nConnection: close\r\n\r\n", payload.len()).unwrap(); + s.write_all(&payload).unwrap(); + } + auths + }); + (url, h) +} + +#[test] +fn push_incrementally_to_a_real_git_remote() { + if Command::new("git").arg("--version").output().is_err() { + eprintln!("git not installed, skipping"); + return; + } + let dir = tempfile::tempdir().unwrap(); + let g = Graph::open(dir.path()).unwrap(); + g.set_now(Some(1_700_000_000_000)); + let mut h = History::open(dir.path(), HistoryOptions::default()).unwrap(); + let p = g.ensure_page("Pushed", None).unwrap(); + g.insert_block(p.id, Placement::LastChildOf(None), "hello remote") + .unwrap(); + h.snapshot(&g, 1_700_000_000_000).unwrap(); + + let remote = tempfile::tempdir().unwrap(); + git(remote.path(), &["init", "--bare", "-q", "."]); + let auth = PushAuth { + username: "u".into(), + secret: "tok".into(), + }; + + let (url, srv) = serve(remote.path().into(), 2); + let r = h.push(&url, "main", Some(&auth), false).unwrap(); + assert!(r.updated && r.objects > 3); + assert_eq!( + git(remote.path(), &["show", "main:pages/Pushed.md"]), + "- hello remote\n" + ); + git(remote.path(), &["fsck", "--strict"]); + let auths = srv.join().unwrap(); + assert!( + auths.iter().all(|a| a.contains("Basic dTp0b2s=")), + "{auths:?}" + ); + + // Second push: new snapshot only sends the delta; unchanged tip is a no-op. + g.set_now(Some(1_700_000_100_000)); + g.insert_block(p.id, Placement::LastChildOf(None), "more") + .unwrap(); + h.snapshot(&g, 1_700_000_100_000).unwrap(); + let (url, srv) = serve(remote.path().into(), 2); + let r = h.push(&url, "main", Some(&auth), false).unwrap(); + assert!(r.updated && r.objects < 8, "{r:?}"); + srv.join().unwrap(); + assert_eq!( + git(remote.path(), &["rev-list", "--count", "main"]).trim(), + "2" + ); + git(remote.path(), &["fsck", "--strict"]); + + let (url, srv) = serve(remote.path().into(), 1); + assert!(!h.push(&url, "main", Some(&auth), false).unwrap().updated); + srv.join().unwrap(); +} diff --git a/docs/history.md b/docs/history.md new file mode 100644 index 0000000..0656be2 --- /dev/null +++ b/docs/history.md @@ -0,0 +1,52 @@ +# History (`synapse-history`) + +Automatic git-like backup of a graph. A bare git repository at `/history/` holds a +deterministic, Logseq-compatible Markdown export; every snapshot is a commit. Plain `git` +works on it (`git --git-dir=/history log`, `clone`, ...). + +## Export format +- `pages/.md`: title encoded Logseq-style (`/` → `___`, `% < > : " \ | ? *` and control + chars percent-encoded). `journals/YYYY_MM_DD.md` for journals. +- File = page properties (`key:: value`, aliases as `alias:: a, b`), then one `- ` bullet per + block, nested with tabs; extra content lines and block properties are indented under the + bullet. Blocks targeted by `((uuid))` get an `id::` property. `collapsed:: true` is kept. +- Property values: raw text, or JSON when the value is not a plain string (so numbers/bools + survive a restore). Keys are sorted, so output is byte-stable. +- `assets.json`: manifest `hash → name/size/mime`, sorted. Asset bytes are **not** committed + (the blob store is already content-addressed) unless `HistoryOptions::include_blobs`, which + adds `blobs/<hash>`. + +## Snapshots +`History::snapshot(&graph, now_ms)` is incremental: it reads `ops_since(last_seq)` plus a scan +of pages whose `updated_at` moved (block deletes/moves do not log their page), rewrites only +those files and removes files of deleted/renamed pages. State (`last_seq`, referenced block +ids) lives in `history/synapse-history.json`; if it is missing or ahead of the graph a full +export is done (unchanged files still hash to the same blobs, so the commit stays small). +Commit messages look like `3 pages edited, 1 created: A, B, C` and end with `Synapse-Seq: n`. + +`maybe_snapshot(&graph, now_ms)` is for the app's periodic timer, driven by `SnapshotPolicy`: +`min_interval` (floor between snapshots), `max_interval` (ceiling when changes are pending), +`on_idle` (snapshot after the graph has been quiet that long). + +## Queries and restore +`snapshots(limit)`, `page_history(title)` (snapshots that changed the page), `page_at`, `file`, +`diff_page(title, from, to)` (unified diff). Revisions are commit ids, abbreviations or `HEAD`. + +`restore_page` / `restore_graph` re-import the Markdown through the `Graph` API and so append +new ops; git history is never rewritten. They take a safety snapshot first. Blocks keep their +ids (`id::`, or matched by identical content) so references survive; pages absent from the +snapshot are deleted (journals are emptied). + +## Push +`History::push(url, branch, Some(&PushAuth{..}), force)` pushes to any `http(s)` Git remote +with a pure-Rust smart-HTTP implementation (gix cannot push yet). Credentials are used for the +request only and never stored. SSH remotes are not supported. + +## Why gix +gix is pure Rust: no C toolchain or OpenSSL/libssh needed for Android and Windows builds. +Fallback if gix ever blocks us: libgit2 via `git2` with vendored libgit2. + +## Known limits +- Block content lines that look like `key:: value` at the end of a block read back as block + properties on restore. +- Alias changes trigger a full re-export (the previous owner of an alias is not logged).