Skip to content

Commit b1edb9e

Browse files
committed
feat: diff algorithm is controlled by git configuration diff.algorithm
1 parent 381924c commit b1edb9e

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

Diff for: git-repository/src/object/tree/diff.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,22 @@ pub mod change {
110110

111111
impl<'old, 'new> DiffPlatform<'old, 'new> {
112112
/// Perform a diff on lines between the old and the new version of a blob.
113+
/// The algorithm is determined by the `diff.algorithm` configuration.
113114
/// Note that the [`Sink`][git_diff::text::imara::Sink] implementation is
114115
/// what makes the diff usable and relies heavily on what the caller requires, as created by `make_sink`.
115-
pub fn lines<FnS, S>(&self, algorithm: git_diff::text::Algorithm, make_sink: FnS) -> S::Out
116+
pub fn lines<FnS, S>(&self, new_sink: FnS) -> S::Out
116117
where
117118
FnS: for<'a> FnOnce(&git_diff::text::imara::intern::InternedInput<&'a [u8]>) -> S,
118119
S: git_diff::text::imara::Sink,
119120
{
120121
git_diff::text::with(
121122
self.old.data.as_bstr(),
122123
self.new.data.as_bstr(),
123-
algorithm,
124+
git_diff::text::Algorithm::Myers, // TODO: use diff.algorithm
124125
// TODO: make use of `core.eol` and/or filters to do line-counting correctly. It's probably
125126
// OK to just know how these objects are saved to know what constitutes a line.
126127
git_diff::text::imara::intern::InternedInput::new,
127-
make_sink,
128+
new_sink,
128129
)
129130
.1
130131
}

Diff for: git-repository/tests/object/tree.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ mod diff {
3535
.diff()
3636
.expect("changed file")
3737
.expect("objects available")
38-
.lines(git::diff::text::Algorithm::Myers, |_| {
39-
git_diff::text::imara::sink::Counter::default()
40-
});
38+
.lines(|_| git_diff::text::imara::sink::Counter::default());
4139
assert_eq!(count.insertions, 1);
4240
assert_eq!(count.removals, 0);
4341
Ok(Default::default())

Diff for: src/plumbing/progress.rs

+4
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ static GIT_CONFIG: &[Record] = &[
280280
deviation: None,
281281
},
282282
},
283+
Record {
284+
config: "diff.algorithm",
285+
usage: Planned { note: Some("to be used when doing line diffs") },
286+
},
283287
Record {
284288
config: "extensions.objectFormat",
285289
usage: InModule {

0 commit comments

Comments
 (0)