From db5c06db60e939401166a5684df9c7e93dbdda83 Mon Sep 17 00:00:00 2001 From: Roben Kleene Date: Sun, 19 Feb 2023 05:41:24 -0500 Subject: [PATCH 1/5] WIP Add filename parameters to create patch --- src/diff/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/diff/mod.rs b/src/diff/mod.rs index a456c41..ec447dc 100644 --- a/src/diff/mod.rs +++ b/src/diff/mod.rs @@ -94,7 +94,7 @@ impl DiffOptions { } /// Produce a Patch between two texts based on the configured options - pub fn create_patch<'a>(&self, original: &'a str, modified: &'a str) -> Patch<'a, str> { + pub fn create_patch<'a>(&self, original: &'a str, modified: &'a str, originalFilename: Option<&'a str>, modifiedFilename: Option<&'a str>) -> Patch<'a, str> { let mut classifier = Classifier::default(); let (old_lines, old_ids) = classifier.classify_lines(original); let (new_lines, new_ids) = classifier.classify_lines(modified); @@ -102,7 +102,7 @@ impl DiffOptions { let solution = self.diff_slice(&old_ids, &new_ids); let hunks = to_hunks(&old_lines, &new_lines, &solution, self.context_len); - Patch::new(Some("original"), Some("modified"), hunks) + Patch::new(originalFilename.unwrap_or(("original")), modifiedFilename.unwrap_or(("modified")), hunks) } /// Create a patch between two potentially non-utf8 texts @@ -181,8 +181,8 @@ fn diff<'a>(original: &'a str, modified: &'a str) -> Vec> { /// let patch = create_patch(original, modified); /// assert_eq!(patch.to_string(), expected); /// ``` -pub fn create_patch<'a>(original: &'a str, modified: &'a str) -> Patch<'a, str> { - DiffOptions::default().create_patch(original, modified) +pub fn create_patch<'a>(original: &'a str, modified: &'a str, originalFilename: Option<&'a str>, modifiedFilename: Option<&'a str>) -> Patch<'a, str> { + DiffOptions::default().create_patch(original, modified, originalFilename, modifiedFilename) } /// Create a patch between two potentially non-utf8 texts From 0c5de6b05b9ceb9b5e99911d07b29d81fe835d3a Mon Sep 17 00:00:00 2001 From: Roben Kleene Date: Mon, 20 Feb 2023 05:37:51 -0500 Subject: [PATCH 2/5] WIP Make separate underlying construct patch --- src/diff/mod.rs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/diff/mod.rs b/src/diff/mod.rs index ec447dc..67f5a35 100644 --- a/src/diff/mod.rs +++ b/src/diff/mod.rs @@ -94,15 +94,13 @@ impl DiffOptions { } /// Produce a Patch between two texts based on the configured options - pub fn create_patch<'a>(&self, original: &'a str, modified: &'a str, originalFilename: Option<&'a str>, modifiedFilename: Option<&'a str>) -> Patch<'a, str> { - let mut classifier = Classifier::default(); - let (old_lines, old_ids) = classifier.classify_lines(original); - let (new_lines, new_ids) = classifier.classify_lines(modified); - - let solution = self.diff_slice(&old_ids, &new_ids); + pub fn create_patch<'a>(&self, original: &'a str, modified: &'a str) -> Patch<'a, str> { + self.construct_patch(original, modified, "original", "modified") + } - let hunks = to_hunks(&old_lines, &new_lines, &solution, self.context_len); - Patch::new(originalFilename.unwrap_or(("original")), modifiedFilename.unwrap_or(("modified")), hunks) + /// Produce a Patch between two texts from files based on the configured options + pub fn create_file_patch<'a>(&self, original: &'a str, modified: &'a str, originalFilename: Option<&'a str>, modifiedFilename: Option<&'a str>) -> Patch<'a, str> { + self.construct_patch(original, modified, originalFilename, modifiedFilename) } /// Create a patch between two potentially non-utf8 texts @@ -134,6 +132,17 @@ impl DiffOptions { solution } + + fn construct_patch<'a>(&self, original: &'a str, modified: &'a str, originalFilename: Option<&'a str>, modifiedFilename: Option<&'a str>) -> Patch<'a, str> { + let mut classifier = Classifier::default(); + let (old_lines, old_ids) = classifier.classify_lines(original); + let (new_lines, new_ids) = classifier.classify_lines(modified); + + let solution = self.diff_slice(&old_ids, &new_ids); + + let hunks = to_hunks(&old_lines, &new_lines, &solution, self.context_len); + Patch::new(originalFilename.unwrap_or("original"), modifiedFilename.unwrap_or("modified"), hunks) + } } impl Default for DiffOptions { @@ -181,8 +190,12 @@ fn diff<'a>(original: &'a str, modified: &'a str) -> Vec> { /// let patch = create_patch(original, modified); /// assert_eq!(patch.to_string(), expected); /// ``` -pub fn create_patch<'a>(original: &'a str, modified: &'a str, originalFilename: Option<&'a str>, modifiedFilename: Option<&'a str>) -> Patch<'a, str> { - DiffOptions::default().create_patch(original, modified, originalFilename, modifiedFilename) +pub fn create_patch<'a>(original: &'a str, modified: &'a str) -> Patch<'a, str> { + DiffOptions::default().create_patch(original, modified) +} + +pub fn create_file_patch<'a>(original: &'a str, modified: &'a str, originalFilename: Option<&'a str>, modifiedFilename: Option<&'a str>) -> Patch<'a, str> { + DiffOptions::default().create_file_patch(original, modified, originalFilename, modifiedFilename) } /// Create a patch between two potentially non-utf8 texts From 40879238d033e0842d4eb4ab2637ac7faaea8017 Mon Sep 17 00:00:00 2001 From: Roben Kleene Date: Mon, 20 Feb 2023 05:43:05 -0500 Subject: [PATCH 3/5] Fix variable names --- src/diff/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/diff/mod.rs b/src/diff/mod.rs index 67f5a35..b74bac8 100644 --- a/src/diff/mod.rs +++ b/src/diff/mod.rs @@ -99,8 +99,8 @@ impl DiffOptions { } /// Produce a Patch between two texts from files based on the configured options - pub fn create_file_patch<'a>(&self, original: &'a str, modified: &'a str, originalFilename: Option<&'a str>, modifiedFilename: Option<&'a str>) -> Patch<'a, str> { - self.construct_patch(original, modified, originalFilename, modifiedFilename) + pub fn create_file_patch<'a>(&self, original: &'a str, modified: &'a str, original_filename: &'a str, modified_filename: &'a str) -> Patch<'a, str> { + self.construct_patch(original, modified, original_filename, modified_filename) } /// Create a patch between two potentially non-utf8 texts @@ -133,7 +133,7 @@ impl DiffOptions { solution } - fn construct_patch<'a>(&self, original: &'a str, modified: &'a str, originalFilename: Option<&'a str>, modifiedFilename: Option<&'a str>) -> Patch<'a, str> { + fn construct_patch<'a>(&self, original: &'a str, modified: &'a str, original_filename: &'a str, modified_filename: &'a str) -> Patch<'a, str> { let mut classifier = Classifier::default(); let (old_lines, old_ids) = classifier.classify_lines(original); let (new_lines, new_ids) = classifier.classify_lines(modified); @@ -141,7 +141,7 @@ impl DiffOptions { let solution = self.diff_slice(&old_ids, &new_ids); let hunks = to_hunks(&old_lines, &new_lines, &solution, self.context_len); - Patch::new(originalFilename.unwrap_or("original"), modifiedFilename.unwrap_or("modified"), hunks) + Patch::new(Some(original_filename), Some(modified_filename), hunks) } } @@ -194,8 +194,8 @@ pub fn create_patch<'a>(original: &'a str, modified: &'a str) -> Patch<'a, str> DiffOptions::default().create_patch(original, modified) } -pub fn create_file_patch<'a>(original: &'a str, modified: &'a str, originalFilename: Option<&'a str>, modifiedFilename: Option<&'a str>) -> Patch<'a, str> { - DiffOptions::default().create_file_patch(original, modified, originalFilename, modifiedFilename) +pub fn create_file_patch<'a>(original: &'a str, modified: &'a str, original_filename: &'a str, modified_filename: &'a str) -> Patch<'a, str> { + DiffOptions::default().create_file_patch(original, modified, original_filename, modified_filename) } /// Create a patch between two potentially non-utf8 texts From f8aad5d92194d1216f0b5b1682eae2f290800d95 Mon Sep 17 00:00:00 2001 From: Roben Kleene Date: Tue, 21 Feb 2023 05:33:23 -0500 Subject: [PATCH 4/5] Expose the function --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 2d4b0dc..3eb1427 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -220,6 +220,6 @@ mod range; mod utils; pub use apply::{apply, apply_bytes, ApplyError}; -pub use diff::{create_patch, create_patch_bytes, DiffOptions}; +pub use diff::{create_patch, create_file_patch, create_patch_bytes, DiffOptions}; pub use merge::{merge, merge_bytes, ConflictStyle, MergeOptions}; pub use patch::{Hunk, HunkRange, Line, ParsePatchError, Patch, PatchFormatter}; From 35003c5677709414f6438b845246701449ad13ec Mon Sep 17 00:00:00 2001 From: Roben Kleene Date: Sun, 25 Jun 2023 16:22:29 +0000 Subject: [PATCH 5/5] Update metadata for fork --- Cargo.toml | 8 ++++---- README.md | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f94b45b..ec35dd6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "diffy" +name = "diffy-fork-filenames" version = "0.3.0" -authors = ["Brandon Williams "] +authors = ["Roben Kleene "] license = "MIT OR Apache-2.0" -description = "Tools for finding and manipulating differences between files" +description = "Fork of https://docs.rs/diffy that allows specifiying filenames" documentation = "https://docs.rs/diffy" -repository = "https://github.com/bmwill/diffy" +repository = "https://github.com/robenkleene/diffy" readme = "README.md" keywords = ["diff", "patch", "merge"] categories = ["text-processing"] diff --git a/README.md b/README.md index 4b9fce7..787fa4a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # diffy +**A fork of [diffy](https://github.com/robenkleene/diffy) that adds support for changing changing the filenames.** + [![diffy on crates.io](https://img.shields.io/crates/v/diffy)](https://crates.io/crates/diffy) [![Documentation (latest release)](https://docs.rs/diffy/badge.svg)](https://docs.rs/diffy/) [![Documentation (master)](https://img.shields.io/badge/docs-master-59f)](https://bmwill.github.io/diffy/diffy/)