Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Nov 15, 2022
1 parent a59c791 commit db7ad53
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
5 changes: 3 additions & 2 deletions git-repository/src/config/cache/init.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::{interpolate_context, util, Error, StageOne};
use crate::config::cache::util::ApplyLeniencyOpt;
use crate::{bstr::BString, config::Cache, repository};

/// Initialization
Expand Down Expand Up @@ -115,7 +116,7 @@ impl Cache {
globals
};

let hex_len = util::check_lenient(util::parse_core_abbrev(&config, object_hash), lenient_config)?;
let hex_len = util::parse_core_abbrev(&config, object_hash).with_leniency(lenient_config)?;

use util::config_bool;
let reflog = util::query_refupdates(&config, lenient_config)?;
Expand Down Expand Up @@ -166,7 +167,7 @@ impl Cache {
/// in one that it them makes the default.
pub fn reread_values_and_clear_caches(&mut self) -> Result<(), Error> {
let config = &self.resolved;
let hex_len = util::check_lenient(util::parse_core_abbrev(config, self.object_hash), self.lenient_config)?;
let hex_len = util::parse_core_abbrev(config, self.object_hash).with_leniency(self.lenient_config)?;

use util::config_bool;
let ignore_case = config_bool(config, "core.ignoreCase", false, self.lenient_config)?;
Expand Down
17 changes: 3 additions & 14 deletions git-repository/src/config/cache/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@ pub(crate) fn config_bool(
lenient: bool,
) -> Result<bool, Error> {
let (section, key) = key.split_once('.').expect("valid section.key format");
match config
config
.boolean(section, None, key)
.unwrap_or(Ok(default))
.map_err(|err| Error::DecodeBoolean {
value: err.input,
key: key.into(),
}) {
Ok(v) => Ok(v),
Err(_err) if lenient => Ok(default),
Err(err) => Err(err),
}
})
.with_leniency(lenient)
}

pub(crate) fn query_refupdates(
Expand Down Expand Up @@ -95,14 +92,6 @@ where
}
}

pub(crate) fn check_lenient<T, E>(v: Result<Option<T>, E>, lenient: bool) -> Result<Option<T>, E> {
match v {
Ok(v) => Ok(v),
Err(_) if lenient => Ok(None),
Err(err) => Err(err),
}
}

pub(crate) fn check_lenient_default<T, E>(v: Result<T, E>, lenient: bool, default: impl FnOnce() -> T) -> Result<T, E> {
match v {
Ok(v) => Ok(v),
Expand Down
14 changes: 6 additions & 8 deletions git-repository/src/repository/config/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl crate::Repository {
#[cfg(feature = "blocking-http-transport")]
{
use crate::bstr::ByteVec;
use crate::config::cache::util::{check_lenient, check_lenient_default};
use crate::config::cache::util::check_lenient_default;
use git_transport::client::http;
use std::borrow::Cow;
use std::convert::{TryFrom, TryInto};
Expand All @@ -34,13 +34,11 @@ impl crate::Repository {
lenient: bool,
key: &'static str,
) -> Result<Option<String>, crate::config::transport::Error> {
check_lenient(
Vec::from(v.into_owned())
.into_string()
.map(Some)
.map_err(|err| crate::config::transport::Error::IllformedUtf8 { source: err, key }),
lenient,
)
Vec::from(v.into_owned())
.into_string()
.map(Some)
.map_err(|err| crate::config::transport::Error::IllformedUtf8 { source: err, key })
.with_leniency(lenient)
}

fn integer<T>(
Expand Down

0 comments on commit db7ad53

Please sign in to comment.