Skip to content

Commit dce127e

Browse files
authored
Merge pull request #1888 from cruessler/respect-diff-algorithm-in-blame
Respect `diff.algorithm` in `gix blame`
2 parents 308096f + 8a31d88 commit dce127e

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
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
},

src/plumbing/main.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1555,10 +1555,17 @@ pub fn main() -> Result<()> {
15551555
progress_keep_open,
15561556
None,
15571557
move |_progress, out, err| {
1558+
let repo = repository(Mode::Lenient)?;
1559+
let diff_algorithm = repo.diff_algorithm()?;
1560+
15581561
core::repository::blame::blame_file(
1559-
repository(Mode::Lenient)?,
1562+
repo,
15601563
&file,
1561-
gix::blame::Options { range, since },
1564+
gix::blame::Options {
1565+
diff_algorithm,
1566+
range,
1567+
since,
1568+
},
15621569
out,
15631570
statistics.then_some(err),
15641571
)

0 commit comments

Comments
 (0)