From 4f22cf66e38aeab1949629320c1e65a89dc333bd Mon Sep 17 00:00:00 2001 From: Scott Lamb Date: Wed, 27 Oct 2021 10:17:41 -0700 Subject: [PATCH] switch from prettydiff to diff prettydiff has a weird chain of dependencies starting with prettytable-rs and ending up with (among other things) argon2rs. --- server/Cargo.lock | 164 ++++----------------------------------- server/db/Cargo.toml | 3 +- server/db/compare.rs | 58 +++++++++----- server/db/upgrade/mod.rs | 7 +- 4 files changed, 61 insertions(+), 171 deletions(-) diff --git a/server/Cargo.lock b/server/Cargo.lock index e76eef7..3edc87f 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -23,7 +23,7 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "796540673305a66d127804eef19ad696f1f204b8c1025aaca4958c17eab32877" dependencies = [ - "getrandom 0.2.3", + "getrandom", "once_cell", "version_check", ] @@ -34,7 +34,7 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ - "getrandom 0.2.3", + "getrandom", "once_cell", "version_check", ] @@ -79,12 +79,6 @@ dependencies = [ "nodrop", ] -[[package]] -name = "arrayvec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" - [[package]] name = "arrayvec" version = "0.7.1" @@ -143,7 +137,7 @@ checksum = "a4d0faafe9e089674fc3efdb311ff5253d445c79d85d1d28bd3ace76d45e7164" dependencies = [ "base64", "blowfish", - "getrandom 0.2.3", + "getrandom", ] [[package]] @@ -171,17 +165,6 @@ dependencies = [ "constant_time_eq", ] -[[package]] -name = "blake2b_simd" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" -dependencies = [ - "arrayref", - "arrayvec 0.5.2", - "constant_time_eq", -] - [[package]] name = "blake3" version = "1.1.0" @@ -225,7 +208,6 @@ dependencies = [ "lazy_static", "memchr", "regex-automata", - "serde", ] [[package]] @@ -373,28 +355,6 @@ dependencies = [ "quote", ] -[[package]] -name = "csv" -version = "1.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1" -dependencies = [ - "bstr", - "csv-core", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "csv-core" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" -dependencies = [ - "memchr", -] - [[package]] name = "cursive" version = "0.16.3" @@ -480,6 +440,12 @@ version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" +[[package]] +name = "diff" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499" + [[package]] name = "digest" version = "0.9.0" @@ -489,17 +455,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "dirs" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - [[package]] name = "dtoa" version = "0.4.8" @@ -512,12 +467,6 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" -[[package]] -name = "encode_unicode" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" - [[package]] name = "encoding_rs" version = "0.8.29" @@ -739,17 +688,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - [[package]] name = "getrandom" version = "0.2.3" @@ -758,7 +696,7 @@ checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ "cfg-if", "libc", - "wasi 0.10.0+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -1187,6 +1125,7 @@ dependencies = [ "blake3", "byteorder", "cstr", + "diff", "failure", "fnv", "futures", @@ -1204,7 +1143,6 @@ dependencies = [ "odds", "parking_lot", "pretty-hex", - "prettydiff", "protobuf", "protobuf-codegen-pure", "ring", @@ -1504,7 +1442,7 @@ dependencies = [ "cfg-if", "instant", "libc", - "redox_syscall 0.2.10", + "redox_syscall", "smallvec", "winapi", ] @@ -1585,30 +1523,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5c99d529f0d30937f6f4b8a86d988047327bb88d04d2c4afc356de74722131" -[[package]] -name = "prettydiff" -version = "0.5.0" -source = "git+https://github.com/scottlamb/prettydiff?branch=pr-update-deps#66d484720e1f3c32dd3cb1806cf489b832ddd9d2" -dependencies = [ - "ansi_term", - "prettytable-rs", - "structopt", -] - -[[package]] -name = "prettytable-rs" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fd04b170004fa2daccf418a7f8253aaf033c27760b5f225889024cf66d7ac2e" -dependencies = [ - "atty", - "csv", - "encode_unicode", - "lazy_static", - "term", - "unicode-width", -] - [[package]] name = "proc-macro-error" version = "1.0.4" @@ -1716,7 +1630,7 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ - "getrandom 0.2.3", + "getrandom", ] [[package]] @@ -1743,12 +1657,6 @@ dependencies = [ "rawpointer", ] -[[package]] -name = "redox_syscall" -version = "0.1.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" - [[package]] name = "redox_syscall" version = "0.2.10" @@ -1758,17 +1666,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "redox_users" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" -dependencies = [ - "getrandom 0.1.16", - "redox_syscall 0.1.57", - "rust-argon2", -] - [[package]] name = "reffers" version = "0.6.1" @@ -1923,18 +1820,6 @@ dependencies = [ "smallvec", ] -[[package]] -name = "rust-argon2" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" -dependencies = [ - "base64", - "blake2b_simd", - "constant_time_eq", - "crossbeam-utils", -] - [[package]] name = "rustc-demangle" version = "0.1.21" @@ -2226,22 +2111,11 @@ dependencies = [ "cfg-if", "libc", "rand", - "redox_syscall 0.2.10", + "redox_syscall", "remove_dir_all", "winapi", ] -[[package]] -name = "term" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42" -dependencies = [ - "byteorder", - "dirs", - "winapi", -] - [[package]] name = "term_size" version = "0.3.2" @@ -2289,7 +2163,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ "libc", - "wasi 0.10.0+wasi-snapshot-preview1", + "wasi", "winapi", ] @@ -2526,7 +2400,7 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" dependencies = [ - "getrandom 0.2.3", + "getrandom", "serde", ] @@ -2552,12 +2426,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - [[package]] name = "wasi" version = "0.10.0+wasi-snapshot-preview1" diff --git a/server/db/Cargo.toml b/server/db/Cargo.toml index bbe0cbe..d50032c 100644 --- a/server/db/Cargo.toml +++ b/server/db/Cargo.toml @@ -18,6 +18,7 @@ base64 = "0.13.0" blake3 = "1.0.0" byteorder = "1.0" cstr = "0.2.5" +diff = "0.1.12" failure = "0.1.1" fnv = "1.0" futures = "0.3" @@ -33,12 +34,12 @@ num-rational = { version = "0.4.0", default-features = false, features = ["std"] odds = { version = "0.4.0", features = ["std-vec"] } parking_lot = { version = "0.11.1", features = [] } pretty-hex = "0.2.1" -prettydiff = { git = "https://github.com/scottlamb/prettydiff", branch = "pr-update-deps" } protobuf = "3.0.0-alpha.1" ring = "0.16.2" rusqlite = "0.26.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" +#similar = "2.1.0" smallvec = "1.0" tempfile = "3.2.0" time = "0.1" diff --git a/server/db/compare.rs b/server/db/compare.rs index ca9cfbc..97384d0 100644 --- a/server/db/compare.rs +++ b/server/db/compare.rs @@ -7,7 +7,6 @@ //! and for tests of `moonfire-nvr upgrade`. use failure::Error; -use prettydiff::diff_slice; use rusqlite::params; use std::fmt::Write; @@ -55,6 +54,35 @@ impl std::fmt::Display for IndexColumn { } } +/// If `slice1` and `slice2` differ, return differences in roughly unified diff form. +fn diff_slices( + name1: &str, + slice1: &[T], + name2: &str, + slice2: &[T], +) -> Option { + let mut diff = format!("--- {}\n+++ {}\n", name1, name2); + let mut changed = false; + for item in diff::slice(slice1, slice2) { + match item { + diff::Result::Left(i) => { + changed = true; + write!(&mut diff, "-{}\n", i) + } + diff::Result::Both(i, _) => write!(&mut diff, " {}\n", i), + diff::Result::Right(i) => { + changed = true; + write!(&mut diff, "+{}\n", i) + } + } + .unwrap(); + } + if !changed { + return None; + } + Some(diff) +} + /// Returns a sorted vec of table names in the given connection. fn get_tables(c: &rusqlite::Connection) -> Result, rusqlite::Error> { c.prepare( @@ -139,13 +167,11 @@ pub fn get_diffs( // Compare table list. let tables1 = get_tables(c1)?; let tables2 = get_tables(c2)?; - if tables1 != tables2 { + if let Some(diff) = diff_slices(n1, &tables1[..], n2, &tables2[..]) { write!( &mut diffs, "table list mismatch, {} vs {}:\n{}", - n1, - n2, - diff_slice(&tables1, &tables2) + n1, n2, diff )?; } @@ -153,14 +179,11 @@ pub fn get_diffs( for t in &tables1 { let columns1 = get_table_columns(c1, &t)?; let columns2 = get_table_columns(c2, &t)?; - if columns1 != columns2 { + if let Some(diff) = diff_slices(n1, &columns1[..], n2, &columns2[..]) { write!( &mut diffs, "table {:?} column, {} vs {}:\n{}", - t, - n1, - n2, - diff_slice(&columns1, &columns2) + t, n1, n2, diff )?; } @@ -168,29 +191,22 @@ pub fn get_diffs( let mut indices2 = get_indices(c2, &t)?; indices1.sort_by(|a, b| a.name.cmp(&b.name)); indices2.sort_by(|a, b| a.name.cmp(&b.name)); - if indices1 != indices2 { + if let Some(diff) = diff_slices(n1, &indices1[..], n2, &indices2[..]) { write!( &mut diffs, "table {:?} indices, {} vs {}:\n{}", - t, - n1, - n2, - diff_slice(&indices1, &indices2) + t, n1, n2, diff )?; } for i in &indices1 { let ic1 = get_index_columns(c1, &i.name)?; let ic2 = get_index_columns(c2, &i.name)?; - if ic1 != ic2 { + if let Some(diff) = diff_slices(n1, &ic1[..], n2, &ic2[..]) { write!( &mut diffs, "table {:?} index {:?} columns {} vs {}:\n{}", - t, - i, - n1, - n2, - diff_slice(&ic1, &ic2) + t, i, n1, n2, diff )?; } } diff --git a/server/db/upgrade/mod.rs b/server/db/upgrade/mod.rs index acf2ab4..36a0b54 100644 --- a/server/db/upgrade/mod.rs +++ b/server/db/upgrade/mod.rs @@ -190,7 +190,12 @@ mod tests { fn compare(c: &rusqlite::Connection, ver: i32, fresh_sql: &str) -> Result<(), Error> { let fresh = new_conn()?; fresh.execute_batch(fresh_sql)?; - if let Some(diffs) = compare::get_diffs("upgraded", &c, "fresh", &fresh)? { + if let Some(diffs) = compare::get_diffs( + &format!("upgraded to version {}", ver), + &c, + &format!("fresh version {}", ver), + &fresh, + )? { panic!("Version {}: differences found:\n{}", ver, diffs); } Ok(())