Skip to content

Commit

Permalink
feat: diff algorithm is controlled by git configuration diff.algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Oct 28, 2022
1 parent 381924c commit b1edb9e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions git-repository/src/object/tree/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,22 @@ pub mod change {

impl<'old, 'new> DiffPlatform<'old, 'new> {
/// Perform a diff on lines between the old and the new version of a blob.
/// The algorithm is determined by the `diff.algorithm` configuration.
/// Note that the [`Sink`][git_diff::text::imara::Sink] implementation is
/// what makes the diff usable and relies heavily on what the caller requires, as created by `make_sink`.
pub fn lines<FnS, S>(&self, algorithm: git_diff::text::Algorithm, make_sink: FnS) -> S::Out
pub fn lines<FnS, S>(&self, new_sink: FnS) -> S::Out
where
FnS: for<'a> FnOnce(&git_diff::text::imara::intern::InternedInput<&'a [u8]>) -> S,
S: git_diff::text::imara::Sink,
{
git_diff::text::with(
self.old.data.as_bstr(),
self.new.data.as_bstr(),
algorithm,
git_diff::text::Algorithm::Myers, // TODO: use diff.algorithm
// TODO: make use of `core.eol` and/or filters to do line-counting correctly. It's probably
// OK to just know how these objects are saved to know what constitutes a line.
git_diff::text::imara::intern::InternedInput::new,
make_sink,
new_sink,
)
.1
}
Expand Down
4 changes: 1 addition & 3 deletions git-repository/tests/object/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ mod diff {
.diff()
.expect("changed file")
.expect("objects available")
.lines(git::diff::text::Algorithm::Myers, |_| {
git_diff::text::imara::sink::Counter::default()
});
.lines(|_| git_diff::text::imara::sink::Counter::default());
assert_eq!(count.insertions, 1);
assert_eq!(count.removals, 0);
Ok(Default::default())
Expand Down
4 changes: 4 additions & 0 deletions src/plumbing/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ static GIT_CONFIG: &[Record] = &[
deviation: None,
},
},
Record {
config: "diff.algorithm",
usage: Planned { note: Some("to be used when doing line diffs") },
},
Record {
config: "extensions.objectFormat",
usage: InModule {
Expand Down

0 comments on commit b1edb9e

Please sign in to comment.