Skip to content

Commit bb2cec0

Browse files
cruesslerByron
authored andcommitted
fix!: respect diff.algorithm in Repository::blame_file
1 parent 663b41e commit bb2cec0

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

gix/src/repository/blame.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ use gix_ref::bstr::BStr;
33

44
use crate::{repository::blame_file, Repository};
55

6+
/// Options to be passed to [Repository::blame_file()](crate::Repository::blame_file()).
7+
#[derive(Default, Debug, Clone)]
8+
pub struct Options {
9+
/// The algorithm to use for diffing. If this is `None`, `diff.algorithm` will be used.
10+
pub diff_algorithm: Option<gix_diff::blob::Algorithm>,
11+
/// The ranges to blame in the file.
12+
pub ranges: gix_blame::BlameRanges,
13+
/// Don't consider commits before the given date.
14+
pub since: Option<gix_date::Time>,
15+
/// Determine if rename tracking should be performed, and how.
16+
pub rewrites: Option<gix_diff::Rewrites>,
17+
}
18+
619
impl Repository {
720
/// Produce a list of consecutive [`gix_blame::BlameEntry`] instances. Each `BlameEntry`
821
/// corresponds to a hunk of consecutive lines of the file at `suspect:<file_path>` that got
@@ -13,11 +26,30 @@ impl Repository {
1326
&self,
1427
file_path: &BStr,
1528
suspect: impl Into<ObjectId>,
16-
options: gix_blame::Options,
29+
options: Options,
1730
) -> Result<gix_blame::Outcome, blame_file::Error> {
1831
let cache: Option<gix_commitgraph::Graph> = self.commit_graph_if_enabled()?;
1932
let mut resource_cache = self.diff_resource_cache_for_tree_diff()?;
2033

34+
let Options {
35+
diff_algorithm,
36+
ranges,
37+
since,
38+
rewrites,
39+
} = options;
40+
let diff_algorithm = match diff_algorithm {
41+
Some(diff_algorithm) => diff_algorithm,
42+
None => self.diff_algorithm()?,
43+
};
44+
45+
let options = gix_blame::Options {
46+
diff_algorithm,
47+
ranges,
48+
since,
49+
rewrites,
50+
debug_track_path: false,
51+
};
52+
2153
let outcome = gix_blame::file(
2254
&self.objects,
2355
suspect.into(),

gix/src/repository/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ pub enum Kind {
1919

2020
#[cfg(any(feature = "attributes", feature = "excludes"))]
2121
pub mod attributes;
22+
///
2223
#[cfg(feature = "blame")]
23-
mod blame;
24+
pub mod blame;
2425
mod cache;
2526
#[cfg(feature = "worktree-mutation")]
2627
mod checkout;
@@ -103,6 +104,8 @@ pub mod blame_file {
103104
#[error(transparent)]
104105
CommitGraphIfEnabled(#[from] super::commit_graph_if_enabled::Error),
105106
#[error(transparent)]
107+
DiffAlgorithm(#[from] crate::config::diff::algorithm::Error),
108+
#[error(transparent)]
106109
DiffResourceCache(#[from] super::diff_resource_cache::Error),
107110
#[error(transparent)]
108111
Blame(#[from] gix_blame::Error),

gix/tests/gix/repository/blame.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn simple() -> crate::Result {
1717
fn with_options() -> crate::Result {
1818
let repo = crate::named_repo("make_blame_repo.sh")?;
1919

20-
let options = gix::blame::Options {
20+
let options = gix::repository::blame::Options {
2121
ranges: gix::blame::BlameRanges::from_one_based_inclusive_range(1..=2)?,
2222
..Default::default()
2323
};

0 commit comments

Comments
 (0)