History

refactor

Sebastian Thiel committed 3 years ago

Commit db7ad531 parent a59c7913 files · +12 −24Browse files

Unified · Split

3 files
  1. git-repository/src/config/cache/init.rs +3 −2
  2. git-repository/src/config/cache/util.rs +3 −14
  3. git-repository/src/repository/config/transport.rs +6 −8
git-repository/src/config/cache/init.rs+3−2
@@ -1,4 +1,5 @@
11 use super::{interpolate_context, util, Error, StageOne};
2+use crate::config::cache::util::ApplyLeniencyOpt;
23 use crate::{bstr::BString, config::Cache, repository};
34
45 /// Initialization
@@ -115,7 +116,7 @@ impl Cache { · 110 unmodified lines
115116 globals
116117 };
117118
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)?;
119120
120121 use util::config_bool;
121122 let reflog = util::query_refupdates(&config, lenient_config)?;
@@ -166,7 +167,7 @@ impl Cache { · 44 unmodified lines
166167 /// in one that it them makes the default.
167168 pub fn reread_values_and_clear_caches(&mut self) -> Result<(), Error> {
168169 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)?;
170171
171172 use util::config_bool;
172173 let ignore_case = config_bool(config, "core.ignoreCase", false, self.lenient_config)?;
git-repository/src/config/cache/util.rs+3−14
@@ -28,17 +28,14 @@ pub(crate) fn config_bool( · 27 unmodified lines
2828 lenient: bool,
2929 ) -> Result<bool, Error> {
3030 let (section, key) = key.split_once('.').expect("valid section.key format");
31− match config
31+ config
3232 .boolean(section, None, key)
3333 .unwrap_or(Ok(default))
3434 .map_err(|err| Error::DecodeBoolean {
3535 value: err.input,
3636 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)
4239 }
4340
4441 pub(crate) fn query_refupdates(
@@ -95,14 +92,6 @@ where · 50 unmodified lines
9592 }
9693 }
9794
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−
10695 pub(crate) fn check_lenient_default<T, E>(v: Result<T, E>, lenient: bool, default: impl FnOnce() -> T) -> Result<T, E> {
10796 match v {
10897 Ok(v) => Ok(v),
git-repository/src/repository/config/transport.rs+6−8
@@ -24,7 +24,7 @@ impl crate::Repository { · 23 unmodified lines
2424 #[cfg(feature = "blocking-http-transport")]
2525 {
2626 use crate::bstr::ByteVec;
27− use crate::config::cache::util::{check_lenient, check_lenient_default};
27+ use crate::config::cache::util::check_lenient_default;
2828 use git_transport::client::http;
2929 use std::borrow::Cow;
3030 use std::convert::{TryFrom, TryInto};
@@ -34,13 +34,11 @@ impl crate::Repository { · 3 unmodified lines
3434 lenient: bool,
3535 key: &'static str,
3636 ) -> 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)
4442 }
4543
4644 fn integer<T>(