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