switch from prettydiff to diff

prettydiff has a weird chain of dependencies starting with
prettytable-rs and ending up with (among other things) argon2rs.
This commit is contained in:
Scott Lamb 2021-10-27 10:17:41 -07:00
parent 884c3333cc
commit 4f22cf66e3
4 changed files with 61 additions and 171 deletions

164
server/Cargo.lock generated
View File

@ -23,7 +23,7 @@ version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "796540673305a66d127804eef19ad696f1f204b8c1025aaca4958c17eab32877" checksum = "796540673305a66d127804eef19ad696f1f204b8c1025aaca4958c17eab32877"
dependencies = [ dependencies = [
"getrandom 0.2.3", "getrandom",
"once_cell", "once_cell",
"version_check", "version_check",
] ]
@ -34,7 +34,7 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
dependencies = [ dependencies = [
"getrandom 0.2.3", "getrandom",
"once_cell", "once_cell",
"version_check", "version_check",
] ]
@ -79,12 +79,6 @@ dependencies = [
"nodrop", "nodrop",
] ]
[[package]]
name = "arrayvec"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]] [[package]]
name = "arrayvec" name = "arrayvec"
version = "0.7.1" version = "0.7.1"
@ -143,7 +137,7 @@ checksum = "a4d0faafe9e089674fc3efdb311ff5253d445c79d85d1d28bd3ace76d45e7164"
dependencies = [ dependencies = [
"base64", "base64",
"blowfish", "blowfish",
"getrandom 0.2.3", "getrandom",
] ]
[[package]] [[package]]
@ -171,17 +165,6 @@ dependencies = [
"constant_time_eq", "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]] [[package]]
name = "blake3" name = "blake3"
version = "1.1.0" version = "1.1.0"
@ -225,7 +208,6 @@ dependencies = [
"lazy_static", "lazy_static",
"memchr", "memchr",
"regex-automata", "regex-automata",
"serde",
] ]
[[package]] [[package]]
@ -373,28 +355,6 @@ dependencies = [
"quote", "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]] [[package]]
name = "cursive" name = "cursive"
version = "0.16.3" version = "0.16.3"
@ -480,6 +440,12 @@ version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57"
[[package]]
name = "diff"
version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499"
[[package]] [[package]]
name = "digest" name = "digest"
version = "0.9.0" version = "0.9.0"
@ -489,17 +455,6 @@ dependencies = [
"generic-array", "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]] [[package]]
name = "dtoa" name = "dtoa"
version = "0.4.8" version = "0.4.8"
@ -512,12 +467,6 @@ version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "encode_unicode"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.29" version = "0.8.29"
@ -739,17 +688,6 @@ dependencies = [
"version_check", "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]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.3" version = "0.2.3"
@ -758,7 +696,7 @@ checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
"wasi 0.10.0+wasi-snapshot-preview1", "wasi",
] ]
[[package]] [[package]]
@ -1187,6 +1125,7 @@ dependencies = [
"blake3", "blake3",
"byteorder", "byteorder",
"cstr", "cstr",
"diff",
"failure", "failure",
"fnv", "fnv",
"futures", "futures",
@ -1204,7 +1143,6 @@ dependencies = [
"odds", "odds",
"parking_lot", "parking_lot",
"pretty-hex", "pretty-hex",
"prettydiff",
"protobuf", "protobuf",
"protobuf-codegen-pure", "protobuf-codegen-pure",
"ring", "ring",
@ -1504,7 +1442,7 @@ dependencies = [
"cfg-if", "cfg-if",
"instant", "instant",
"libc", "libc",
"redox_syscall 0.2.10", "redox_syscall",
"smallvec", "smallvec",
"winapi", "winapi",
] ]
@ -1585,30 +1523,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5c99d529f0d30937f6f4b8a86d988047327bb88d04d2c4afc356de74722131" 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]] [[package]]
name = "proc-macro-error" name = "proc-macro-error"
version = "1.0.4" version = "1.0.4"
@ -1716,7 +1630,7 @@ version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
dependencies = [ dependencies = [
"getrandom 0.2.3", "getrandom",
] ]
[[package]] [[package]]
@ -1743,12 +1657,6 @@ dependencies = [
"rawpointer", "rawpointer",
] ]
[[package]]
name = "redox_syscall"
version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.2.10" version = "0.2.10"
@ -1758,17 +1666,6 @@ dependencies = [
"bitflags", "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]] [[package]]
name = "reffers" name = "reffers"
version = "0.6.1" version = "0.6.1"
@ -1923,18 +1820,6 @@ dependencies = [
"smallvec", "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]] [[package]]
name = "rustc-demangle" name = "rustc-demangle"
version = "0.1.21" version = "0.1.21"
@ -2226,22 +2111,11 @@ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
"rand", "rand",
"redox_syscall 0.2.10", "redox_syscall",
"remove_dir_all", "remove_dir_all",
"winapi", "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]] [[package]]
name = "term_size" name = "term_size"
version = "0.3.2" version = "0.3.2"
@ -2289,7 +2163,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [ dependencies = [
"libc", "libc",
"wasi 0.10.0+wasi-snapshot-preview1", "wasi",
"winapi", "winapi",
] ]
@ -2526,7 +2400,7 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
dependencies = [ dependencies = [
"getrandom 0.2.3", "getrandom",
"serde", "serde",
] ]
@ -2552,12 +2426,6 @@ dependencies = [
"try-lock", "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]] [[package]]
name = "wasi" name = "wasi"
version = "0.10.0+wasi-snapshot-preview1" version = "0.10.0+wasi-snapshot-preview1"

View File

@ -18,6 +18,7 @@ base64 = "0.13.0"
blake3 = "1.0.0" blake3 = "1.0.0"
byteorder = "1.0" byteorder = "1.0"
cstr = "0.2.5" cstr = "0.2.5"
diff = "0.1.12"
failure = "0.1.1" failure = "0.1.1"
fnv = "1.0" fnv = "1.0"
futures = "0.3" 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"] } odds = { version = "0.4.0", features = ["std-vec"] }
parking_lot = { version = "0.11.1", features = [] } parking_lot = { version = "0.11.1", features = [] }
pretty-hex = "0.2.1" pretty-hex = "0.2.1"
prettydiff = { git = "https://github.com/scottlamb/prettydiff", branch = "pr-update-deps" }
protobuf = "3.0.0-alpha.1" protobuf = "3.0.0-alpha.1"
ring = "0.16.2" ring = "0.16.2"
rusqlite = "0.26.1" rusqlite = "0.26.1"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
#similar = "2.1.0"
smallvec = "1.0" smallvec = "1.0"
tempfile = "3.2.0" tempfile = "3.2.0"
time = "0.1" time = "0.1"

View File

@ -7,7 +7,6 @@
//! and for tests of `moonfire-nvr upgrade`. //! and for tests of `moonfire-nvr upgrade`.
use failure::Error; use failure::Error;
use prettydiff::diff_slice;
use rusqlite::params; use rusqlite::params;
use std::fmt::Write; 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<T: std::fmt::Display + PartialEq>(
name1: &str,
slice1: &[T],
name2: &str,
slice2: &[T],
) -> Option<String> {
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. /// Returns a sorted vec of table names in the given connection.
fn get_tables(c: &rusqlite::Connection) -> Result<Vec<String>, rusqlite::Error> { fn get_tables(c: &rusqlite::Connection) -> Result<Vec<String>, rusqlite::Error> {
c.prepare( c.prepare(
@ -139,13 +167,11 @@ pub fn get_diffs(
// Compare table list. // Compare table list.
let tables1 = get_tables(c1)?; let tables1 = get_tables(c1)?;
let tables2 = get_tables(c2)?; let tables2 = get_tables(c2)?;
if tables1 != tables2 { if let Some(diff) = diff_slices(n1, &tables1[..], n2, &tables2[..]) {
write!( write!(
&mut diffs, &mut diffs,
"table list mismatch, {} vs {}:\n{}", "table list mismatch, {} vs {}:\n{}",
n1, n1, n2, diff
n2,
diff_slice(&tables1, &tables2)
)?; )?;
} }
@ -153,14 +179,11 @@ pub fn get_diffs(
for t in &tables1 { for t in &tables1 {
let columns1 = get_table_columns(c1, &t)?; let columns1 = get_table_columns(c1, &t)?;
let columns2 = get_table_columns(c2, &t)?; let columns2 = get_table_columns(c2, &t)?;
if columns1 != columns2 { if let Some(diff) = diff_slices(n1, &columns1[..], n2, &columns2[..]) {
write!( write!(
&mut diffs, &mut diffs,
"table {:?} column, {} vs {}:\n{}", "table {:?} column, {} vs {}:\n{}",
t, t, n1, n2, diff
n1,
n2,
diff_slice(&columns1, &columns2)
)?; )?;
} }
@ -168,29 +191,22 @@ pub fn get_diffs(
let mut indices2 = get_indices(c2, &t)?; let mut indices2 = get_indices(c2, &t)?;
indices1.sort_by(|a, b| a.name.cmp(&b.name)); indices1.sort_by(|a, b| a.name.cmp(&b.name));
indices2.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!( write!(
&mut diffs, &mut diffs,
"table {:?} indices, {} vs {}:\n{}", "table {:?} indices, {} vs {}:\n{}",
t, t, n1, n2, diff
n1,
n2,
diff_slice(&indices1, &indices2)
)?; )?;
} }
for i in &indices1 { for i in &indices1 {
let ic1 = get_index_columns(c1, &i.name)?; let ic1 = get_index_columns(c1, &i.name)?;
let ic2 = get_index_columns(c2, &i.name)?; let ic2 = get_index_columns(c2, &i.name)?;
if ic1 != ic2 { if let Some(diff) = diff_slices(n1, &ic1[..], n2, &ic2[..]) {
write!( write!(
&mut diffs, &mut diffs,
"table {:?} index {:?} columns {} vs {}:\n{}", "table {:?} index {:?} columns {} vs {}:\n{}",
t, t, i, n1, n2, diff
i,
n1,
n2,
diff_slice(&ic1, &ic2)
)?; )?;
} }
} }

View File

@ -190,7 +190,12 @@ mod tests {
fn compare(c: &rusqlite::Connection, ver: i32, fresh_sql: &str) -> Result<(), Error> { fn compare(c: &rusqlite::Connection, ver: i32, fresh_sql: &str) -> Result<(), Error> {
let fresh = new_conn()?; let fresh = new_conn()?;
fresh.execute_batch(fresh_sql)?; 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); panic!("Version {}: differences found:\n{}", ver, diffs);
} }
Ok(()) Ok(())