Struct git_repository::config::Snapshot
source · [−]pub struct Snapshot<'repo> { /* private fields */ }
Expand description
A platform to access configuration values as read from disk.
Note that these values won’t update even if the underlying file(s) change.
Implementations
sourceimpl<'repo> Snapshot<'repo>
impl<'repo> Snapshot<'repo>
Access configuration values, frozen in time, using a key
which is a .
separated string of up to
three tokens, namely section_name.[subsection_name.]value_name
, like core.bare
or remote.origin.url
.
Note that single-value methods always return the last value found, which is the one set most recently in the hierarchy of configuration files, aka ‘last one wins’.
sourcepub fn boolean(&self, key: &str) -> Option<bool>
pub fn boolean(&self, key: &str) -> Option<bool>
Return the boolean at key
, or None
if there is no such value or if the value can’t be interpreted as
boolean.
For a non-degenerating version, use try_boolean(…)
.
Note that this method takes the most recent value at key
even if it is from a file with reduced trust.
sourcepub fn try_boolean(&self, key: &str) -> Option<Result<bool, Error>>
pub fn try_boolean(&self, key: &str) -> Option<Result<bool, Error>>
Like boolean()
, but it will report an error if the value couldn’t be interpreted as boolean.
sourcepub fn integer(&self, key: &str) -> Option<i64>
pub fn integer(&self, key: &str) -> Option<i64>
Return the resolved integer at key
, or None
if there is no such value or if the value can’t be interpreted as
integer or exceeded the value range.
For a non-degenerating version, use try_integer(…)
.
Note that this method takes the most recent value at key
even if it is from a file with reduced trust.
sourcepub fn try_integer(&self, key: &str) -> Option<Result<i64, Error>>
pub fn try_integer(&self, key: &str) -> Option<Result<i64, Error>>
Like integer()
, but it will report an error if the value couldn’t be interpreted as boolean.
sourceimpl Snapshot<'_>
impl Snapshot<'_>
sourcepub fn credential_helpers(
&self,
url: Url
) -> Result<(Cascade, Action, Options<'static>), Error>
pub fn credential_helpers(
&self,
url: Url
) -> Result<(Cascade, Action, Options<'static>), Error>
Returns the configuration for all git-credential helpers from trusted configuration that apply
to the given url
along with an action preconfigured to invoke the cascade with.
This includes url
which may be altered to contain a user-name as configured.
These can be invoked to obtain credentials. Note that the url
is expected to be the one used
to connect to a remote, and thus should already have passed the url-rewrite engine.
Deviation
- Invalid urls can’t be used to obtain credential helpers as they are rejected early when creating a valid
url
here. - Parsed urls will automatically drop the port if it’s the default, i.e.
http://host:80
becomeshttp://host
when parsed. This affects the prompt provided to the user, so that git will use the verbatim url, whereas we usehttp://host
. - Upper-case scheme and host will be lower-cased automatically when parsing into a url, so prompts differ compared to git.
- A difference in prompt might affect the matching of getting existing stored credentials, and it’s a question of this being a feature or a bug.