-
-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: forward line-diffing capabilities curtesy of the
similar
crat…
…e. (#470) This is a first and maybe the last step towards providing diffing functionality, and it seems like the right choice to keep this in similar and contribute there as needed. All algorithms are well described and thus shouldn't be git-specific per-se, and `similar` is the best the community has to offer.
- Loading branch information
Showing
4 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,6 @@ | |
|
||
/// | ||
pub mod tree; | ||
|
||
/// | ||
pub mod lines; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use git_object::bstr::BStr; | ||
use similar::TextDiff; | ||
|
||
/// The crate powering file diffs. | ||
pub use similar; | ||
pub use similar::Algorithm; | ||
|
||
/// Provide an iterator over the changes needed to turn `old` into `new` with `algorithm`. | ||
/// | ||
/// See [the `similar` crate documentation][similar::TextDiffConfig::diff_lines()] for information on how to use the iterator. | ||
pub fn with<'old, 'new, 'bufs>( | ||
old: &'old BStr, | ||
new: &'new BStr, | ||
algorithm: Algorithm, | ||
) -> TextDiff<'old, 'new, 'bufs, [u8]> { | ||
similar::TextDiffConfig::default() | ||
.algorithm(algorithm) | ||
.diff_lines(old.as_ref(), new.as_ref()) | ||
} | ||
|
||
/// Provide an iterator over the changes needed to turn `old` into `new` with Myers algorithm, the default for `git`. | ||
/// | ||
/// See [the `similar` crate documentation][similar::TextDiffConfig::diff_lines()] for information on how to use the iterator. | ||
pub fn myers<'old, 'new, 'bufs>(old: &'old BStr, new: &'new BStr) -> TextDiff<'old, 'new, 'bufs, [u8]> { | ||
with(old, new, Algorithm::Myers) | ||
} |