Skip to content

Commit

Permalink
Merge branch 'imra-diff'
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Oct 28, 2022
2 parents c9c1658 + 7d5fb3c commit f53f942
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 97 deletions.
91 changes: 51 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion git-diff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ authors = ["Sebastian Thiel <[email protected]>"]
edition = "2018"
include = ["src/**/*"]

[features]
serde1 = ["serde", "git-hash/serde1", "git-object/serde1"]

[lib]
doctest = false

[dependencies]
git-hash = { version = "^0.9.11", path = "../git-hash" }
git-object = { version = "^0.22.0", path = "../git-object" }
thiserror = "1.0.32"
similar = { version = "2.2.0", features = ["bytes"] }
imara-diff = "0.1.3"
serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}

[dev-dependencies]
git-odb = { path = "../git-odb" }
Expand Down
2 changes: 1 addition & 1 deletion git-diff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
pub mod tree;

///
pub mod lines;
pub mod text;
25 changes: 0 additions & 25 deletions git-diff/src/lines.rs

This file was deleted.

26 changes: 26 additions & 0 deletions git-diff/src/text.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use git_object::bstr::BStr;
/// The crate powering file diffs.
pub use imara_diff as imara;
pub use imara_diff::Algorithm;

/// Create a diff yielding the changes to turn `old` into `new` with `algorithm`. `make_input` obtains the `old` and `new`
/// byte buffers and produces an interner, which is then passed to `make_sink` for creating a processor over the changes.
///
/// See [the `imara-diff` crate documentation][imara] for information on how to implement a [`Sink`][imara::Sink].
pub fn with<'a, FnI, FnS, S>(
old: &'a BStr,
new: &'a BStr,
algorithm: Algorithm,
make_input: FnI,
make_sink: FnS,
) -> (imara::intern::InternedInput<&'a [u8]>, S::Out)
where
FnI: FnOnce(&'a [u8], &'a [u8]) -> imara::intern::InternedInput<&'a [u8]>,
FnS: FnOnce(&imara::intern::InternedInput<&'a [u8]>) -> S,
S: imara_diff::Sink,
{
let input = make_input(old.as_ref(), new.as_ref());
let sink = make_sink(&input);
let out = imara::diff(algorithm, &input, sink);
(input, out)
}
Loading

0 comments on commit f53f942

Please sign in to comment.