diff --git a/Cargo.lock b/Cargo.lock index e3ec597c..fadf0412 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -223,6 +223,7 @@ dependencies = [ "ctrlc", "fastrand", "fs2", + "gitpatch", "globset", "humantime", "ignore", @@ -236,7 +237,6 @@ dependencies = [ "nix 0.29.0", "num_cpus", "nutmeg", - "patch", "path-slash", "predicates 3.0.0", "pretty_assertions", @@ -587,6 +587,17 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +[[package]] +name = "gitpatch" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce212119eb3801015ea7e8bfb78f029ca16805de0d808358c080ff55ecbe675" +dependencies = [ + "chrono", + "nom", + "nom_locate", +] + [[package]] name = "globset" version = "0.4.10" @@ -1058,17 +1069,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "patch" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c07fdcdd8b05bdcf2a25bc195b6c34cbd52762ada9dba88bf81e7686d14e7a" -dependencies = [ - "chrono", - "nom", - "nom_locate", -] - [[package]] name = "path-slash" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 6e40164f..0e9c845b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,7 @@ jobserver = "0.1" mutants = "0.0.3" nextest-metadata = "0.12.1" num_cpus = "1.16" -patch = "0.7" +gitpatch = "0.7" path-slash = "0.2" quote = "1.0.35" regex = "1.10" diff --git a/src/in_diff.rs b/src/in_diff.rs index 2b103af7..16db3dd4 100644 --- a/src/in_diff.rs +++ b/src/in_diff.rs @@ -4,13 +4,12 @@ //! for example from uncommitted or unmerged changes. use std::collections::HashMap; -use std::iter::once; use anyhow::{anyhow, bail}; use camino::Utf8Path; +use gitpatch::{Line, Patch}; use indoc::formatdoc; use itertools::Itertools; -use patch::{Line, Patch}; use tracing::{info, trace, warn}; use crate::mutant::Mutant; @@ -19,22 +18,13 @@ use crate::Result; /// Return only mutants to functions whose source was touched by this diff. pub fn diff_filter(mutants: Vec, diff_text: &str) -> Result> { - // Strip any "Binary files .. differ" lines because `patch` doesn't understand them at - // the moment; this could be removed if it's fixed in that crate. - let fixed_diff = diff_text - .lines() - .filter(|line| !(line.starts_with("Binary files "))) - .chain(once("")) - .join("\n"); - // Flatten the error to a string because otherwise it references the diff, and can't be returned. - if fixed_diff.trim().is_empty() { + if diff_text.trim().is_empty() { info!("diff file is empty; no mutants will match"); return Ok(Vec::new()); } - let patches = - Patch::from_multiple(&fixed_diff).map_err(|err| anyhow!("Failed to parse diff: {err}"))?; + Patch::from_multiple(diff_text).map_err(|err| anyhow!("Failed to parse diff: {err}"))?; check_diff_new_text_matches(&patches, &mutants)?; let mut lines_changed_by_path: HashMap<&Utf8Path, Vec> = HashMap::new(); for patch in &patches { diff --git a/tests/in_diff.rs b/tests/in_diff.rs index 0bb85cff..b8f57c4f 100644 --- a/tests/in_diff.rs +++ b/tests/in_diff.rs @@ -84,7 +84,7 @@ fn binary_diff_is_not_an_error_and_matches_nothing() { .assert() .success() .stdout("") - .stderr(predicate::str::contains("diff file is empty")); + .stderr(""); } #[test]