summaryrefslogtreecommitdiffstats
path: root/vendor/gix-config/src/file/access/raw.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gix-config/src/file/access/raw.rs')
-rw-r--r--vendor/gix-config/src/file/access/raw.rs100
1 files changed, 69 insertions, 31 deletions
diff --git a/vendor/gix-config/src/file/access/raw.rs b/vendor/gix-config/src/file/access/raw.rs
index 44b318f24..3736bf3a2 100644
--- a/vendor/gix-config/src/file/access/raw.rs
+++ b/vendor/gix-config/src/file/access/raw.rs
@@ -40,8 +40,17 @@ impl<'event> File<'event> {
key: impl AsRef<str>,
filter: &mut MetadataFilter,
) -> Result<Cow<'_, BStr>, lookup::existing::Error> {
- let section_ids = self.section_ids_by_name_and_subname(section_name.as_ref(), subsection_name)?;
- let key = key.as_ref();
+ self.raw_value_filter_inner(section_name.as_ref(), subsection_name, key.as_ref(), filter)
+ }
+
+ fn raw_value_filter_inner(
+ &self,
+ section_name: &str,
+ subsection_name: Option<&BStr>,
+ key: &str,
+ filter: &mut MetadataFilter,
+ ) -> Result<Cow<'_, BStr>, lookup::existing::Error> {
+ let section_ids = self.section_ids_by_name_and_subname(section_name, subsection_name)?;
for section_id in section_ids.rev() {
let section = self.sections.get(&section_id).expect("known section id");
if !filter(section.meta()) {
@@ -81,8 +90,18 @@ impl<'event> File<'event> {
key: &'lookup str,
filter: &mut MetadataFilter,
) -> Result<ValueMut<'_, 'lookup, 'event>, lookup::existing::Error> {
+ self.raw_value_mut_filter_inner(section_name.as_ref(), subsection_name, key, filter)
+ }
+
+ fn raw_value_mut_filter_inner<'lookup>(
+ &mut self,
+ section_name: &str,
+ subsection_name: Option<&'lookup BStr>,
+ key: &'lookup str,
+ filter: &mut MetadataFilter,
+ ) -> Result<ValueMut<'_, 'lookup, 'event>, lookup::existing::Error> {
let mut section_ids = self
- .section_ids_by_name_and_subname(section_name.as_ref(), subsection_name)?
+ .section_ids_by_name_and_subname(section_name, subsection_name)?
.rev();
let key = section::Key(Cow::<BStr>::Borrowed(key.into()));
@@ -157,9 +176,9 @@ impl<'event> File<'event> {
/// # use std::borrow::Cow;
/// # use std::convert::TryFrom;
/// # use bstr::BStr;
- /// # let gix_config = gix_config::File::try_from("[core]a=b\n[core]\na=c\na=d").unwrap();
+ /// # let git_config = gix_config::File::try_from("[core]a=b\n[core]\na=c\na=d").unwrap();
/// assert_eq!(
- /// gix_config.raw_values("core", None, "a").unwrap(),
+ /// git_config.raw_values("core", None, "a").unwrap(),
/// vec![
/// Cow::<BStr>::Borrowed("b".into()),
/// Cow::<BStr>::Borrowed("c".into()),
@@ -191,9 +210,18 @@ impl<'event> File<'event> {
key: impl AsRef<str>,
filter: &mut MetadataFilter,
) -> Result<Vec<Cow<'_, BStr>>, lookup::existing::Error> {
+ self.raw_values_filter_inner(section_name.as_ref(), subsection_name, key.as_ref(), filter)
+ }
+
+ fn raw_values_filter_inner(
+ &self,
+ section_name: &str,
+ subsection_name: Option<&BStr>,
+ key: &str,
+ filter: &mut MetadataFilter,
+ ) -> Result<Vec<Cow<'_, BStr>>, lookup::existing::Error> {
let mut values = Vec::new();
- let section_ids = self.section_ids_by_name_and_subname(section_name.as_ref(), subsection_name)?;
- let key = key.as_ref();
+ let section_ids = self.section_ids_by_name_and_subname(section_name, subsection_name)?;
for section_id in section_ids {
let section = self.sections.get(&section_id).expect("known section id");
if !filter(section.meta()) {
@@ -231,9 +259,9 @@ impl<'event> File<'event> {
/// # use std::borrow::Cow;
/// # use std::convert::TryFrom;
/// # use bstr::BStr;
- /// # let mut gix_config = gix_config::File::try_from("[core]a=b\n[core]\na=c\na=d").unwrap();
+ /// # let mut git_config = gix_config::File::try_from("[core]a=b\n[core]\na=c\na=d").unwrap();
/// assert_eq!(
- /// gix_config.raw_values("core", None, "a")?,
+ /// git_config.raw_values("core", None, "a")?,
/// vec![
/// Cow::<BStr>::Borrowed("b".into()),
/// Cow::<BStr>::Borrowed("c".into()),
@@ -241,10 +269,10 @@ impl<'event> File<'event> {
/// ]
/// );
///
- /// gix_config.raw_values_mut("core", None, "a")?.set_all("g");
+ /// git_config.raw_values_mut("core", None, "a")?.set_all("g");
///
/// assert_eq!(
- /// gix_config.raw_values("core", None, "a")?,
+ /// git_config.raw_values("core", None, "a")?,
/// vec![
/// Cow::<BStr>::Borrowed("g".into()),
/// Cow::<BStr>::Borrowed("g".into()),
@@ -277,7 +305,17 @@ impl<'event> File<'event> {
key: &'lookup str,
filter: &mut MetadataFilter,
) -> Result<MultiValueMut<'_, 'lookup, 'event>, lookup::existing::Error> {
- let section_ids = self.section_ids_by_name_and_subname(section_name.as_ref(), subsection_name)?;
+ self.raw_values_mut_filter_inner(section_name.as_ref(), subsection_name, key, filter)
+ }
+
+ fn raw_values_mut_filter_inner<'lookup>(
+ &mut self,
+ section_name: &str,
+ subsection_name: Option<&'lookup BStr>,
+ key: &'lookup str,
+ filter: &mut MetadataFilter,
+ ) -> Result<MultiValueMut<'_, 'lookup, 'event>, lookup::existing::Error> {
+ let section_ids = self.section_ids_by_name_and_subname(section_name, subsection_name)?;
let key = section::Key(Cow::<BStr>::Borrowed(key.into()));
let mut offsets = HashMap::new();
@@ -352,11 +390,11 @@ impl<'event> File<'event> {
/// # use std::borrow::Cow;
/// # use bstr::BStr;
/// # use std::convert::TryFrom;
- /// # let mut gix_config = gix_config::File::try_from("[core]a=b\n[core]\na=c\na=d").unwrap();
- /// gix_config.set_existing_raw_value("core", None, "a", "e")?;
- /// assert_eq!(gix_config.raw_value("core", None, "a")?, Cow::<BStr>::Borrowed("e".into()));
+ /// # let mut git_config = gix_config::File::try_from("[core]a=b\n[core]\na=c\na=d").unwrap();
+ /// git_config.set_existing_raw_value("core", None, "a", "e")?;
+ /// assert_eq!(git_config.raw_value("core", None, "a")?, Cow::<BStr>::Borrowed("e".into()));
/// assert_eq!(
- /// gix_config.raw_values("core", None, "a")?,
+ /// git_config.raw_values("core", None, "a")?,
/// vec![
/// Cow::<BStr>::Borrowed("b".into()),
/// Cow::<BStr>::Borrowed("c".into()),
@@ -395,12 +433,12 @@ impl<'event> File<'event> {
/// # use std::borrow::Cow;
/// # use bstr::BStr;
/// # use std::convert::TryFrom;
- /// # let mut gix_config = gix_config::File::try_from("[core]a=b").unwrap();
- /// let prev = gix_config.set_raw_value("core", None, "a", "e")?;
- /// gix_config.set_raw_value("core", None, "b", "f")?;
+ /// # let mut git_config = gix_config::File::try_from("[core]a=b").unwrap();
+ /// let prev = git_config.set_raw_value("core", None, "a", "e")?;
+ /// git_config.set_raw_value("core", None, "b", "f")?;
/// assert_eq!(prev.expect("present").as_ref(), "b");
- /// assert_eq!(gix_config.raw_value("core", None, "a")?, Cow::<BStr>::Borrowed("e".into()));
- /// assert_eq!(gix_config.raw_value("core", None, "b")?, Cow::<BStr>::Borrowed("f".into()));
+ /// assert_eq!(git_config.raw_value("core", None, "a")?, Cow::<BStr>::Borrowed("e".into()));
+ /// assert_eq!(git_config.raw_value("core", None, "b")?, Cow::<BStr>::Borrowed("f".into()));
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
pub fn set_raw_value<'b, Key, E>(
@@ -432,7 +470,7 @@ impl<'event> File<'event> {
section::key::Error: From<E>,
{
let mut section = self.section_mut_or_create_new_filter(section_name, subsection_name, filter)?;
- Ok(section.set(key.try_into().map_err(section::key::Error::from)?, new_value))
+ Ok(section.set(key.try_into().map_err(section::key::Error::from)?, new_value.into()))
}
/// Sets a multivar in a given section, optional subsection, and key value.
@@ -468,14 +506,14 @@ impl<'event> File<'event> {
/// # use std::borrow::Cow;
/// # use std::convert::TryFrom;
/// # use bstr::BStr;
- /// # let mut gix_config = gix_config::File::try_from("[core]a=b\n[core]\na=c\na=d").unwrap();
+ /// # let mut git_config = gix_config::File::try_from("[core]a=b\n[core]\na=c\na=d").unwrap();
/// let new_values = vec![
/// "x",
/// "y",
/// "z",
/// ];
- /// gix_config.set_existing_raw_multi_value("core", None, "a", new_values.into_iter())?;
- /// let fetched_config = gix_config.raw_values("core", None, "a")?;
+ /// git_config.set_existing_raw_multi_value("core", None, "a", new_values.into_iter())?;
+ /// let fetched_config = git_config.raw_values("core", None, "a")?;
/// assert!(fetched_config.contains(&Cow::<BStr>::Borrowed("x".into())));
/// assert!(fetched_config.contains(&Cow::<BStr>::Borrowed("y".into())));
/// assert!(fetched_config.contains(&Cow::<BStr>::Borrowed("z".into())));
@@ -489,13 +527,13 @@ impl<'event> File<'event> {
/// # use std::borrow::Cow;
/// # use std::convert::TryFrom;
/// # use bstr::BStr;
- /// # let mut gix_config = gix_config::File::try_from("[core]a=b\n[core]\na=c\na=d").unwrap();
+ /// # let mut git_config = gix_config::File::try_from("[core]a=b\n[core]\na=c\na=d").unwrap();
/// let new_values = vec![
/// "x",
/// "y",
/// ];
- /// gix_config.set_existing_raw_multi_value("core", None, "a", new_values.into_iter())?;
- /// let fetched_config = gix_config.raw_values("core", None, "a")?;
+ /// git_config.set_existing_raw_multi_value("core", None, "a", new_values.into_iter())?;
+ /// let fetched_config = git_config.raw_values("core", None, "a")?;
/// assert!(fetched_config.contains(&Cow::<BStr>::Borrowed("x".into())));
/// assert!(fetched_config.contains(&Cow::<BStr>::Borrowed("y".into())));
/// # Ok::<(), gix_config::lookup::existing::Error>(())
@@ -508,15 +546,15 @@ impl<'event> File<'event> {
/// # use std::borrow::Cow;
/// # use std::convert::TryFrom;
/// # use bstr::BStr;
- /// # let mut gix_config = gix_config::File::try_from("[core]a=b\n[core]\na=c\na=d").unwrap();
+ /// # let mut git_config = gix_config::File::try_from("[core]a=b\n[core]\na=c\na=d").unwrap();
/// let new_values = vec![
/// "x",
/// "y",
/// "z",
/// "discarded",
/// ];
- /// gix_config.set_existing_raw_multi_value("core", None, "a", new_values)?;
- /// assert!(!gix_config.raw_values("core", None, "a")?.contains(&Cow::<BStr>::Borrowed("discarded".into())));
+ /// git_config.set_existing_raw_multi_value("core", None, "a", new_values)?;
+ /// assert!(!git_config.raw_values("core", None, "a")?.contains(&Cow::<BStr>::Borrowed("discarded".into())));
/// # Ok::<(), gix_config::lookup::existing::Error>(())
/// ```
pub fn set_existing_raw_multi_value<'a, Iter, Item>(