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
145merge = ["tree-editor", "blob-diff", "dep:gix-merge", "attributes"]145merge = ["tree-editor", "blob-diff", "dep:gix-merge", "attributes"]
146 146
147## Add blame command similar to `git blame`.147## Add blame command similar to `git blame`.
148blame = ["dep:gix-blame"]148blame = ["dep:gix-blame", "blob-diff"]
149 149
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.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.
151worktree-stream = ["gix-worktree-stream", "attributes"]151worktree-stream = ["gix-worktree-stream", "attributes"]
gix/src/repository/blame.rs+21−2
@@ -13,11 +13,30 @@ impl Repository { · 12 unmodified lines
13 &self,13 &self,
14 file_path: &BStr,14 file_path: &BStr,
15 suspect: impl Into<ObjectId>,15 suspect: impl Into<ObjectId>,
16 options: gix_blame::Options,16 options: blame_file::Options,
17 ) -> Result<gix_blame::Outcome, blame_file::Error> {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 let mut resource_cache = self.diff_resource_cache_for_tree_diff()?;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 let outcome = gix_blame::file(40 let outcome = gix_blame::file(
22 &self.objects,41 &self.objects,
23 suspect.into(),42 suspect.into(),
gix/src/repository/mod.rs+16−0
@@ -19,6 +19,7 @@ pub enum Kind { · 18 unmodified lines
19 19
20#[cfg(any(feature = "attributes", feature = "excludes"))]20#[cfg(any(feature = "attributes", feature = "excludes"))]
21pub mod attributes;21pub mod attributes;
22///
22#[cfg(feature = "blame")]23#[cfg(feature = "blame")]
23mod blame;24mod blame;
24mod cache;25mod cache;
@@ -96,6 +97,19 @@ mod new_commit_as { · 71 unmodified lines
96///97///
97#[cfg(feature = "blame")]98#[cfg(feature = "blame")]
98pub mod blame_file {99pub 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 /// The error returned by [Repository::blame_file()](crate::Repository::blame_file()).113 /// The error returned by [Repository::blame_file()](crate::Repository::blame_file()).
100 #[derive(Debug, thiserror::Error)]114 #[derive(Debug, thiserror::Error)]
101 #[allow(missing_docs)]115 #[allow(missing_docs)]
@@ -103,6 +117,8 @@ pub mod blame_file { · 1 unmodified line
103 #[error(transparent)]117 #[error(transparent)]
104 CommitGraphIfEnabled(#[from] super::commit_graph_if_enabled::Error),118 CommitGraphIfEnabled(#[from] super::commit_graph_if_enabled::Error),
105 #[error(transparent)]119 #[error(transparent)]
120 DiffAlgorithm(#[from] crate::config::diff::algorithm::Error),
121 #[error(transparent)]
106 DiffResourceCache(#[from] super::diff_resource_cache::Error),122 DiffResourceCache(#[from] super::diff_resource_cache::Error),
107 #[error(transparent)]123 #[error(transparent)]
108 Blame(#[from] gix_blame::Error),124 Blame(#[from] gix_blame::Error),
gix/tests/gix/repository/blame.rs+1−1
@@ -17,7 +17,7 @@ fn simple() -> crate::Result { · 16 unmodified lines
17fn with_options() -> crate::Result {17fn with_options() -> crate::Result {
18 let repo = crate::named_repo("make_blame_repo.sh")?;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 ranges: gix::blame::BlameRanges::from_one_based_inclusive_range(1..=2)?,21 ranges: gix::blame::BlameRanges::from_one_based_inclusive_range(1..=2)?,
22 ..Default::default()22 ..Default::default()
23 };23 };
tests/journey/ein.sh+11−3
@@ -1,5 +1,10 @@
1# Must be sourced into the main journey test1# Must be sourced into the main journey test
2 2
3
4function remove-thread-id {
5 sed -E 's/ \([0-9]+\)//'
6}
7
3if test "$kind" = "max" || test "$kind" = "max-pure"; then8if test "$kind" = "max" || test "$kind" = "max-pure"; then
4title "Porcelain ${kind}"9title "Porcelain ${kind}"
5(10(
@@ -8,21 +13,24 @@ title "Porcelain ${kind}" · 2 unmodified lines
8 (with "the --quiet option set"13 (with "the --quiet option set"
9 it "fails as expected" && {14 it "fails as expected" && {
10 WITH_SNAPSHOT="$snapshot/expected-failure" \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 (with "NO --quiet option set"21 (with "NO --quiet option set"
16 it "fails as expected" && {22 it "fails as expected" && {
17 WITH_SNAPSHOT="$snapshot/expected-failure-in-thread" \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 (not_on_ci # due to different TTY settings, the output differs, it's OK for now28 (not_on_ci # due to different TTY settings, the output differs, it's OK for now
22 (with "progress option set"29 (with "progress option set"
23 it "fails as expected" && {30 it "fails as expected" && {
24 WITH_SNAPSHOT="$snapshot/expected-failure-in-thread-with-progress" \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 )