| 1 |
mod remoterust-analyzer cargo git-delta 0.19.2 git_config/remote/; |
| 2 |
|
| 3 |
pub use remoterust-analyzer cargo git-delta 0.19.2 git_config/remote/::GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#; |
| 4 |
|
| 5 |
use craterust-analyzer cargo git-delta 0.19.2 crate/::envrust-analyzer cargo git-delta 0.19.2 env/::DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#; |
| 6 |
use regexrust-analyzer cargo regex 1.12.3 crate/::Regexrust-analyzer cargo regex 1.12.3 regex/string/Regex#; |
| 7 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::OnceCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/OnceCell#; |
| 8 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#; |
| 9 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#; |
| 10 |
|
| 11 |
use lazy_staticrust-analyzer cargo lazy_static 1.4.0 crate/::lazy_staticrust-analyzer cargo lazy_static 1.4.0 lazy_static!; |
| 12 |
|
| 13 |
pub struct GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig# { |
| 14 |
configrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config.: git2rust-analyzer cargo git2 0.21.0 crate/::Configrust-analyzer cargo git2 0.21.0 config/Config#, |
| 15 |
config_from_env_varrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config_from_env_var.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 16 |
pub enabledrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#enabled.: bool, |
| 17 |
reporust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#repo.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<git2rust-analyzer cargo git2 0.21.0 crate/::Repositoryrust-analyzer cargo git2 0.21.0 repo/Repository#>, |
| 18 |
remote_urlrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#remote_url.: OnceCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/OnceCell#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#>>, |
| 19 |
// To make GitConfig cloneable when testing (in turn to make Config cloneable): |
| 20 |
#[cfg(test)] |
| 21 |
pathrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#path.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, |
| 22 |
} |
| 23 |
|
| 24 |
#[cfg(test)] |
| 25 |
impl Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# for GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig# { |
| 26 |
fn clonerust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig][Clone]clone().(&self) -> Selfrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig][Clone] { |
| 27 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(self.reporust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#repo..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()); |
| 28 |
GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig# { |
| 29 |
// Assumes no test modifies the file pointed to by `path` |
| 30 |
configrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config.: git2rust-analyzer cargo git2 0.21.0 crate/::Configrust-analyzer cargo git2 0.21.0 config/Config#::openrust-analyzer cargo git2 0.21.0 config/impl#[Config]open().(&self.pathrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#path.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 31 |
config_from_env_varrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config_from_env_var.: self.config_from_env_varrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config_from_env_var..clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][Clone]clone().(), |
| 32 |
enabledrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#enabled.: self.enabledrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#enabled., |
| 33 |
reporust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#repo.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 34 |
remote_urlrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#remote_url.: OnceCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/OnceCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/impl#[`OnceCell<T>`]new().(), |
| 35 |
pathrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#path.: self.pathrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#path..clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][Clone]clone().(), |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
impl GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig# { |
| 41 |
#[cfg(not(test))] |
| 42 |
pub fn try_create(env: &DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig]> { |
| 43 |
use craterust-analyzer cargo git-delta 0.19.2 crate/::fatalrust-analyzer cargo git-delta 0.19.2 fatal().; |
| 44 |
|
| 45 |
let repo = match &envrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/env!.current_dir { |
| 46 |
Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(dir) => git2rust-analyzer cargo git2 0.21.0 crate/::Repositoryrust-analyzer cargo git2 0.21.0 repo/Repository#::discover(dir).ok(), |
| 47 |
_ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 48 |
}; |
| 49 |
let config = match &repo { |
| 50 |
Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(repo) => repo.config().ok(), |
| 51 |
None => git2rust-analyzer cargo git2 0.21.0 crate/::Configrust-analyzer cargo git2 0.21.0 config/Config#::open_default().ok(), |
| 52 |
}; |
| 53 |
match config { |
| 54 |
Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(mut config) => { |
| 55 |
let config = config.snapshot().unwrap_or_else(|err| { |
| 56 |
fatal(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to read git config: {err}")); |
| 57 |
}); |
| 58 |
Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig] { |
| 59 |
config, |
| 60 |
config_from_env_var: parse_config_from_env_varrust-analyzer cargo git-delta 0.19.2 git_config/parse_config_from_env_var().(envrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/env!), |
| 61 |
repo, |
| 62 |
enabled: true, |
| 63 |
remote_url: OnceCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/OnceCell#::new(), |
| 64 |
}) |
| 65 |
} |
| 66 |
None => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
#[cfg(test)] |
| 71 |
pub fn try_createrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig]try_create().(_env: &DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig]> { |
| 72 |
// Do not read local git configs when testing |
| 73 |
Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 74 |
} |
| 75 |
|
| 76 |
#[cfg(test)] |
| 77 |
pub fn for_testingrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig]for_testing().() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig]> { |
| 78 |
Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig# { |
| 79 |
configrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config.: git2rust-analyzer cargo git2 0.21.0 crate/::Configrust-analyzer cargo git2 0.21.0 config/Config#::newrust-analyzer cargo git2 0.21.0 config/impl#[Config]new().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 80 |
config_from_env_varrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config_from_env_var.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().(), |
| 81 |
enabledrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#enabled.: true, |
| 82 |
reporust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#repo.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 83 |
remote_urlrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#remote_url.: OnceCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/OnceCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/impl#[`OnceCell<T>`]new().(), |
| 84 |
pathrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#path.: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().("/invalid_null.git"), |
| 85 |
}) |
| 86 |
} |
| 87 |
|
| 88 |
pub fn from_pathrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig]from_path().(env: &DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#, path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, honor_env_var: bool) -> Selfrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig] { |
| 89 |
use craterust-analyzer cargo git-delta 0.19.2 crate/::fatalrust-analyzer cargo git-delta 0.19.2 fatal().; |
| 90 |
|
| 91 |
match git2rust-analyzer cargo git2 0.21.0 crate/::Configrust-analyzer cargo git2 0.21.0 config/Config#::openrust-analyzer cargo git2 0.21.0 config/impl#[Config]open().(path) { |
| 92 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(mut config) => { |
| 93 |
let config = config.snapshotrust-analyzer cargo git2 0.21.0 config/impl#[Config]snapshot().().unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(|err| { |
| 94 |
fatalrust-analyzer cargo git-delta 0.19.2 fatal().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to read git config: {err}")); |
| 95 |
}); |
| 96 |
|
| 97 |
Selfrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig] { |
| 98 |
configrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config., |
| 99 |
config_from_env_varrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config_from_env_var.: if honor_env_var { |
| 100 |
parse_config_from_env_varrust-analyzer cargo git-delta 0.19.2 git_config/parse_config_from_env_var().(env) |
| 101 |
} else { |
| 102 |
HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().() |
| 103 |
}, |
| 104 |
reporust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#repo.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 105 |
enabledrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#enabled.: true, |
| 106 |
remote_urlrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#remote_url.: OnceCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/OnceCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/impl#[`OnceCell<T>`]new().(), |
| 107 |
#[cfg(test)] |
| 108 |
pathrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#path.: path.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 109 |
} |
| 110 |
} |
| 111 |
Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => { |
| 112 |
fatalrust-analyzer cargo git-delta 0.19.2 fatal().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Failed to read git config: {}", e.messagerust-analyzer cargo git2 0.21.0 error/impl#[Error]message().())); |
| 113 |
} |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
pub fn getrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig]get().<T>(&self, key: &str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> |
| 118 |
where |
| 119 |
T: GitConfigGetrust-analyzer cargo git-delta 0.19.2 git_config/GitConfigGet#, |
| 120 |
{ |
| 121 |
if self.enabledrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#enabled. { |
| 122 |
T::git_config_getrust-analyzer cargo git-delta 0.19.2 git_config/GitConfigGet#git_config_get().(key, self) |
| 123 |
} else { |
| 124 |
Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
#[cfg(test)] |
| 129 |
fn get_remote_url_implrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig]get_remote_url_impl().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#> { |
| 130 |
GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#::for_testingrust-analyzer cargo git-delta 0.19.2 git_config/remote/impl#[GitRemoteRepo]for_testing().() |
| 131 |
} |
| 132 |
|
| 133 |
#[cfg(not(test))] |
| 134 |
fn get_remote_url_impl(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#> { |
| 135 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#; |
| 136 |
selfrust-analyzer cargo git-delta 0.19.2 git_config/.repo |
| 137 |
.as_ref()? |
| 138 |
.find_remote("origin") |
| 139 |
.ok()? |
| 140 |
.url() |
| •141 |
.ok() |
| 142 |
.and_then(|url| GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#::from_str(url).ok()) |
| 143 |
} |
| 144 |
|
| 145 |
pub fn get_remote_urlrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig]get_remote_url().(&self) -> &Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<GitRemoteReporust-analyzer cargo git-delta 0.19.2 git_config/remote/GitRemoteRepo#> { |
| 146 |
self.remote_urlrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#remote_url..get_or_initrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/impl#[`OnceCell<T>`]get_or_init().(|| self.get_remote_url_implrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig]get_remote_url_impl().()) |
| 147 |
} |
| 148 |
|
| 149 |
pub fn for_eachrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig]for_each().<F>(&self, regex: &str, mut f: F) |
| 150 |
where |
| 151 |
F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&str, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>), |
| 152 |
{ |
| 153 |
let mut entries = self.configrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config..entriesrust-analyzer cargo git2 0.21.0 config/impl#[Config]entries().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(regex)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 154 |
while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(entry) = entries.nextrust-analyzer cargo git2 0.21.0 config/impl#[`ConfigEntries<'cfg>`]next().() { |
| 155 |
let entry = entry.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 156 |
let name = entry.namerust-analyzer cargo git2 0.21.0 config/impl#[`ConfigEntry<'cfg>`]name().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| •157 |
f(name, entry.valuerust-analyzer cargo git2 0.21.0 config/impl#[`ConfigEntry<'cfg>`]value().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()); |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
fn parse_config_from_env_varrust-analyzer cargo git-delta 0.19.2 git_config/parse_config_from_env_var().(env: &DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#) -> HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 163 |
if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s) = &env.git_config_parametersrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#git_config_parameters. { |
| 164 |
parse_config_from_env_var_valuerust-analyzer cargo git-delta 0.19.2 git_config/parse_config_from_env_var_value().(s) |
| 165 |
} else { |
| 166 |
HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().() |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
lazy_staticrust-analyzer cargo lazy_static 1.4.0 lazy_static!! { |
| 171 |
static ref GIT_CONFIG_PARAMETERS_REGEXrust-analyzer cargo git-delta 0.19.2 git_config/GIT_CONFIG_PARAMETERS_REGEX#: Regexrust-analyzer cargo regex 1.12.3 regex/string/Regex# = Regexrust-analyzer cargo regex 1.12.3 regex/string/Regex#::newrust-analyzer cargo regex 1.12.3 regex/string/impl#[Regex]new().( |
| 172 |
r"(?x) |
| 173 |
(?: # Non-capturing group containing union |
| 174 |
'(delta\.[a-z-]+)=([^']+)' # Git <2.31.0 format |
| 175 |
| |
| 176 |
'(delta\.[a-z-]+)'='([^']+)' # Git ≥2.31.0 format |
| 177 |
) |
| 178 |
" |
| 179 |
) |
| 180 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 181 |
} |
| 182 |
|
| 183 |
fn parse_config_from_env_var_valuerust-analyzer cargo git-delta 0.19.2 git_config/parse_config_from_env_var_value().(s: &str) -> HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 184 |
GIT_CONFIG_PARAMETERS_REGEXrust-analyzer cargo git-delta 0.19.2 git_config/GIT_CONFIG_PARAMETERS_REGEX. |
| 185 |
.captures_iterrust-analyzer cargo regex 1.12.3 regex/string/impl#[Regex]captures_iter().(s) |
| 186 |
.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|captures| { |
| 187 |
let (i, j) = match ( |
| 188 |
captures.getrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`]get().(1), |
| 189 |
captures.getrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`]get().(2), |
| 190 |
captures.getrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`]get().(3), |
| 191 |
captures.getrust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`]get().(4), |
| 192 |
) { |
| 193 |
(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => (1, 2), |
| 194 |
(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_)) => (3, 4), |
| 195 |
_ => (0, 0), |
| 196 |
}; |
| 197 |
if (i, j) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core tuple/impl#[`(U, T)`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core tuple/impl#[`(U, T)`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core tuple/impl#[`(U, T)`][`PartialEq<Self>`]eq().(0, 0) { |
| 198 |
("".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), "".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 199 |
} else { |
| 200 |
(captures[rust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`][`Index<usize>`]index().i]rust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`][`Index<usize>`]index()..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), captures[rust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`][`Index<usize>`]index().j]rust-analyzer cargo regex 1.12.3 regex/string/impl#[`Captures<'h>`][`Index<usize>`]index()..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()) |
| 201 |
} |
| 202 |
}) |
| 203 |
.collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().() |
| 204 |
} |
| 205 |
|
| 206 |
pub trait GitConfigGetrust-analyzer cargo git-delta 0.19.2 git_config/GitConfigGet# { |
| 207 |
fn git_config_getrust-analyzer cargo git-delta 0.19.2 git_config/GitConfigGet#git_config_get().(key: &str, git_config: &GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Self> |
| 208 |
where |
| 209 |
Self: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#; |
| 210 |
} |
| 211 |
|
| 212 |
impl GitConfigGetrust-analyzer cargo git-delta 0.19.2 git_config/GitConfigGet# for Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 213 |
fn git_config_getrust-analyzer cargo git-delta 0.19.2 git_config/impl#[String][GitConfigGet]git_config_get().(key: &str, git_config: &GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo git-delta 0.19.2 git_config/impl#[String][GitConfigGet]> { |
| 214 |
match git_config.config_from_env_varrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config_from_env_var..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(key) { |
| 215 |
Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(val) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(val.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), |
| 216 |
Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => git_config.configrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config..get_stringrust-analyzer cargo git2 0.21.0 config/impl#[Config]get_string().(key).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().(), |
| 217 |
} |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
impl GitConfigGetrust-analyzer cargo git-delta 0.19.2 git_config/GitConfigGet# for Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 222 |
fn git_config_getrust-analyzer cargo git-delta 0.19.2 git_config/impl#[`Option<String>`][GitConfigGet]git_config_get().(key: &str, git_config: &GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo git-delta 0.19.2 git_config/impl#[`Option<String>`][GitConfigGet]> { |
| 223 |
match git_config.config_from_env_varrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config_from_env_var..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(key) { |
| 224 |
Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(val) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(val.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())), |
| 225 |
Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => match git_config.configrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config..get_stringrust-analyzer cargo git2 0.21.0 config/impl#[Config]get_string().(key) { |
| 226 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(val) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(val)), |
| 227 |
_ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 228 |
}, |
| 229 |
} |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
impl GitConfigGetrust-analyzer cargo git-delta 0.19.2 git_config/GitConfigGet# for bool { |
| 234 |
fn git_config_getrust-analyzer cargo git-delta 0.19.2 git_config/impl#[bool][GitConfigGet]git_config_get().(key: &str, git_config: &GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo git-delta 0.19.2 git_config/impl#[bool][GitConfigGet]> { |
| 235 |
match git_config.config_from_env_varrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config_from_env_var..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(key).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s| s.as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().()) { |
| 236 |
Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("true") => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(true), |
| 237 |
Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("false") => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(false), |
| 238 |
_ => git_config.configrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config..get_boolrust-analyzer cargo git2 0.21.0 config/impl#[Config]get_bool().(key).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().(), |
| 239 |
} |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
impl GitConfigGetrust-analyzer cargo git-delta 0.19.2 git_config/GitConfigGet# for usize { |
| 244 |
fn git_config_getrust-analyzer cargo git-delta 0.19.2 git_config/impl#[usize][GitConfigGet]git_config_get().(key: &str, git_config: &GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo git-delta 0.19.2 git_config/impl#[usize][GitConfigGet]> { |
| 245 |
if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s) = git_config.config_from_env_varrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config_from_env_var..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(key) { |
| 246 |
if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(n) = s.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<usize>() { |
| 247 |
return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(n); |
| 248 |
} |
| 249 |
} |
| 250 |
match git_config.configrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config..get_i64rust-analyzer cargo git2 0.21.0 config/impl#[Config]get_i64().(key) { |
| 251 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(value) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value as usize), |
| 252 |
_ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 253 |
} |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
impl GitConfigGetrust-analyzer cargo git-delta 0.19.2 git_config/GitConfigGet# for f64 { |
| 258 |
fn git_config_getrust-analyzer cargo git-delta 0.19.2 git_config/impl#[f64][GitConfigGet]git_config_get().(key: &str, git_config: &GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo git-delta 0.19.2 git_config/impl#[f64][GitConfigGet]> { |
| 259 |
if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s) = git_config.config_from_env_varrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config_from_env_var..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(key) { |
| 260 |
if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(n) = s.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<f64>() { |
| 261 |
return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(n); |
| 262 |
} |
| 263 |
} |
| 264 |
match git_config.configrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#config..get_stringrust-analyzer cargo git2 0.21.0 config/impl#[Config]get_string().(key) { |
| 265 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(value) => value.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<f64>().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().(), |
| 266 |
_ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 267 |
} |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
#[cfg(test)] |
| 272 |
mod testsrust-analyzer cargo git-delta 0.19.2 git_config/tests/ { |
| 273 |
|
| 274 |
use superrust-analyzer cargo git-delta 0.19.2 git_config/::parse_config_from_env_var_valuerust-analyzer cargo git-delta 0.19.2 git_config/parse_config_from_env_var_value().; |
| 275 |
|
| 276 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 277 |
fn test_parse_config_from_env_var_valuerust-analyzer cargo git-delta 0.19.2 git_config/tests/test_parse_config_from_env_var_value().() { |
| 278 |
// To generate test cases, use git -c ... with |
| 279 |
// [core] |
| 280 |
// pager = env | grep GIT_CONFIG_PARAMETERS |
| 281 |
|
| 282 |
// We test multiple formats because the format of the value stored by |
| 283 |
// git in this environment variable has changed in recent versions of |
| 284 |
// Git. See |
| 285 |
// https://github.com/git/git/blob/311531c9de557d25ac087c1637818bd2aad6eb3a/Documentation/RelNotes/2.31.0.txt#L127-L130 |
| 286 |
|
| 287 |
for env_var_value in &["'user.name=xxx'", "'user.name'='xxx'"] { |
| 288 |
let config = parse_config_from_env_var_valuerust-analyzer cargo git-delta 0.19.2 git_config/parse_config_from_env_var_value().(env_var_value); |
| 289 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(config.is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]is_empty().()); |
| 290 |
} |
| 291 |
|
| 292 |
for env_var_value in &["'delta.plus-style=green'", "'delta.plus-style'='green'"] { |
| 293 |
let config = parse_config_from_env_var_valuerust-analyzer cargo git-delta 0.19.2 git_config/parse_config_from_env_var_value().(env_var_value); |
| 294 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(config[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."delta.plus-style"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., "green"); |
| 295 |
} |
| 296 |
|
| 297 |
for env_var_value in &[ |
| 298 |
r##"'user.name=xxx' 'delta.hunk-header-line-number-style=red "#067a00"'"##, |
| 299 |
r##"'user.name'='xxx' 'delta.hunk-header-line-number-style'='red "#067a00"'"##, |
| 300 |
] { |
| 301 |
let config = parse_config_from_env_var_valuerust-analyzer cargo git-delta 0.19.2 git_config/parse_config_from_env_var_value().(env_var_value); |
| 302 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 303 |
config[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."delta.hunk-header-line-number-style"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., |
| 304 |
r##"red "#067a00""## |
| 305 |
); |
| 306 |
} |
| 307 |
|
| 308 |
for env_var_value in &[ |
| 309 |
r##"'user.name=xxx' 'delta.side-by-side=false'"##, |
| 310 |
r##"'user.name'='xxx' 'delta.side-by-side'='false'"##, |
| 311 |
] { |
| 312 |
let config = parse_config_from_env_var_valuerust-analyzer cargo git-delta 0.19.2 git_config/parse_config_from_env_var_value().(env_var_value); |
| 313 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(config[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."delta.side-by-side"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., "false"); |
| 314 |
} |
| 315 |
|
| 316 |
for env_var_value in &[ |
| 317 |
r##"'delta.plus-style=green' 'delta.side-by-side=false' 'delta.hunk-header-line-number-style=red "#067a00"'"##, |
| 318 |
r##"'delta.plus-style'='green' 'delta.side-by-side'='false' 'delta.hunk-header-line-number-style'='red "#067a00"'"##, |
| 319 |
] { |
| 320 |
let config = parse_config_from_env_var_valuerust-analyzer cargo git-delta 0.19.2 git_config/parse_config_from_env_var_value().(env_var_value); |
| 321 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(config[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."delta.plus-style"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., "green"); |
| 322 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(config[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."delta.side-by-side"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., "false"); |
| 323 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 324 |
config[rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()."delta.hunk-header-line-number-style"]rust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`][`Index<&Q>`]index()., |
| 325 |
r##"red "#067a00""## |
| 326 |
); |
| 327 |
} |
| 328 |
} |
| 329 |
} |