Skip to content

Commit 20dce42

Browse files
committed
Merge branch 'patch-1'
2 parents 7549559 + 3f84213 commit 20dce42

File tree

6 files changed

+40
-6
lines changed

6 files changed

+40
-6
lines changed

gix/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ comfort = ["gix-features/progress-unit-bytes", "gix-features/progress-unit-human
6161
#! A component is a distinct feature which may be comprised of one or more methods around a particular topic.
6262
#! Providers of libraries should only activate the components they need.
6363

64+
## Provide a top-level `command` module that helps with spawning commands similarly to `git`.
65+
command = ["dep:gix-command"]
66+
6467
## Obtain information similar to `git status`.
6568
status = ["gix-status"]
6669

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

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

8689
## Add support for mailmaps, as way of determining the final name of commmiters and authors.
8790
mailmap = ["dep:gix-mailmap", "revision"]

gix/src/config/snapshot/access.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![allow(clippy::result_large_err)]
22
use std::borrow::Cow;
3+
use std::ffi::OsStr;
34

45
use gix_features::threading::OwnShared;
56
use gix_macros::momo;
@@ -68,6 +69,21 @@ impl<'repo> Snapshot<'repo> {
6869
.config
6970
.trusted_file_path(key.section_name, key.subsection_name, key.value_name)
7071
}
72+
73+
/// Return the trusted string at `key` for launching using [command::prepare()](gix_command::prepare()),
74+
/// or `None` if there is no such value or if no value was found in a trusted file.
75+
#[momo]
76+
pub fn trusted_program<'a>(&self, key: impl Into<&'a BStr>) -> Option<Cow<'repo, OsStr>> {
77+
let value = self
78+
.repo
79+
.config
80+
.resolved
81+
.string_filter_by_key(key, &mut self.repo.config.filter_config_section.clone())?;
82+
Some(match gix_path::from_bstr(value) {
83+
Cow::Borrowed(v) => Cow::Borrowed(v.as_os_str()),
84+
Cow::Owned(v) => Cow::Owned(v.into_os_string()),
85+
})
86+
}
7187
}
7288

7389
/// Utilities and additional access

gix/src/config/tree/keys.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,19 @@ pub type RemoteName = Any<validate::RemoteName>;
165165
pub type Boolean = Any<validate::Boolean>;
166166

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

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

173183
/// A key that represents a path (to a resource).

gix/src/config/tree/sections/core.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ impl Core {
2222
/// The `core.disambiguate` key.
2323
pub const DISAMBIGUATE: Disambiguate =
2424
Disambiguate::new_with_validate("disambiguate", &config::Tree::CORE, validate::Disambiguate);
25+
/// The `core.editor` key.
26+
pub const EDITOR: keys::Program = keys::Program::new_program("editor", &config::Tree::CORE);
2527
/// The `core.fileMode` key.
2628
pub const FILE_MODE: keys::Boolean = keys::Boolean::new_boolean("fileMode", &config::Tree::CORE);
2729
/// The `core.ignoreCase` key.
@@ -58,10 +60,10 @@ impl Core {
5860
.with_environment_override("GIT_ASKPASS")
5961
.with_note("fallback is 'SSH_ASKPASS'");
6062
/// The `core.excludesFile` key.
61-
pub const EXCLUDES_FILE: keys::Executable = keys::Executable::new_executable("excludesFile", &config::Tree::CORE);
63+
pub const EXCLUDES_FILE: keys::Path = keys::Path::new_path("excludesFile", &config::Tree::CORE);
6264
/// The `core.attributesFile` key.
63-
pub const ATTRIBUTES_FILE: keys::Executable =
64-
keys::Executable::new_executable("attributesFile", &config::Tree::CORE)
65+
pub const ATTRIBUTES_FILE: keys::Path =
66+
keys::Path::new_path("attributesFile", &config::Tree::CORE)
6567
.with_deviation("for checkout - it's already queried but needs building of attributes group, and of course support during checkout");
6668
/// The `core.sshCommand` key.
6769
pub const SSH_COMMAND: keys::Executable = keys::Executable::new_executable("sshCommand", &config::Tree::CORE)
@@ -102,6 +104,7 @@ impl Section for Core {
102104
&Self::CHECK_STAT,
103105
&Self::DELTA_BASE_CACHE_LIMIT,
104106
&Self::DISAMBIGUATE,
107+
&Self::EDITOR,
105108
&Self::FILE_MODE,
106109
&Self::IGNORE_CASE,
107110
&Self::FILES_REF_LOCK_TIMEOUT,

gix/src/config/tree/sections/diff.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ impl Diff {
1919
pub const RENAMES: Renames = Renames::new_renames("renames", &config::Tree::DIFF);
2020

2121
/// The `diff.<driver>.command` key.
22-
pub const DRIVER_COMMAND: keys::String = keys::String::new_string("command", &config::Tree::DIFF)
22+
pub const DRIVER_COMMAND: keys::Program = keys::Program::new_program("command", &config::Tree::DIFF)
2323
.with_subsection_requirement(Some(SubSectionRequirement::Parameter("driver")));
2424
/// The `diff.<driver>.textconv` key.
25-
pub const DRIVER_TEXTCONV: keys::String = keys::String::new_string("textconv", &config::Tree::DIFF)
25+
pub const DRIVER_TEXTCONV: keys::Program = keys::Program::new_program("textconv", &config::Tree::DIFF)
2626
.with_subsection_requirement(Some(SubSectionRequirement::Parameter("driver")));
2727
/// The `diff.<driver>.algorithm` key.
2828
pub const DRIVER_ALGORITHM: Algorithm =

gix/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@
9595
pub use gix_actor as actor;
9696
#[cfg(feature = "attributes")]
9797
pub use gix_attributes as attrs;
98+
#[cfg(feature = "command")]
99+
pub use gix_command as command;
98100
pub use gix_commitgraph as commitgraph;
99101
#[cfg(feature = "credentials")]
100102
pub use gix_credentials as credentials;

0 commit comments

Comments
 (0)