pub use git_config::*;
use git_features::threading::OnceCell;
use crate::{bstr::BString, remote, repository::identity, revision::spec, Repository};
pub(crate) mod cache;
mod snapshot;
pub use snapshot::credential_helpers;
pub mod overrides;
pub struct Snapshot<'repo> {
pub(crate) repo: &'repo Repository,
}
pub struct SnapshotMut<'repo> {
pub(crate) repo: Option<&'repo mut Repository>,
pub(crate) config: git_config::File<'static>,
}
pub struct CommitAutoRollback<'repo> {
pub(crate) repo: Option<&'repo mut Repository>,
pub(crate) prev_config: crate::Config,
}
pub(crate) mod section {
pub fn is_trusted(meta: &git_config::file::Metadata) -> bool {
meta.trust == git_sec::Trust::Full || meta.source.kind() != git_config::source::Kind::Repository
}
}
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("Could not read configuration file")]
Io(#[from] std::io::Error),
#[error("Could not decode configuration value at {key:?}")]
Value {
source: git_config::value::Error,
key: &'static str,
},
#[error(transparent)]
Init(#[from] git_config::file::init::Error),
#[error(transparent)]
ResolveIncludes(#[from] git_config::file::includes::Error),
#[error(transparent)]
FromEnv(#[from] git_config::file::init::from_env::Error),
#[error("Cannot handle objects formatted as {:?}", .name)]
UnsupportedObjectFormat { name: BString },
#[error("The value for '{}' cannot be empty", .key)]
EmptyValue { key: &'static str },
#[error("Invalid value for 'core.abbrev' = '{}'. It must be between 4 and {}", .value, .max)]
CoreAbbrev { value: BString, max: u8 },
#[error("Value '{}' at key '{}' could not be decoded as boolean", .value, .key)]
DecodeBoolean { key: String, value: BString },
#[error(transparent)]
PathInterpolation(#[from] git_config::path::interpolate::Error),
#[error("{source:?} configuration overrides at open or init time could not be applied.")]
ConfigOverrides {
#[source]
err: overrides::Error,
source: git_config::Source,
},
#[error("Invalid value for 'core.logAllRefUpdates': \"{value}\"")]
LogAllRefUpdates { value: BString },
}
pub mod diff {
pub mod algorithm {
use crate::bstr::BString;
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("Unknown diff algorithm named '{name}'")]
Unknown { name: BString },
#[error("The '{name}' algorithm is not yet implemented")]
Unimplemented { name: BString },
}
}
}
pub mod checkout_options {
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("{key} could not be decoded")]
Configuration {
key: &'static str,
source: git_config::value::Error,
},
#[error("Failed to interpolate the attribute file configured at `core.attributesFile`")]
AttributesFileInterpolation(#[from] git_config::path::interpolate::Error),
}
}
pub mod ssh_connect_options {
use crate::bstr::BString;
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("The ssh variant named {name:?} at key `ssh.variant` is unknown.")]
SshVariant { name: BString },
}
}
pub mod transport {
use std::borrow::Cow;
use crate::{bstr, bstr::BStr};
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error(
"Could not interpret configuration key {key:?} as {kind} integer of desired range with value: {actual}"
)]
InvalidInteger {
key: &'static str,
kind: &'static str,
actual: i64,
},
#[error("Could not interpret configuration key {key:?}")]
ConfigValue {
source: git_config::value::Error,
key: &'static str,
},
#[error("Could not interpolate path at key {key:?}")]
InterpolatePath {
source: git_config::path::interpolate::Error,
key: &'static str,
},
#[error("Could not decode value at key {key:?} as UTF-8 string")]
IllformedUtf8 {
key: Cow<'static, BStr>,
source: bstr::FromUtf8Error,
},
#[error("Invalid URL passed for configuration")]
ParseUrl(#[from] git_url::parse::Error),
#[error("Could obtain configuration for an HTTP url")]
Http(#[from] http::Error),
}
pub mod http {
use std::borrow::Cow;
use crate::bstr::{BStr, BString};
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("The proxy authentication method name {value:?} found at key `{key}` is invalid")]
InvalidProxyAuthMethod { value: String, key: Cow<'static, BStr> },
#[error("Could not configure the credential helpers for the authenticated proxy url")]
ConfigureProxyAuthenticate(#[from] crate::config::snapshot::credential_helpers::Error),
#[error("The SSL version at key `{key} named {name:?} is unknown")]
InvalidSslVersion { key: &'static str, name: BString },
#[error("The HTTP version at key `{key} named {name:?} is unknown")]
InvalidHttpVersion { key: &'static str, name: BString },
}
}
}
#[derive(Clone)]
pub(crate) struct Cache {
pub resolved: crate::Config,
pub hex_len: Option<usize>,
pub is_bare: bool,
pub object_hash: git_hash::Kind,
pub use_multi_pack_index: bool,
pub reflog: Option<git_ref::store::WriteReflog>,
pub(crate) user_agent: OnceCell<String>,
pub(crate) personas: OnceCell<identity::Personas>,
pub(crate) url_rewrite: OnceCell<remote::url::Rewrite>,
#[cfg(any(feature = "blocking-network-client", feature = "async-network-client"))]
pub(crate) url_scheme: OnceCell<remote::url::SchemePermission>,
pub(crate) diff_algorithm: OnceCell<git_diff::blob::Algorithm>,
pub(crate) pack_cache_bytes: Option<usize>,
pub(crate) object_cache_bytes: usize,
filter_config_section: fn(&git_config::file::Metadata) -> bool,
pub object_kind_hint: Option<spec::parse::ObjectKindHint>,
pub ignore_case: bool,
pub lenient_config: bool,
xdg_config_home_env: git_sec::Permission,
home_env: git_sec::Permission,
}