Unified · Split
| @@ -1,4 +1,5 @@ | |||
| 1 | use super::{interpolate_context, util, Error, StageOne}; | 1 | use super::{interpolate_context, util, Error, StageOne}; |
| 2 | use crate::config::cache::util::ApplyLeniencyOpt; | ||
| 2 | use crate::{bstr::BString, config::Cache, repository}; | 3 | use crate::{bstr::BString, config::Cache, repository}; |
| 3 | 4 | ||
| 4 | /// Initialization | 5 | /// Initialization |
| @@ -115,7 +116,7 @@ impl Cache { · 110 unmodified lines | |||
| 115 | globals | 116 | globals |
| 116 | }; | 117 | }; |
| 117 | 118 | ||
| 118 | let hex_len = util::check_lenient(util::parse_core_abbrev(&config, object_hash), lenient_config)?; | 119 | let hex_len = util::parse_core_abbrev(&config, object_hash).with_leniency(lenient_config)?; |
| 119 | 120 | ||
| 120 | use util::config_bool; | 121 | use util::config_bool; |
| 121 | let reflog = util::query_refupdates(&config, lenient_config)?; | 122 | let reflog = util::query_refupdates(&config, lenient_config)?; |
| @@ -166,7 +167,7 @@ impl Cache { · 44 unmodified lines | |||
| 166 | /// in one that it them makes the default. | 167 | /// in one that it them makes the default. |
| 167 | pub fn reread_values_and_clear_caches(&mut self) -> Result<(), Error> { | 168 | pub fn reread_values_and_clear_caches(&mut self) -> Result<(), Error> { |
| 168 | let config = &self.resolved; | 169 | let config = &self.resolved; |
| 169 | let hex_len = util::check_lenient(util::parse_core_abbrev(config, self.object_hash), self.lenient_config)?; | 170 | let hex_len = util::parse_core_abbrev(config, self.object_hash).with_leniency(self.lenient_config)?; |
| 170 | 171 | ||
| 171 | use util::config_bool; | 172 | use util::config_bool; |
| 172 | let ignore_case = config_bool(config, "core.ignoreCase", false, self.lenient_config)?; | 173 | let ignore_case = config_bool(config, "core.ignoreCase", false, self.lenient_config)?; |
| @@ -28,17 +28,14 @@ pub(crate) fn config_bool( · 27 unmodified lines | |||
| 28 | lenient: bool, | 28 | lenient: bool, |
| 29 | ) -> Result<bool, Error> { | 29 | ) -> Result<bool, Error> { |
| 30 | let (section, key) = key.split_once('.').expect("valid section.key format"); | 30 | let (section, key) = key.split_once('.').expect("valid section.key format"); |
| 31 | match config | 31 | config |
| 32 | .boolean(section, None, key) | 32 | .boolean(section, None, key) |
| 33 | .unwrap_or(Ok(default)) | 33 | .unwrap_or(Ok(default)) |
| 34 | .map_err(|err| Error::DecodeBoolean { | 34 | .map_err(|err| Error::DecodeBoolean { |
| 35 | value: err.input, | 35 | value: err.input, |
| 36 | key: key.into(), | 36 | key: key.into(), |
| 37 | }) { | 37 | }) |
| 38 | Ok(v) => Ok(v), | 38 | .with_leniency(lenient) |
| 39 | Err(_err) if lenient => Ok(default), | ||
| 40 | Err(err) => Err(err), | ||
| 41 | } | ||
| 42 | } | 39 | } |
| 43 | 40 | ||
| 44 | pub(crate) fn query_refupdates( | 41 | pub(crate) fn query_refupdates( |
| @@ -95,14 +92,6 @@ where · 50 unmodified lines | |||
| 95 | } | 92 | } |
| 96 | } | 93 | } |
| 97 | 94 | ||
| 98 | pub(crate) fn check_lenient<T, E>(v: Result<Option<T>, E>, lenient: bool) -> Result<Option<T>, E> { | ||
| 99 | match v { | ||
| 100 | Ok(v) => Ok(v), | ||
| 101 | Err(_) if lenient => Ok(None), | ||
| 102 | Err(err) => Err(err), | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | pub(crate) fn check_lenient_default<T, E>(v: Result<T, E>, lenient: bool, default: impl FnOnce() -> T) -> Result<T, E> { | 95 | pub(crate) fn check_lenient_default<T, E>(v: Result<T, E>, lenient: bool, default: impl FnOnce() -> T) -> Result<T, E> { |
| 107 | match v { | 96 | match v { |
| 108 | Ok(v) => Ok(v), | 97 | Ok(v) => Ok(v), |
| @@ -24,7 +24,7 @@ impl crate::Repository { · 23 unmodified lines | |||
| 24 | #[cfg(feature = "blocking-http-transport")] | 24 | #[cfg(feature = "blocking-http-transport")] |
| 25 | { | 25 | { |
| 26 | use crate::bstr::ByteVec; | 26 | use crate::bstr::ByteVec; |
| 27 | use crate::config::cache::util::{check_lenient, check_lenient_default}; | 27 | use crate::config::cache::util::check_lenient_default; |
| 28 | use git_transport::client::http; | 28 | use git_transport::client::http; |
| 29 | use std::borrow::Cow; | 29 | use std::borrow::Cow; |
| 30 | use std::convert::{TryFrom, TryInto}; | 30 | use std::convert::{TryFrom, TryInto}; |
| @@ -34,13 +34,11 @@ impl crate::Repository { · 3 unmodified lines | |||
| 34 | lenient: bool, | 34 | lenient: bool, |
| 35 | key: &'static str, | 35 | key: &'static str, |
| 36 | ) -> Result<Option<String>, crate::config::transport::Error> { | 36 | ) -> Result<Option<String>, crate::config::transport::Error> { |
| 37 | check_lenient( | 37 | Vec::from(v.into_owned()) |
| 38 | Vec::from(v.into_owned()) | 38 | .into_string() |
| 39 | .into_string() | 39 | .map(Some) |
| 40 | .map(Some) | 40 | .map_err(|err| crate::config::transport::Error::IllformedUtf8 { source: err, key }) |
| 41 | .map_err(|err| crate::config::transport::Error::IllformedUtf8 { source: err, key }), | 41 | .with_leniency(lenient) |
| 42 | lenient, | ||
| 43 | ) | ||
| 44 | } | 42 | } |
| 45 | 43 | ||
| 46 | fn integer<T>( | 44 | fn integer<T>( |