History

Merge pull request #2240 from cruessler/add-gix-repository-blame-options

fix!: respect `diff.algorithm` in `Repository::blame_file`

Sebastian Thiel committed 1 year ago

Commit 385ab162 parents 663b41e adc36245 files · +50 −7Browse files

Unified · Split

5 files
  1. gix/Cargo.toml +1 −1
  2. gix/src/repository/blame.rs +21 −2
  3. gix/src/repository/mod.rs +16 −0
  4. gix/tests/gix/repository/blame.rs +1 −1
  5. tests/journey/ein.sh +11 −3
gix/Cargo.toml+1−1
@@ -145,7 +145,7 @@ blob-diff = ["gix-diff/blob", "attributes"] · 144 unmodified lines
145145 merge = ["tree-editor", "blob-diff", "dep:gix-merge", "attributes"]
146146
147147 ## Add blame command similar to `git blame`.
148−blame = ["dep:gix-blame"]
148+blame = ["dep:gix-blame", "blob-diff"]
149149
150150 ## Make it possible to turn a tree into a stream of bytes, which can be decoded to entries and turned into various other formats.
151151 worktree-stream = ["gix-worktree-stream", "attributes"]
gix/src/repository/blame.rs+21−2
@@ -13,11 +13,30 @@ impl Repository { · 12 unmodified lines
1313 &self,
1414 file_path: &BStr,
1515 suspect: impl Into<ObjectId>,
16− options: gix_blame::Options,
16+ options: blame_file::Options,
1717 ) -> 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()?;
1919 let mut resource_cache = self.diff_resource_cache_for_tree_diff()?;
2020
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+
2140 let outcome = gix_blame::file(
2241 &self.objects,
2342 suspect.into(),
gix/src/repository/mod.rs+16−0
@@ -19,6 +19,7 @@ pub enum Kind { · 18 unmodified lines
1919
2020 #[cfg(any(feature = "attributes", feature = "excludes"))]
2121 pub mod attributes;
22+///
2223 #[cfg(feature = "blame")]
2324 mod blame;
2425 mod cache;
@@ -96,6 +97,19 @@ mod new_commit_as { · 71 unmodified lines
9697 ///
9798 #[cfg(feature = "blame")]
9899 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+
99113 /// The error returned by [Repository::blame_file()](crate::Repository::blame_file()).
100114 #[derive(Debug, thiserror::Error)]
101115 #[allow(missing_docs)]
@@ -103,6 +117,8 @@ pub mod blame_file { · 1 unmodified line
103117 #[error(transparent)]
104118 CommitGraphIfEnabled(#[from] super::commit_graph_if_enabled::Error),
105119 #[error(transparent)]
120+ DiffAlgorithm(#[from] crate::config::diff::algorithm::Error),
121+ #[error(transparent)]
106122 DiffResourceCache(#[from] super::diff_resource_cache::Error),
107123 #[error(transparent)]
108124 Blame(#[from] gix_blame::Error),
gix/tests/gix/repository/blame.rs+1−1
@@ -17,7 +17,7 @@ fn simple() -> crate::Result { · 16 unmodified lines
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_file::Options {
2121 ranges: gix::blame::BlameRanges::from_one_based_inclusive_range(1..=2)?,
2222 ..Default::default()
2323 };
tests/journey/ein.sh+11−3
@@ -1,5 +1,10 @@
11 # Must be sourced into the main journey test
22
3+
4+function remove-thread-id {
5+ sed -E 's/ \([0-9]+\)//'
6+}
7+
38 if test "$kind" = "max" || test "$kind" = "max-pure"; then
49 title "Porcelain ${kind}"
510 (
@@ -8,21 +13,24 @@ title "Porcelain ${kind}" · 2 unmodified lines
813 (with "the --quiet option set"
914 it "fails as expected" && {
1015 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"
1218 }
1319 )
1420
1521 (with "NO --quiet option set"
1622 it "fails as expected" && {
1723 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"
1926 }
2027 )
2128 (not_on_ci # due to different TTY settings, the output differs, it's OK for now
2229 (with "progress option set"
2330 it "fails as expected" && {
2431 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"
2634 }
2735 )
2836 )