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 @@
1use super::{interpolate_context, util, Error, StageOne};1use super::{interpolate_context, util, Error, StageOne};
2use crate::config::cache::util::ApplyLeniencyOpt;
2use crate::{bstr::BString, config::Cache, repository};3use crate::{bstr::BString, config::Cache, repository};
3 4
4/// Initialization5/// Initialization
@@ -115,7 +116,7 @@ impl Cache { · 110 unmodified lines
115 globals116 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)?;
git-repository/src/config/cache/util.rs+3−14
@@ -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 config31 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
44pub(crate) fn query_refupdates(41pub(crate) fn query_refupdates(
@@ -95,14 +92,6 @@ where · 50 unmodified lines
95 }92 }
96}93}
97 94
98pub(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
106pub(crate) fn check_lenient_default<T, E>(v: Result<T, E>, lenient: bool, default: impl FnOnce() -> T) -> Result<T, E> {95pub(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),
git-repository/src/repository/config/transport.rs+6−8
@@ -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>(