Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
23 changes: 21 additions & 2 deletions gix/src/repository/blame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,30 @@ impl Repository {
&self,
file_path: &BStr,
suspect: impl Into<ObjectId>,
options: gix_blame::Options,
options: blame_file::Options,
) -> Result<gix_blame::Outcome, blame_file::Error> {
let cache: Option<gix_commitgraph::Graph> = 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(),
Expand Down
16 changes: 16 additions & 0 deletions gix/src/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum Kind {

#[cfg(any(feature = "attributes", feature = "excludes"))]
pub mod attributes;
///
#[cfg(feature = "blame")]
mod blame;
mod cache;
Expand Down Expand Up @@ -96,13 +97,28 @@ 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<gix_diff::blob::Algorithm>,
/// The ranges to blame in the file.
pub ranges: gix_blame::BlameRanges,
/// Don't consider commits before the given date.
pub since: Option<gix_date::Time>,
/// Determine if rename tracking should be performed, and how.
pub rewrites: Option<gix_diff::Rewrites>,
}

/// The error returned by [Repository::blame_file()](crate::Repository::blame_file()).
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[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),
Expand Down
2 changes: 1 addition & 1 deletion gix/tests/gix/repository/blame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down
14 changes: 11 additions & 3 deletions tests/journey/ein.sh
Original file line number Diff line number Diff line change
@@ -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}"
(
Expand All @@ -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"
}
)
)
Expand Down
Loading