Skip to content

Commit e9a493c

Browse files
committed
feat!: add diff_algorithm to blame::file()
1 parent 36a846f commit e9a493c

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

gix-blame/src/file/function.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,15 @@ pub fn file(
269269
unreachable!("We already found file_path in suspect^{{tree}}, so it can't be deleted")
270270
}
271271
gix_diff::tree::recorder::Change::Modification { previous_oid, oid, .. } => {
272-
let changes = blob_changes(&odb, resource_cache, oid, previous_oid, file_path, &mut stats)?;
272+
let changes = blob_changes(
273+
&odb,
274+
resource_cache,
275+
oid,
276+
previous_oid,
277+
file_path,
278+
options.diff_algorithm,
279+
&mut stats,
280+
)?;
273281
hunks_to_blame = process_changes(hunks_to_blame, changes, suspect, parent_id);
274282
}
275283
}
@@ -553,6 +561,7 @@ fn blob_changes(
553561
oid: ObjectId,
554562
previous_oid: ObjectId,
555563
file_path: &BStr,
564+
diff_algorithm: gix_diff::blob::Algorithm,
556565
stats: &mut Statistics,
557566
) -> Result<Vec<Change>, Error> {
558567
/// Record all [`Change`]s to learn about additions, deletions and unchanged portions of a *Source File*.
@@ -631,7 +640,7 @@ fn blob_changes(
631640
let number_of_lines_in_destination = input.after.len();
632641
let change_recorder = ChangeRecorder::new(number_of_lines_in_destination as u32);
633642

634-
let res = gix_diff::blob::diff(gix_diff::blob::Algorithm::Histogram, &input, change_recorder);
643+
let res = gix_diff::blob::diff(diff_algorithm, &input, change_recorder);
635644
stats.blobs_diffed += 1;
636645
Ok(res)
637646
}

gix-blame/src/types.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use std::{
1010
/// Options to be passed to [`file()`](crate::file()).
1111
#[derive(Default, Debug, Clone)]
1212
pub struct Options {
13+
/// The algorithm to use for diffing.
14+
pub diff_algorithm: gix_diff::blob::Algorithm,
1315
/// A 1-based inclusive range, in order to mirror `git`’s behaviour. `Some(20..40)` represents
1416
/// 21 lines, spanning from line 20 up to and including line 40. This will be converted to
1517
/// `19..40` internally as the algorithm uses 0-based ranges that are exclusive at the end.

gix-blame/tests/blame.rs

+4
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ macro_rules! mktest {
192192
&mut resource_cache,
193193
format!("{}.txt", $case).as_str().into(),
194194
gix_blame::Options {
195+
diff_algorithm: gix_diff::blob::Algorithm::Histogram,
195196
range: None,
196197
since: None,
197198
},
@@ -262,6 +263,7 @@ fn diff_disparity() {
262263
&mut resource_cache,
263264
format!("{case}.txt").as_str().into(),
264265
gix_blame::Options {
266+
diff_algorithm: gix_diff::blob::Algorithm::Histogram,
265267
range: None,
266268
since: None,
267269
},
@@ -293,6 +295,7 @@ fn line_range() {
293295
&mut resource_cache,
294296
"simple.txt".into(),
295297
gix_blame::Options {
298+
diff_algorithm: gix_diff::blob::Algorithm::Histogram,
296299
range: Some(1..2),
297300
since: None,
298301
},
@@ -323,6 +326,7 @@ fn since() {
323326
&mut resource_cache,
324327
"simple.txt".into(),
325328
gix_blame::Options {
329+
diff_algorithm: gix_diff::blob::Algorithm::Histogram,
326330
range: None,
327331
since: Some(gix_date::parse("2025-01-31", None).unwrap()),
328332
},

0 commit comments

Comments
 (0)