From bb2cec09db45c10e58527b56682e602692a5628d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20R=C3=BC=C3=9Fler?= Date: Thu, 30 Oct 2025 20:34:48 +0100 Subject: [PATCH 1/3] fix!: respect `diff.algorithm` in `Repository::blame_file` --- gix/src/repository/blame.rs | 34 ++++++++++++++++++++++++++++++- gix/src/repository/mod.rs | 5 ++++- gix/tests/gix/repository/blame.rs | 2 +- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/gix/src/repository/blame.rs b/gix/src/repository/blame.rs index 84c0902f7de..1c1614c53bf 100644 --- a/gix/src/repository/blame.rs +++ b/gix/src/repository/blame.rs @@ -3,6 +3,19 @@ use gix_ref::bstr::BStr; use crate::{repository::blame_file, Repository}; +/// 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 this is `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, +} + impl Repository { /// Produce a list of consecutive [`gix_blame::BlameEntry`] instances. Each `BlameEntry` /// corresponds to a hunk of consecutive lines of the file at `suspect:` that got @@ -13,11 +26,30 @@ impl Repository { &self, file_path: &BStr, suspect: impl Into, - options: gix_blame::Options, + options: Options, ) -> Result { let cache: Option = self.commit_graph_if_enabled()?; let mut resource_cache = self.diff_resource_cache_for_tree_diff()?; + let 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..a09d081029a 100644 --- a/gix/src/repository/mod.rs +++ b/gix/src/repository/mod.rs @@ -19,8 +19,9 @@ pub enum Kind { #[cfg(any(feature = "attributes", feature = "excludes"))] pub mod attributes; +/// #[cfg(feature = "blame")] -mod blame; +pub mod blame; mod cache; #[cfg(feature = "worktree-mutation")] mod checkout; @@ -103,6 +104,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..84646d6da60 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::Options { ranges: gix::blame::BlameRanges::from_one_based_inclusive_range(1..=2)?, ..Default::default() }; From 2a187cacbc66dd6c78c0549d9e07f65a0337f0a6 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 1 Nov 2025 15:22:28 +0100 Subject: [PATCH 2/3] refactor - put `Options` into the right place --- gix/Cargo.toml | 2 +- gix/src/repository/blame.rs | 19 +++---------------- gix/src/repository/mod.rs | 15 ++++++++++++++- gix/tests/gix/repository/blame.rs | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) 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 1c1614c53bf..18064ce5288 100644 --- a/gix/src/repository/blame.rs +++ b/gix/src/repository/blame.rs @@ -3,19 +3,6 @@ use gix_ref::bstr::BStr; use crate::{repository::blame_file, Repository}; -/// 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 this is `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, -} - impl Repository { /// Produce a list of consecutive [`gix_blame::BlameEntry`] instances. Each `BlameEntry` /// corresponds to a hunk of consecutive lines of the file at `suspect:` that got @@ -26,12 +13,12 @@ impl Repository { &self, file_path: &BStr, suspect: impl Into, - options: 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 Options { + let blame_file::Options { diff_algorithm, ranges, since, diff --git a/gix/src/repository/mod.rs b/gix/src/repository/mod.rs index a09d081029a..e6c2ab66ac0 100644 --- a/gix/src/repository/mod.rs +++ b/gix/src/repository/mod.rs @@ -21,7 +21,7 @@ pub enum Kind { pub mod attributes; /// #[cfg(feature = "blame")] -pub mod blame; +mod blame; mod cache; #[cfg(feature = "worktree-mutation")] mod checkout; @@ -97,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)] diff --git a/gix/tests/gix/repository/blame.rs b/gix/tests/gix/repository/blame.rs index 84646d6da60..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::repository::blame::Options { + let options = gix::repository::blame_file::Options { ranges: gix::blame::BlameRanges::from_one_based_inclusive_range(1..=2)?, ..Default::default() }; From adc3624dc9dfcb3470257659e06c2dd9fa09f305 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 1 Nov 2025 15:51:10 +0100 Subject: [PATCH 3/3] Fix CI --- tests/journey/ein.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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" } ) )