Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "diffy"
name = "diffy-fork-filenames"
version = "0.3.0"
authors = ["Brandon Williams <bwilliams.eng@gmail.com>"]
authors = ["Roben Kleene <contact@robenkleene.com>"]
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"]
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/)
Expand Down
27 changes: 20 additions & 7 deletions src/diff/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,12 @@ 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> {
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);
self.construct_patch(original, modified, "original", "modified")
}

let hunks = to_hunks(&old_lines, &new_lines, &solution, self.context_len);
Patch::new(Some("original"), Some("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, 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
Expand Down Expand Up @@ -134,6 +132,17 @@ impl DiffOptions {

solution
}

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);

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_filename), Some(modified_filename), hunks)
}
}

impl Default for DiffOptions {
Expand Down Expand Up @@ -185,6 +194,10 @@ 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, 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
pub fn create_patch_bytes<'a>(original: &'a [u8], modified: &'a [u8]) -> Patch<'a, [u8]> {
DiffOptions::default().create_patch_bytes(original, modified)
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};