diff --git a/gix/Cargo.toml b/gix/Cargo.toml index 2fdce440009..3549c848983 100644 --- a/gix/Cargo.toml +++ b/gix/Cargo.toml @@ -145,7 +145,7 @@ blob-diff = ["gix-diff/blob", "attributes"] merge = ["tree-editor", "blob-diff", "dep:gix-merge", "attributes"] ## Add blame command similar to `git blame`. -blame = ["dep:gix-blame"] +blame = ["dep:gix-blame", "blob-diff"] ## Make it possible to turn a tree into a stream of bytes, which can be decoded to entries and turned into various other formats. worktree-stream = ["gix-worktree-stream", "attributes"] diff --git a/gix/src/repository/blame.rs b/gix/src/repository/blame.rs index 84c0902f7de..18064ce5288 100644 --- a/gix/src/repository/blame.rs +++ b/gix/src/repository/blame.rs @@ -13,11 +13,30 @@ impl Repository { &self, file_path: &BStr, suspect: impl Into, - options: gix_blame::Options, + options: blame_file::Options, ) -> Result { - let cache: Option = self.commit_graph_if_enabled()?; + let cache = self.commit_graph_if_enabled()?; let mut resource_cache = self.diff_resource_cache_for_tree_diff()?; + let blame_file::Options { + diff_algorithm, + ranges, + since, + rewrites, + } = options; + let diff_algorithm = match diff_algorithm { + Some(diff_algorithm) => diff_algorithm, + None => self.diff_algorithm()?, + }; + + let options = gix_blame::Options { + diff_algorithm, + ranges, + since, + rewrites, + debug_track_path: false, + }; + let outcome = gix_blame::file( &self.objects, suspect.into(), diff --git a/gix/src/repository/mod.rs b/gix/src/repository/mod.rs index ae1b55b64d0..e6c2ab66ac0 100644 --- a/gix/src/repository/mod.rs +++ b/gix/src/repository/mod.rs @@ -19,6 +19,7 @@ pub enum Kind { #[cfg(any(feature = "attributes", feature = "excludes"))] pub mod attributes; +/// #[cfg(feature = "blame")] mod blame; mod cache; @@ -96,6 +97,19 @@ mod new_commit_as { /// #[cfg(feature = "blame")] pub mod blame_file { + /// Options to be passed to [Repository::blame_file()](crate::Repository::blame_file()). + #[derive(Default, Debug, Clone)] + pub struct Options { + /// The algorithm to use for diffing. If `None`, `diff.algorithm` will be used. + pub diff_algorithm: Option, + /// The ranges to blame in the file. + pub ranges: gix_blame::BlameRanges, + /// Don't consider commits before the given date. + pub since: Option, + /// Determine if rename tracking should be performed, and how. + pub rewrites: Option, + } + /// The error returned by [Repository::blame_file()](crate::Repository::blame_file()). #[derive(Debug, thiserror::Error)] #[allow(missing_docs)] @@ -103,6 +117,8 @@ pub mod blame_file { #[error(transparent)] CommitGraphIfEnabled(#[from] super::commit_graph_if_enabled::Error), #[error(transparent)] + DiffAlgorithm(#[from] crate::config::diff::algorithm::Error), + #[error(transparent)] DiffResourceCache(#[from] super::diff_resource_cache::Error), #[error(transparent)] Blame(#[from] gix_blame::Error), diff --git a/gix/tests/gix/repository/blame.rs b/gix/tests/gix/repository/blame.rs index d3a7c23c947..aa5106f0d32 100644 --- a/gix/tests/gix/repository/blame.rs +++ b/gix/tests/gix/repository/blame.rs @@ -17,7 +17,7 @@ fn simple() -> crate::Result { fn with_options() -> crate::Result { let repo = crate::named_repo("make_blame_repo.sh")?; - let options = gix::blame::Options { + let options = gix::repository::blame_file::Options { ranges: gix::blame::BlameRanges::from_one_based_inclusive_range(1..=2)?, ..Default::default() }; diff --git a/tests/journey/ein.sh b/tests/journey/ein.sh index 89bffe1eed5..c971f8ac9e6 100644 --- a/tests/journey/ein.sh +++ b/tests/journey/ein.sh @@ -1,5 +1,10 @@ # Must be sourced into the main journey test + +function remove-thread-id { + sed -E 's/ \([0-9]+\)//' +} + if test "$kind" = "max" || test "$kind" = "max-pure"; then title "Porcelain ${kind}" ( @@ -8,21 +13,24 @@ title "Porcelain ${kind}" (with "the --quiet option set" it "fails as expected" && { WITH_SNAPSHOT="$snapshot/expected-failure" \ - expect_run_sh 101 "$exe -q panic" + SNAPSHOT_FILTER=remove-thread-id \ + expect_run_sh 0 "$exe -q panic" } ) (with "NO --quiet option set" it "fails as expected" && { WITH_SNAPSHOT="$snapshot/expected-failure-in-thread" \ - expect_run_sh 101 "$exe panic" + SNAPSHOT_FILTER=remove-thread-id \ + expect_run_sh 0 "$exe panic" } ) (not_on_ci # due to different TTY settings, the output differs, it's OK for now (with "progress option set" it "fails as expected" && { WITH_SNAPSHOT="$snapshot/expected-failure-in-thread-with-progress" \ - expect_run_sh 101 "$exe --progress panic" + SNAPSHOT_FILTER=remove-thread-id \ + expect_run_sh 0 "$exe --progress panic" } ) )