Skip to content

Commit

Permalink
feat: Add blob::pipeline::WorktreeRoots::is_unset()
Browse files Browse the repository at this point in the history
That way it's easy to determine if a worktree root has any root set.
  • Loading branch information
Byron committed Sep 13, 2024
1 parent 1d3d258 commit 56fe2b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion gix-diff/src/blob/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct WorktreeRoots {
pub new_root: Option<PathBuf>,
}

/// Access
impl WorktreeRoots {
/// Return the root path for the given `kind`
pub fn by_kind(&self, kind: ResourceKind) -> Option<&Path> {
Expand All @@ -30,6 +31,11 @@ impl WorktreeRoots {
ResourceKind::NewOrDestination => self.new_root.as_deref(),
}
}

/// Return `true` if all worktree roots are unset.
pub fn is_unset(&self) -> bool {
self.new_root.is_none() && self.old_root.is_none()
}
}

/// Data as part of an [Outcome].
Expand Down Expand Up @@ -184,6 +190,8 @@ impl Pipeline {
/// Access
impl Pipeline {
/// Return all drivers that this instance was initialized with.
///
/// They are sorted by [`name`](Driver::name) to support binary searches.
pub fn drivers(&self) -> &[super::Driver] {
&self.drivers
}
Expand Down Expand Up @@ -445,7 +453,7 @@ impl Pipeline {
}
}
.map_err(|err| {
convert_to_diffable::Error::CreateTempfile {
convert_to_diffable::Error::StreamCopy {
source: err,
rela_path: rela_path.to_owned(),
}
Expand Down Expand Up @@ -533,6 +541,10 @@ impl Driver {
pub fn prepare_binary_to_text_cmd(&self, path: &Path) -> Option<std::process::Command> {
let command: &BStr = self.binary_to_text_command.as_ref()?.as_ref();
let cmd = gix_command::prepare(gix_path::from_bstr(command).into_owned())
// This program intentionally doesn't get the whole Git context.
// In fact, when checked it only saw the `GIT_EXEC_PATH` and `COLORTERM` environment variables, nothing more.
// We by default let it inherit the entire environment. On Windows, Git seems to add the env though.
.with_context(Default::default())
.with_shell()
.stdin(Stdio::null())
.stdout(Stdio::piped())
Expand Down
2 changes: 1 addition & 1 deletion gix-diff/src/blob/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub mod prepare_diff {

use crate::blob::platform::Resource;

/// The kind of operation that was performed during the [`diff`](super::Platform::prepare_diff()) operation.
/// The kind of operation that should be performed based on the configuration of the resources involved in the diff.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum Operation<'a> {
/// The [internal diff algorithm](imara_diff::diff) should be called with the provided arguments.
Expand Down

0 comments on commit 56fe2b0

Please sign in to comment.