fix!: respect `diff.algorithm` in `Repository::blame_file`
Unified · Split
| @@ -145,7 +145,7 @@ blob-diff = ["gix-diff/blob", "attributes"] · 144 unmodified lines | ||
| 145 | 145 | merge = ["tree-editor", "blob-diff", "dep:gix-merge", "attributes"] |
| 146 | 146 | |
| 147 | 147 | ## Add blame command similar to `git blame`. |
| 148 | −blame = ["dep:gix-blame"] | |
| 148 | +blame = ["dep:gix-blame", "blob-diff"] | |
| 149 | 149 | |
| 150 | 150 | ## Make it possible to turn a tree into a stream of bytes, which can be decoded to entries and turned into various other formats. |
| 151 | 151 | worktree-stream = ["gix-worktree-stream", "attributes"] |
| @@ -13,11 +13,30 @@ impl Repository { · 12 unmodified lines | ||
| 13 | 13 | &self, |
| 14 | 14 | file_path: &BStr, |
| 15 | 15 | suspect: impl Into<ObjectId>, |
| 16 | − options: gix_blame::Options, | |
| 16 | + options: blame_file::Options, | |
| 17 | 17 | ) -> Result<gix_blame::Outcome, blame_file::Error> { |
| 18 | − let cache: Option<gix_commitgraph::Graph> = self.commit_graph_if_enabled()?; | |
| 18 | + let cache = self.commit_graph_if_enabled()?; | |
| 19 | 19 | let mut resource_cache = self.diff_resource_cache_for_tree_diff()?; |
| 20 | 20 | |
| 21 | + let blame_file::Options { | |
| 22 | + diff_algorithm, | |
| 23 | + ranges, | |
| 24 | + since, | |
| 25 | + rewrites, | |
| 26 | + } = options; | |
| 27 | + let diff_algorithm = match diff_algorithm { | |
| 28 | + Some(diff_algorithm) => diff_algorithm, | |
| 29 | + None => self.diff_algorithm()?, | |
| 30 | + }; | |
| 31 | + | |
| 32 | + let options = gix_blame::Options { | |
| 33 | + diff_algorithm, | |
| 34 | + ranges, | |
| 35 | + since, | |
| 36 | + rewrites, | |
| 37 | + debug_track_path: false, | |
| 38 | + }; | |
| 39 | + | |
| 21 | 40 | let outcome = gix_blame::file( |
| 22 | 41 | &self.objects, |
| 23 | 42 | suspect.into(), |
| @@ -19,6 +19,7 @@ pub enum Kind { · 18 unmodified lines | ||
| 19 | 19 | |
| 20 | 20 | #[cfg(any(feature = "attributes", feature = "excludes"))] |
| 21 | 21 | pub mod attributes; |
| 22 | +/// | |
| 22 | 23 | #[cfg(feature = "blame")] |
| 23 | 24 | mod blame; |
| 24 | 25 | mod cache; |
| @@ -96,6 +97,19 @@ mod new_commit_as { · 71 unmodified lines | ||
| 96 | 97 | /// |
| 97 | 98 | #[cfg(feature = "blame")] |
| 98 | 99 | pub mod blame_file { |
| 100 | + /// Options to be passed to [Repository::blame_file()](crate::Repository::blame_file()). | |
| 101 | + #[derive(Default, Debug, Clone)] | |
| 102 | + pub struct Options { | |
| 103 | + /// The algorithm to use for diffing. If `None`, `diff.algorithm` will be used. | |
| 104 | + pub diff_algorithm: Option<gix_diff::blob::Algorithm>, | |
| 105 | + /// The ranges to blame in the file. | |
| 106 | + pub ranges: gix_blame::BlameRanges, | |
| 107 | + /// Don't consider commits before the given date. | |
| 108 | + pub since: Option<gix_date::Time>, | |
| 109 | + /// Determine if rename tracking should be performed, and how. | |
| 110 | + pub rewrites: Option<gix_diff::Rewrites>, | |
| 111 | + } | |
| 112 | + | |
| 99 | 113 | /// The error returned by [Repository::blame_file()](crate::Repository::blame_file()). |
| 100 | 114 | #[derive(Debug, thiserror::Error)] |
| 101 | 115 | #[allow(missing_docs)] |
| @@ -103,6 +117,8 @@ pub mod blame_file { · 1 unmodified line | ||
| 103 | 117 | #[error(transparent)] |
| 104 | 118 | CommitGraphIfEnabled(#[from] super::commit_graph_if_enabled::Error), |
| 105 | 119 | #[error(transparent)] |
| 120 | + DiffAlgorithm(#[from] crate::config::diff::algorithm::Error), | |
| 121 | + #[error(transparent)] | |
| 106 | 122 | DiffResourceCache(#[from] super::diff_resource_cache::Error), |
| 107 | 123 | #[error(transparent)] |
| 108 | 124 | Blame(#[from] gix_blame::Error), |
| @@ -17,7 +17,7 @@ fn simple() -> crate::Result { · 16 unmodified lines | ||
| 17 | 17 | fn with_options() -> crate::Result { |
| 18 | 18 | let repo = crate::named_repo("make_blame_repo.sh")?; |
| 19 | 19 | |
| 20 | − let options = gix::blame::Options { | |
| 20 | + let options = gix::repository::blame_file::Options { | |
| 21 | 21 | ranges: gix::blame::BlameRanges::from_one_based_inclusive_range(1..=2)?, |
| 22 | 22 | ..Default::default() |
| 23 | 23 | }; |
| @@ -1,5 +1,10 @@ | ||
| 1 | 1 | # Must be sourced into the main journey test |
| 2 | 2 | |
| 3 | + | |
| 4 | +function remove-thread-id { | |
| 5 | + sed -E 's/ \([0-9]+\)//' | |
| 6 | +} | |
| 7 | + | |
| 3 | 8 | if test "$kind" = "max" || test "$kind" = "max-pure"; then |
| 4 | 9 | title "Porcelain ${kind}" |
| 5 | 10 | ( |
| @@ -8,21 +13,24 @@ title "Porcelain ${kind}" · 2 unmodified lines | ||
| 8 | 13 | (with "the --quiet option set" |
| 9 | 14 | it "fails as expected" && { |
| 10 | 15 | WITH_SNAPSHOT="$snapshot/expected-failure" \ |
| 11 | − expect_run_sh 101 "$exe -q panic" | |
| 16 | + SNAPSHOT_FILTER=remove-thread-id \ | |
| 17 | + expect_run_sh 0 "$exe -q panic" | |
| 12 | 18 | } |
| 13 | 19 | ) |
| 14 | 20 | |
| 15 | 21 | (with "NO --quiet option set" |
| 16 | 22 | it "fails as expected" && { |
| 17 | 23 | WITH_SNAPSHOT="$snapshot/expected-failure-in-thread" \ |
| 18 | − expect_run_sh 101 "$exe panic" | |
| 24 | + SNAPSHOT_FILTER=remove-thread-id \ | |
| 25 | + expect_run_sh 0 "$exe panic" | |
| 19 | 26 | } |
| 20 | 27 | ) |
| 21 | 28 | (not_on_ci # due to different TTY settings, the output differs, it's OK for now |
| 22 | 29 | (with "progress option set" |
| 23 | 30 | it "fails as expected" && { |
| 24 | 31 | WITH_SNAPSHOT="$snapshot/expected-failure-in-thread-with-progress" \ |
| 25 | − expect_run_sh 101 "$exe --progress panic" | |
| 32 | + SNAPSHOT_FILTER=remove-thread-id \ | |
| 33 | + expect_run_sh 0 "$exe --progress panic" | |
| 26 | 34 | } |
| 27 | 35 | ) |
| 28 | 36 | ) |