Skip to content

Commit

Permalink
Merge branch 'patch-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Dec 12, 2023
2 parents 7549559 + 3f84213 commit 20dce42
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 6 deletions.
5 changes: 4 additions & 1 deletion gix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ comfort = ["gix-features/progress-unit-bytes", "gix-features/progress-unit-human
#! A component is a distinct feature which may be comprised of one or more methods around a particular topic.
#! Providers of libraries should only activate the components they need.

## Provide a top-level `command` module that helps with spawning commands similarly to `git`.
command = ["dep:gix-command"]

## Obtain information similar to `git status`.
status = ["gix-status"]

Expand All @@ -81,7 +84,7 @@ worktree-mutation = ["attributes", "dep:gix-worktree-state"]
excludes = ["dep:gix-ignore", "dep:gix-worktree", "index"]

## Query attributes and excludes. Enables access to pathspecs, worktree checkouts, filter-pipelines and submodules.
attributes = ["excludes", "dep:gix-filter", "dep:gix-pathspec", "dep:gix-attributes", "dep:gix-submodule", "gix-worktree?/attributes", "dep:gix-command"]
attributes = ["excludes", "dep:gix-filter", "dep:gix-pathspec", "dep:gix-attributes", "dep:gix-submodule", "gix-worktree?/attributes", "command"]

## Add support for mailmaps, as way of determining the final name of commmiters and authors.
mailmap = ["dep:gix-mailmap", "revision"]
Expand Down
16 changes: 16 additions & 0 deletions gix/src/config/snapshot/access.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(clippy::result_large_err)]
use std::borrow::Cow;
use std::ffi::OsStr;

use gix_features::threading::OwnShared;
use gix_macros::momo;
Expand Down Expand Up @@ -68,6 +69,21 @@ impl<'repo> Snapshot<'repo> {
.config
.trusted_file_path(key.section_name, key.subsection_name, key.value_name)
}

/// Return the trusted string at `key` for launching using [command::prepare()](gix_command::prepare()),
/// or `None` if there is no such value or if no value was found in a trusted file.
#[momo]
pub fn trusted_program<'a>(&self, key: impl Into<&'a BStr>) -> Option<Cow<'repo, OsStr>> {
let value = self
.repo
.config
.resolved
.string_filter_by_key(key, &mut self.repo.config.filter_config_section.clone())?;
Some(match gix_path::from_bstr(value) {
Cow::Borrowed(v) => Cow::Borrowed(v.as_os_str()),
Cow::Owned(v) => Cow::Owned(v.into_os_string()),
})
}
}

/// Utilities and additional access
Expand Down
10 changes: 10 additions & 0 deletions gix/src/config/tree/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,19 @@ pub type RemoteName = Any<validate::RemoteName>;
pub type Boolean = Any<validate::Boolean>;

/// A key that represents an executable program, shell script or shell commands.
///
/// Once obtained with [trusted_program()](crate::config::Snapshot::trusted_program())
/// one can run it with [command::prepare()](gix_command::prepare), possibly after
/// [obtaining](crate::Repository::command_context) and [setting](gix_command::Prepare::with_context)
/// a git [command context](gix_command::Context) (depending on the commands needs).
pub type Program = Any<validate::Program>;

/// A key that represents an executable program as identified by name or path.
///
/// Once obtained with [trusted_program()](crate::config::Snapshot::trusted_program())
/// one can run it with [command::prepare()](gix_command::prepare), possibly after
/// [obtaining](crate::Repository::command_context) and [setting](gix_command::Prepare::with_context)
/// a git [command context](gix_command::Context) (depending on the commands needs).
pub type Executable = Any<validate::Executable>;

/// A key that represents a path (to a resource).
Expand Down
9 changes: 6 additions & 3 deletions gix/src/config/tree/sections/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ impl Core {
/// The `core.disambiguate` key.
pub const DISAMBIGUATE: Disambiguate =
Disambiguate::new_with_validate("disambiguate", &config::Tree::CORE, validate::Disambiguate);
/// The `core.editor` key.
pub const EDITOR: keys::Program = keys::Program::new_program("editor", &config::Tree::CORE);
/// The `core.fileMode` key.
pub const FILE_MODE: keys::Boolean = keys::Boolean::new_boolean("fileMode", &config::Tree::CORE);
/// The `core.ignoreCase` key.
Expand Down Expand Up @@ -58,10 +60,10 @@ impl Core {
.with_environment_override("GIT_ASKPASS")
.with_note("fallback is 'SSH_ASKPASS'");
/// The `core.excludesFile` key.
pub const EXCLUDES_FILE: keys::Executable = keys::Executable::new_executable("excludesFile", &config::Tree::CORE);
pub const EXCLUDES_FILE: keys::Path = keys::Path::new_path("excludesFile", &config::Tree::CORE);
/// The `core.attributesFile` key.
pub const ATTRIBUTES_FILE: keys::Executable =
keys::Executable::new_executable("attributesFile", &config::Tree::CORE)
pub const ATTRIBUTES_FILE: keys::Path =
keys::Path::new_path("attributesFile", &config::Tree::CORE)
.with_deviation("for checkout - it's already queried but needs building of attributes group, and of course support during checkout");
/// The `core.sshCommand` key.
pub const SSH_COMMAND: keys::Executable = keys::Executable::new_executable("sshCommand", &config::Tree::CORE)
Expand Down Expand Up @@ -102,6 +104,7 @@ impl Section for Core {
&Self::CHECK_STAT,
&Self::DELTA_BASE_CACHE_LIMIT,
&Self::DISAMBIGUATE,
&Self::EDITOR,
&Self::FILE_MODE,
&Self::IGNORE_CASE,
&Self::FILES_REF_LOCK_TIMEOUT,
Expand Down
4 changes: 2 additions & 2 deletions gix/src/config/tree/sections/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ impl Diff {
pub const RENAMES: Renames = Renames::new_renames("renames", &config::Tree::DIFF);

/// The `diff.<driver>.command` key.
pub const DRIVER_COMMAND: keys::String = keys::String::new_string("command", &config::Tree::DIFF)
pub const DRIVER_COMMAND: keys::Program = keys::Program::new_program("command", &config::Tree::DIFF)
.with_subsection_requirement(Some(SubSectionRequirement::Parameter("driver")));
/// The `diff.<driver>.textconv` key.
pub const DRIVER_TEXTCONV: keys::String = keys::String::new_string("textconv", &config::Tree::DIFF)
pub const DRIVER_TEXTCONV: keys::Program = keys::Program::new_program("textconv", &config::Tree::DIFF)
.with_subsection_requirement(Some(SubSectionRequirement::Parameter("driver")));
/// The `diff.<driver>.algorithm` key.
pub const DRIVER_ALGORITHM: Algorithm =
Expand Down
2 changes: 2 additions & 0 deletions gix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
pub use gix_actor as actor;
#[cfg(feature = "attributes")]
pub use gix_attributes as attrs;
#[cfg(feature = "command")]
pub use gix_command as command;
pub use gix_commitgraph as commitgraph;
#[cfg(feature = "credentials")]
pub use gix_credentials as credentials;
Expand Down

0 comments on commit 20dce42

Please sign in to comment.