diff options
Diffstat (limited to 'vendor/gix-config/src/file')
-rw-r--r-- | vendor/gix-config/src/file/access/comfort.rs | 33 | ||||
-rw-r--r-- | vendor/gix-config/src/file/access/mutate.rs | 103 | ||||
-rw-r--r-- | vendor/gix-config/src/file/access/raw.rs | 100 | ||||
-rw-r--r-- | vendor/gix-config/src/file/access/read_only.rs | 29 | ||||
-rw-r--r-- | vendor/gix-config/src/file/init/comfort.rs | 14 | ||||
-rw-r--r-- | vendor/gix-config/src/file/init/from_env.rs | 4 | ||||
-rw-r--r-- | vendor/gix-config/src/file/init/from_paths.rs | 23 | ||||
-rw-r--r-- | vendor/gix-config/src/file/mod.rs | 6 | ||||
-rw-r--r-- | vendor/gix-config/src/file/mutable/mod.rs | 6 | ||||
-rw-r--r-- | vendor/gix-config/src/file/mutable/section.rs | 12 | ||||
-rw-r--r-- | vendor/gix-config/src/file/section/body.rs | 14 | ||||
-rw-r--r-- | vendor/gix-config/src/file/section/mod.rs | 2 | ||||
-rw-r--r-- | vendor/gix-config/src/file/write.rs | 10 |
13 files changed, 217 insertions, 139 deletions
diff --git a/vendor/gix-config/src/file/access/comfort.rs b/vendor/gix-config/src/file/access/comfort.rs index b4953c597..ed62e7792 100644 --- a/vendor/gix-config/src/file/access/comfort.rs +++ b/vendor/gix-config/src/file/access/comfort.rs @@ -31,7 +31,8 @@ impl<'event> File<'event> { key: impl AsRef<str>, filter: &mut MetadataFilter, ) -> Option<Cow<'_, BStr>> { - self.raw_value_filter(section_name, subsection_name, key, filter).ok() + self.raw_value_filter(section_name.as_ref(), subsection_name, key.as_ref(), filter) + .ok() } /// Like [`string_filter()`][File::string_filter()], but suitable for statically known `key`s like `remote.origin.url`. @@ -40,7 +41,7 @@ impl<'event> File<'event> { key: impl Into<&'a BStr>, filter: &mut MetadataFilter, ) -> Option<Cow<'_, BStr>> { - let key = crate::parse::key(key)?; + let key = crate::parse::key(key.into())?; self.raw_value_filter(key.section_name, key.subsection_name, key.value_name, filter) .ok() } @@ -78,7 +79,7 @@ impl<'event> File<'event> { key: impl AsRef<str>, filter: &mut MetadataFilter, ) -> Option<crate::Path<'_>> { - self.raw_value_filter(section_name, subsection_name, key, filter) + self.raw_value_filter(section_name.as_ref(), subsection_name, key.as_ref(), filter) .ok() .map(crate::Path::from) } @@ -89,7 +90,7 @@ impl<'event> File<'event> { key: impl Into<&'a BStr>, filter: &mut MetadataFilter, ) -> Option<crate::Path<'_>> { - let key = crate::parse::key(key)?; + let key = crate::parse::key(key.into())?; self.path_filter(key.section_name, key.subsection_name, key.value_name, filter) } @@ -127,7 +128,7 @@ impl<'event> File<'event> { continue; } match section.value_implicit(key) { - Some(Some(v)) => return Some(crate::Boolean::try_from(v).map(|b| b.into())), + Some(Some(v)) => return Some(crate::Boolean::try_from(v).map(Into::into)), Some(None) => return Some(Ok(true)), None => continue, } @@ -141,7 +142,7 @@ impl<'event> File<'event> { key: impl Into<&'a BStr>, filter: &mut MetadataFilter, ) -> Option<Result<bool, value::Error>> { - let key = crate::parse::key(key)?; + let key = crate::parse::key(key.into())?; self.boolean_filter(key.section_name, key.subsection_name, key.value_name, filter) } @@ -168,7 +169,9 @@ impl<'event> File<'event> { key: impl AsRef<str>, filter: &mut MetadataFilter, ) -> Option<Result<i64, value::Error>> { - let int = self.raw_value_filter(section_name, subsection_name, key, filter).ok()?; + let int = self + .raw_value_filter(section_name.as_ref(), subsection_name, key.as_ref(), filter) + .ok()?; Some(crate::Integer::try_from(int.as_ref()).and_then(|b| { b.to_decimal() .ok_or_else(|| value::Error::new("Integer overflow", int.into_owned())) @@ -181,7 +184,7 @@ impl<'event> File<'event> { key: impl Into<&'a BStr>, filter: &mut MetadataFilter, ) -> Option<Result<i64, value::Error>> { - let key = crate::parse::key(key)?; + let key = crate::parse::key(key.into())?; self.integer_filter(key.section_name, key.subsection_name, key.value_name, filter) } @@ -192,12 +195,13 @@ impl<'event> File<'event> { subsection_name: Option<&BStr>, key: impl AsRef<str>, ) -> Option<Vec<Cow<'_, BStr>>> { - self.raw_values(section_name, subsection_name, key).ok() + self.raw_values(section_name.as_ref(), subsection_name, key.as_ref()) + .ok() } /// Like [`strings()`][File::strings()], but suitable for statically known `key`s like `remote.origin.url`. pub fn strings_by_key<'a>(&self, key: impl Into<&'a BStr>) -> Option<Vec<Cow<'_, BStr>>> { - let key = crate::parse::key(key)?; + let key = crate::parse::key(key.into())?; self.strings(key.section_name, key.subsection_name, key.value_name) } @@ -209,7 +213,8 @@ impl<'event> File<'event> { key: impl AsRef<str>, filter: &mut MetadataFilter, ) -> Option<Vec<Cow<'_, BStr>>> { - self.raw_values_filter(section_name, subsection_name, key, filter).ok() + self.raw_values_filter(section_name.as_ref(), subsection_name, key.as_ref(), filter) + .ok() } /// Like [`strings_filter()`][File::strings_filter()], but suitable for statically known `key`s like `remote.origin.url`. @@ -218,7 +223,7 @@ impl<'event> File<'event> { key: impl Into<&'a BStr>, filter: &mut MetadataFilter, ) -> Option<Vec<Cow<'_, BStr>>> { - let key = crate::parse::key(key)?; + let key = crate::parse::key(key.into())?; self.strings_filter(key.section_name, key.subsection_name, key.value_name, filter) } @@ -247,7 +252,7 @@ impl<'event> File<'event> { key: impl AsRef<str>, filter: &mut MetadataFilter, ) -> Option<Result<Vec<i64>, value::Error>> { - self.raw_values_filter(section_name, subsection_name, key, filter) + self.raw_values_filter(section_name.as_ref(), subsection_name, key.as_ref(), filter) .ok() .map(|values| { values @@ -268,7 +273,7 @@ impl<'event> File<'event> { key: impl Into<&'a BStr>, filter: &mut MetadataFilter, ) -> Option<Result<Vec<i64>, value::Error>> { - let key = crate::parse::key(key)?; + let key = crate::parse::key(key.into())?; self.integers_filter(key.section_name, key.subsection_name, key.value_name, filter) } } diff --git a/vendor/gix-config/src/file/access/mutate.rs b/vendor/gix-config/src/file/access/mutate.rs index e1cfc6e1c..4844a34f4 100644 --- a/vendor/gix-config/src/file/access/mutate.rs +++ b/vendor/gix-config/src/file/access/mutate.rs @@ -18,10 +18,17 @@ impl<'event> File<'event> { name: impl AsRef<str>, subsection_name: Option<&BStr>, ) -> Result<SectionMut<'a, 'event>, lookup::existing::Error> { + self.section_mut_inner(name.as_ref(), subsection_name) + } + + fn section_mut_inner<'a>( + &'a mut self, + name: &str, + subsection_name: Option<&BStr>, + ) -> Result<SectionMut<'a, 'event>, lookup::existing::Error> { let id = self - .section_ids_by_name_and_subname(name.as_ref(), subsection_name)? - .rev() - .next() + .section_ids_by_name_and_subname(name, subsection_name)? + .next_back() .expect("BUG: Section lookup vec was empty"); let nl = self.detect_newline_style_smallvec(); Ok(self @@ -65,7 +72,15 @@ impl<'event> File<'event> { subsection_name: Option<&BStr>, filter: &mut MetadataFilter, ) -> Result<SectionMut<'a, 'event>, section::header::Error> { - let name = name.as_ref(); + self.section_mut_or_create_new_filter_inner(name.as_ref(), subsection_name, filter) + } + + fn section_mut_or_create_new_filter_inner<'a>( + &'a mut self, + name: &str, + subsection_name: Option<&BStr>, + filter: &mut MetadataFilter, + ) -> Result<SectionMut<'a, 'event>, section::header::Error> { match self .section_ids_by_name_and_subname(name.as_ref(), subsection_name) .ok() @@ -97,8 +112,17 @@ impl<'event> File<'event> { subsection_name: Option<&BStr>, filter: &mut MetadataFilter, ) -> Result<Option<file::SectionMut<'a, 'event>>, lookup::existing::Error> { + self.section_mut_filter_inner(name.as_ref(), subsection_name, filter) + } + + fn section_mut_filter_inner<'a>( + &'a mut self, + name: &str, + subsection_name: Option<&BStr>, + filter: &mut MetadataFilter, + ) -> Result<Option<file::SectionMut<'a, 'event>>, lookup::existing::Error> { let id = self - .section_ids_by_name_and_subname(name.as_ref(), subsection_name)? + .section_ids_by_name_and_subname(name, subsection_name)? .rev() .find(|id| { let s = &self.sections[id]; @@ -131,10 +155,10 @@ impl<'event> File<'event> { /// # use std::borrow::Cow; /// # use gix_config::File; /// # use std::convert::TryFrom; - /// let mut gix_config = gix_config::File::default(); - /// let section = gix_config.new_section("hello", Some(Cow::Borrowed("world".into())))?; + /// let mut git_config = gix_config::File::default(); + /// let section = git_config.new_section("hello", Some(Cow::Borrowed("world".into())))?; /// let nl = section.newline().to_owned(); - /// assert_eq!(gix_config.to_string(), format!("[hello \"world\"]{nl}")); + /// assert_eq!(git_config.to_string(), format!("[hello \"world\"]{nl}")); /// # Ok::<(), Box<dyn std::error::Error>>(()) /// ``` /// @@ -146,13 +170,13 @@ impl<'event> File<'event> { /// # use std::convert::TryFrom; /// # use bstr::ByteSlice; /// # use gix_config::parse::section; - /// let mut gix_config = gix_config::File::default(); - /// let mut section = gix_config.new_section("hello", Some(Cow::Borrowed("world".into())))?; + /// let mut git_config = gix_config::File::default(); + /// let mut section = git_config.new_section("hello", Some(Cow::Borrowed("world".into())))?; /// section.push(section::Key::try_from("a")?, Some("b".into())); /// let nl = section.newline().to_owned(); - /// assert_eq!(gix_config.to_string(), format!("[hello \"world\"]{nl}\ta = b{nl}")); - /// let _section = gix_config.new_section("core", None); - /// assert_eq!(gix_config.to_string(), format!("[hello \"world\"]{nl}\ta = b{nl}[core]{nl}")); + /// assert_eq!(git_config.to_string(), format!("[hello \"world\"]{nl}\ta = b{nl}")); + /// let _section = git_config.new_section("core", None); + /// assert_eq!(git_config.to_string(), format!("[hello \"world\"]{nl}\ta = b{nl}[core]{nl}")); /// # Ok::<(), Box<dyn std::error::Error>>(()) /// ``` pub fn new_section( @@ -160,6 +184,14 @@ impl<'event> File<'event> { name: impl Into<Cow<'event, str>>, subsection: impl Into<Option<Cow<'event, BStr>>>, ) -> Result<SectionMut<'_, 'event>, section::header::Error> { + self.new_section_inner(name.into(), subsection.into()) + } + + fn new_section_inner( + &mut self, + name: Cow<'event, str>, + subsection: Option<Cow<'event, BStr>>, + ) -> Result<SectionMut<'_, 'event>, section::header::Error> { let id = self.push_section_internal(file::Section::new(name, subsection, OwnShared::clone(&self.meta))?); let nl = self.detect_newline_style_smallvec(); let mut section = self.sections.get_mut(&id).expect("each id yields a section").to_mut(nl); @@ -178,13 +210,13 @@ impl<'event> File<'event> { /// ``` /// # use gix_config::File; /// # use std::convert::TryFrom; - /// let mut gix_config = gix_config::File::try_from( + /// let mut git_config = gix_config::File::try_from( /// r#"[hello "world"] /// some-value = 4 /// "#)?; /// - /// let section = gix_config.remove_section("hello", Some("world".into())); - /// assert_eq!(gix_config.to_string(), ""); + /// let section = git_config.remove_section("hello", Some("world".into())); + /// assert_eq!(git_config.to_string(), ""); /// # Ok::<(), Box<dyn std::error::Error>>(()) /// ``` /// @@ -193,27 +225,26 @@ impl<'event> File<'event> { /// ``` /// # use gix_config::File; /// # use std::convert::TryFrom; - /// let mut gix_config = gix_config::File::try_from( + /// let mut git_config = gix_config::File::try_from( /// r#"[hello "world"] /// some-value = 4 /// [hello "world"] /// some-value = 5 /// "#)?; /// - /// let section = gix_config.remove_section("hello", Some("world".into())); - /// assert_eq!(gix_config.to_string(), "[hello \"world\"]\n some-value = 4\n"); + /// let section = git_config.remove_section("hello", Some("world".into())); + /// assert_eq!(git_config.to_string(), "[hello \"world\"]\n some-value = 4\n"); /// # Ok::<(), Box<dyn std::error::Error>>(()) /// ``` pub fn remove_section<'a>( &mut self, - name: &str, + name: impl AsRef<str>, subsection_name: impl Into<Option<&'a BStr>>, ) -> Option<file::Section<'event>> { let id = self - .section_ids_by_name_and_subname(name, subsection_name.into()) + .section_ids_by_name_and_subname(name.as_ref(), subsection_name.into()) .ok()? - .rev() - .next()?; + .next_back()?; self.remove_section_by_id(id) } @@ -256,12 +287,21 @@ impl<'event> File<'event> { /// later sections with the same name have precedent over earlier ones. pub fn remove_section_filter<'a>( &mut self, - name: &str, + name: impl AsRef<str>, subsection_name: impl Into<Option<&'a BStr>>, filter: &mut MetadataFilter, ) -> Option<file::Section<'event>> { + self.remove_section_filter_inner(name.as_ref(), subsection_name.into(), filter) + } + + fn remove_section_filter_inner( + &mut self, + name: &str, + subsection_name: Option<&BStr>, + filter: &mut MetadataFilter, + ) -> Option<file::Section<'event>> { let id = self - .section_ids_by_name_and_subname(name, subsection_name.into()) + .section_ids_by_name_and_subname(name, subsection_name) .ok()? .rev() .find(|id| filter(self.sections.get(id).expect("each id has a section").meta()))?; @@ -274,17 +314,13 @@ impl<'event> File<'event> { self.sections.remove(&id) } - /// Adds the provided section to the config, returning a mutable reference - /// to it for immediate editing. + /// Adds the provided `section` to the config, returning a mutable reference to it for immediate editing. /// Note that its meta-data will remain as is. - pub fn push_section( - &mut self, - section: file::Section<'event>, - ) -> Result<SectionMut<'_, 'event>, section::header::Error> { + pub fn push_section(&mut self, section: file::Section<'event>) -> SectionMut<'_, 'event> { let id = self.push_section_internal(section); let nl = self.detect_newline_style_smallvec(); let section = self.sections.get_mut(&id).expect("each id yields a section").to_mut(nl); - Ok(section) + section } /// Renames the section with `name` and `subsection_name`, modifying the last matching section @@ -298,8 +334,7 @@ impl<'event> File<'event> { ) -> Result<(), rename_section::Error> { let id = self .section_ids_by_name_and_subname(name.as_ref(), subsection_name.into())? - .rev() - .next() + .next_back() .expect("list of sections were empty, which violates invariant"); let section = self.sections.get_mut(&id).expect("known section-id"); section.header = section::Header::new(new_name, new_subsection_name)?; 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(§ion_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(§ion_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>( diff --git a/vendor/gix-config/src/file/access/read_only.rs b/vendor/gix-config/src/file/access/read_only.rs index 5520c6566..eb1071fe2 100644 --- a/vendor/gix-config/src/file/access/read_only.rs +++ b/vendor/gix-config/src/file/access/read_only.rs @@ -42,11 +42,11 @@ impl<'event> File<'event> { /// a = 10k /// c = false /// "#; - /// let gix_config = gix_config::File::try_from(config)?; + /// let git_config = gix_config::File::try_from(config)?; /// // You can either use the turbofish to determine the type... - /// let a_value = gix_config.value::<Integer>("core", None, "a")?; + /// let a_value = git_config.value::<Integer>("core", None, "a")?; /// // ... or explicitly declare the type to avoid the turbofish - /// let c_value: Boolean = gix_config.value("core", None, "c")?; + /// let c_value: Boolean = git_config.value("core", None, "c")?; /// # Ok::<(), Box<dyn std::error::Error>>(()) /// ``` pub fn value<'a, T: TryFrom<Cow<'a, BStr>>>( @@ -96,9 +96,9 @@ impl<'event> File<'event> { /// a /// a = false /// "#; - /// let gix_config = gix_config::File::try_from(config).unwrap(); + /// let git_config = gix_config::File::try_from(config).unwrap(); /// // You can either use the turbofish to determine the type... - /// let a_value = gix_config.values::<Boolean>("core", None, "a")?; + /// let a_value = git_config.values::<Boolean>("core", None, "a")?; /// assert_eq!( /// a_value, /// vec![ @@ -108,7 +108,7 @@ impl<'event> File<'event> { /// ] /// ); /// // ... or explicitly declare the type to avoid the turbofish - /// let c_value: Vec<Boolean> = gix_config.values("core", None, "c").unwrap(); + /// let c_value: Vec<Boolean> = git_config.values("core", None, "c").unwrap(); /// assert_eq!(c_value, vec![Boolean(false)]); /// # Ok::<(), Box<dyn std::error::Error>>(()) /// ``` @@ -131,7 +131,7 @@ impl<'event> File<'event> { /// Returns the last found immutable section with a given `name` and optional `subsection_name`. pub fn section( &self, - name: impl AsRef<str>, + name: &str, subsection_name: Option<&BStr>, ) -> Result<&file::Section<'event>, lookup::existing::Error> { self.section_filter(name, subsection_name, &mut |_| true)? @@ -140,10 +140,7 @@ impl<'event> File<'event> { /// Returns the last found immutable section with a given `key`, identifying the name and subsection name like `core` /// or `remote.origin`. - pub fn section_by_key<'a>( - &self, - key: impl Into<&'a BStr>, - ) -> Result<&file::Section<'event>, lookup::existing::Error> { + pub fn section_by_key(&self, key: &BStr) -> Result<&file::Section<'event>, lookup::existing::Error> { let key = crate::parse::section::unvalidated::Key::parse(key).ok_or(lookup::existing::Error::KeyMissing)?; self.section(key.section_name, key.subsection_name) } @@ -154,7 +151,7 @@ impl<'event> File<'event> { /// is returned. pub fn section_filter<'a>( &'a self, - name: impl AsRef<str>, + name: &str, subsection_name: Option<&BStr>, filter: &mut MetadataFilter, ) -> Result<Option<&'a file::Section<'event>>, lookup::existing::Error> { @@ -171,9 +168,9 @@ impl<'event> File<'event> { } /// Like [`section_filter()`][File::section_filter()], but identifies the section with `key` like `core` or `remote.origin`. - pub fn section_filter_by_key<'a, 'b>( + pub fn section_filter_by_key<'a>( &'a self, - key: impl Into<&'b BStr>, + key: &BStr, filter: &mut MetadataFilter, ) -> Result<Option<&'a file::Section<'event>>, lookup::existing::Error> { let key = crate::parse::section::unvalidated::Key::parse(key).ok_or(lookup::existing::Error::KeyMissing)?; @@ -210,8 +207,8 @@ impl<'event> File<'event> { /// [core "apple"] /// e = f /// "#; - /// let gix_config = gix_config::File::try_from(config)?; - /// assert_eq!(gix_config.sections_by_name("core").map_or(0, |s|s.count()), 3); + /// let git_config = gix_config::File::try_from(config)?; + /// assert_eq!(git_config.sections_by_name("core").map_or(0, |s|s.count()), 3); /// # Ok::<(), Box<dyn std::error::Error>>(()) /// ``` #[must_use] diff --git a/vendor/gix-config/src/file/init/comfort.rs b/vendor/gix-config/src/file/init/comfort.rs index aa77fb9c0..4a5a1c68b 100644 --- a/vendor/gix-config/src/file/init/comfort.rs +++ b/vendor/gix-config/src/file/init/comfort.rs @@ -1,3 +1,5 @@ +use std::borrow::Cow; + use crate::{ file::{init, Metadata}, path, source, File, Source, @@ -30,7 +32,7 @@ impl File<'static> { let path = source .storage_location(&mut gix_path::env::var) .and_then(|p| p.is_file().then_some(p)) - .map(|p| p.into_owned()); + .map(Cow::into_owned); Metadata { path, @@ -53,9 +55,9 @@ impl File<'static> { /// A typical use of this is to [`append`][File::append()] this configuration to another one with lower /// precedence to obtain overrides. /// - /// See [`gix-config`'s documentation] for more information on the environment variables in question. + /// See [`git-config`'s documentation] for more information on the environment variables in question. /// - /// [`gix-config`'s documentation]: https://git-scm.com/docs/gix-config#Documentation/gix-config.txt-GITCONFIGCOUNT + /// [`git-config`'s documentation]: https://git-scm.com/docs/git-config#Documentation/git-config.txt-GITCONFIGCOUNT pub fn from_environment_overrides() -> Result<File<'static>, init::from_env::Error> { let home = gix_path::env::home_dir(); let options = init::Options { @@ -80,16 +82,16 @@ impl File<'static> { /// /// Includes will be resolved within limits as some information like the git installation directory is missing to interpolate /// paths with as well as git repository information like the branch name. - pub fn from_git_dir(dir: impl Into<std::path::PathBuf>) -> Result<File<'static>, from_git_dir::Error> { + pub fn from_git_dir(dir: std::path::PathBuf) -> Result<File<'static>, from_git_dir::Error> { let (mut local, git_dir) = { let source = Source::Local; - let mut path = dir.into(); + let mut path = dir; path.push( source .storage_location(&mut gix_path::env::var) .expect("location available for local"), ); - let local = Self::from_path_no_includes(&path, source)?; + let local = Self::from_path_no_includes(path.clone(), source)?; path.pop(); (local, path) }; diff --git a/vendor/gix-config/src/file/init/from_env.rs b/vendor/gix-config/src/file/init/from_env.rs index 167d37399..2c487e595 100644 --- a/vendor/gix-config/src/file/init/from_env.rs +++ b/vendor/gix-config/src/file/init/from_env.rs @@ -31,11 +31,11 @@ pub enum Error { /// Instantiation from environment variables impl File<'static> { /// Generates a config from `GIT_CONFIG_*` environment variables or returns `Ok(None)` if no configuration was found. - /// See [`gix-config`'s documentation] for more information on the environment variables in question. + /// See [`git-config`'s documentation] for more information on the environment variables in question. /// /// With `options` configured, it's possible to resolve `include.path` or `includeIf.<condition>.path` directives as well. /// - /// [`gix-config`'s documentation]: https://git-scm.com/docs/gix-config#Documentation/gix-config.txt-GITCONFIGCOUNT + /// [`git-config`'s documentation]: https://git-scm.com/docs/git-config#Documentation/git-config.txt-GITCONFIGCOUNT pub fn from_env(options: init::Options<'_>) -> Result<Option<File<'static>>, Error> { use std::env; let count: usize = match env::var("GIT_CONFIG_COUNT") { diff --git a/vendor/gix-config/src/file/init/from_paths.rs b/vendor/gix-config/src/file/init/from_paths.rs index 0eb7de69b..c0412a95f 100644 --- a/vendor/gix-config/src/file/init/from_paths.rs +++ b/vendor/gix-config/src/file/init/from_paths.rs @@ -23,8 +23,7 @@ impl File<'static> { /// Load the single file at `path` with `source` without following include directives. /// /// Note that the path will be checked for ownership to derive trust. - pub fn from_path_no_includes(path: impl Into<std::path::PathBuf>, source: crate::Source) -> Result<Self, Error> { - let path = path.into(); + pub fn from_path_no_includes(path: std::path::PathBuf, source: crate::Source) -> Result<Self, Error> { let trust = match gix_sec::Trust::from_path_ownership(&path) { Ok(t) => t, Err(err) => return Err(Error::Io { source: err, path }), @@ -49,7 +48,7 @@ impl File<'static> { )?) } - /// Constructs a `gix-config` file from the provided metadata, which must include a path to read from or be ignored. + /// Constructs a `git-config` file from the provided metadata, which must include a path to read from or be ignored. /// Returns `Ok(None)` if there was not a single input path provided, which is a possibility due to /// [`Metadata::path`] being an `Option`. /// If an input path doesn't exist, the entire operation will abort. See [`from_paths_metadata_buf()`][Self::from_paths_metadata_buf()] @@ -60,7 +59,12 @@ impl File<'static> { ) -> Result<Option<Self>, Error> { let mut buf = Vec::with_capacity(512); let err_on_nonexisting_paths = true; - Self::from_paths_metadata_buf(path_meta, &mut buf, err_on_nonexisting_paths, options) + Self::from_paths_metadata_buf( + &mut path_meta.into_iter().map(Into::into), + &mut buf, + err_on_nonexisting_paths, + options, + ) } /// Like [`from_paths_metadata()`][Self::from_paths_metadata()], but will use `buf` to temporarily store the config file @@ -68,17 +72,14 @@ impl File<'static> { /// /// If `err_on_nonexisting_paths` is false, instead of aborting with error, we will continue to the next path instead. pub fn from_paths_metadata_buf( - path_meta: impl IntoIterator<Item = impl Into<Metadata>>, + path_meta: &mut dyn Iterator<Item = Metadata>, buf: &mut Vec<u8>, err_on_non_existing_paths: bool, options: Options<'_>, ) -> Result<Option<Self>, Error> { let mut target = None; let mut seen = BTreeSet::default(); - for (path, mut meta) in path_meta.into_iter().filter_map(|meta| { - let mut meta = meta.into(); - meta.path.take().map(|p| (p, meta)) - }) { + for (path, mut meta) in path_meta.filter_map(|mut meta| meta.path.take().map(|p| (p, meta))) { if !seen.insert(path.clone()) { continue; } @@ -91,7 +92,7 @@ impl File<'static> { Err(err) => { let err = Error::Io { source: err, path }; if options.ignore_io_errors { - log::warn!("ignoring: {err:#?}"); + gix_features::trace::warn!("ignoring: {err:#?}"); continue; } else { return Err(err); @@ -103,7 +104,7 @@ impl File<'static> { Ok(_) => {} Err(err) => { if options.ignore_io_errors { - log::warn!( + gix_features::trace::warn!( "ignoring: {:#?}", Error::Io { source: err, diff --git a/vendor/gix-config/src/file/mod.rs b/vendor/gix-config/src/file/mod.rs index 2dd8c88fe..e99c6eb94 100644 --- a/vendor/gix-config/src/file/mod.rs +++ b/vendor/gix-config/src/file/mod.rs @@ -1,4 +1,4 @@ -//! A high level wrapper around a single or multiple `gix-config` file, for reading and mutation. +//! A high level wrapper around a single or multiple `git-config` file, for reading and mutation. use std::{ borrow::Cow, collections::HashMap, @@ -66,7 +66,7 @@ pub struct Metadata { pub trust: gix_sec::Trust, } -/// A section in a gix-config file, like `[core]` or `[remote "origin"]`, along with all of its keys. +/// A section in a git-config file, like `[core]` or `[remote "origin"]`, along with all of its keys. #[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)] pub struct Section<'a> { header: crate::parse::section::Header<'a>, @@ -104,7 +104,7 @@ impl AddAssign<usize> for Size { /// This value does not imply any ordering between sections, as new sections /// with higher section IDs may be in between lower ID sections after `File` mutation. /// -/// We need to use a section id because `gix-config` permits sections with +/// We need to use a section id because `git-config` permits sections with /// identical names, making it ambiguous when used in maps, for instance. /// /// This id guaranteed to be unique, but not guaranteed to be compact. In other diff --git a/vendor/gix-config/src/file/mutable/mod.rs b/vendor/gix-config/src/file/mutable/mod.rs index ad99e09b9..506a5484d 100644 --- a/vendor/gix-config/src/file/mutable/mod.rs +++ b/vendor/gix-config/src/file/mutable/mod.rs @@ -9,10 +9,10 @@ pub(crate) mod section; pub(crate) mod value; fn escape_value(value: &BStr) -> BString { - let starts_with_whitespace = value.first().map_or(false, |b| b.is_ascii_whitespace()); + let starts_with_whitespace = value.first().map_or(false, u8::is_ascii_whitespace); let ends_with_whitespace = value .get(value.len().saturating_sub(1)) - .map_or(false, |b| b.is_ascii_whitespace()); + .map_or(false, u8::is_ascii_whitespace); let contains_comment_indicators = value.find_byteset(b";#").is_some(); let quote = starts_with_whitespace || ends_with_whitespace || contains_comment_indicators; @@ -74,7 +74,7 @@ impl<'a> Whitespace<'a> { .find_map(|(idx, e)| matches!(e, Event::SectionKey(_)).then(|| idx)); key_pos .map(|key_pos| { - let pre_key = s.0[..key_pos].iter().rev().next().and_then(|e| match e { + let pre_key = s.0[..key_pos].iter().next_back().and_then(|e| match e { Event::Whitespace(s) => Some(s.clone()), _ => None, }); diff --git a/vendor/gix-config/src/file/mutable/section.rs b/vendor/gix-config/src/file/mutable/section.rs index def68ac60..336ccad2d 100644 --- a/vendor/gix-config/src/file/mutable/section.rs +++ b/vendor/gix-config/src/file/mutable/section.rs @@ -123,10 +123,10 @@ impl<'a, 'event> SectionMut<'a, 'event> { /// Sets the last key value pair if it exists, or adds the new value. /// Returns the previous value if it replaced a value, or None if it adds /// the value. - pub fn set<'b>(&mut self, key: Key<'event>, value: impl Into<&'b BStr>) -> Option<Cow<'event, BStr>> { + pub fn set(&mut self, key: Key<'event>, value: &BStr) -> Option<Cow<'event, BStr>> { match self.key_and_value_range_by(&key) { None => { - self.push(key, Some(value.into())); + self.push(key, Some(value)); None } Some((key_range, value_range)) => { @@ -136,15 +136,15 @@ impl<'a, 'event> SectionMut<'a, 'event> { self.section .body .0 - .insert(range_start, Event::Value(escape_value(value.into()).into())); + .insert(range_start, Event::Value(escape_value(value).into())); Some(ret) } } } /// Removes the latest value by key and returns it, if it exists. - pub fn remove(&mut self, key: impl AsRef<str>) -> Option<Cow<'event, BStr>> { - let key = Key::from_str_unchecked(key.as_ref()); + pub fn remove(&mut self, key: &str) -> Option<Cow<'event, BStr>> { + let key = Key::from_str_unchecked(key); let (key_range, _value_range) = self.key_and_value_range_by(&key)?; Some(self.remove_internal(key_range, true)) } @@ -185,7 +185,7 @@ impl<'a, 'event> SectionMut<'a, 'event> { assert!( whitespace .as_deref() - .map_or(true, |ws| ws.iter().all(|b| b.is_ascii_whitespace())), + .map_or(true, |ws| ws.iter().all(u8::is_ascii_whitespace)), "input whitespace must only contain whitespace characters." ); self.whitespace.pre_key = whitespace; diff --git a/vendor/gix-config/src/file/section/body.rs b/vendor/gix-config/src/file/section/body.rs index 694de18bd..1bc12725c 100644 --- a/vendor/gix-config/src/file/section/body.rs +++ b/vendor/gix-config/src/file/section/body.rs @@ -18,14 +18,14 @@ impl<'event> Body<'event> { /// Note that we consider values without key separator `=` non-existing. #[must_use] pub fn value(&self, key: impl AsRef<str>) -> Option<Cow<'_, BStr>> { - self.value_implicit(key).flatten() + self.value_implicit(key.as_ref()).flatten() } /// Retrieves the last matching value in a section with the given key, if present, and indicates an implicit value with `Some(None)`, /// and a non-existing one as `None` #[must_use] - pub fn value_implicit(&self, key: impl AsRef<str>) -> Option<Option<Cow<'_, BStr>>> { - let key = Key::from_str_unchecked(key.as_ref()); + pub fn value_implicit(&self, key: &str) -> Option<Option<Cow<'_, BStr>>> { + let key = Key::from_str_unchecked(key); let (_key_range, range) = self.key_and_value_range_by(&key)?; let range = match range { None => return Some(None), @@ -54,8 +54,8 @@ impl<'event> Body<'event> { /// Retrieves all values that have the provided key name. This may return /// an empty vec, which implies there were no values with the provided key. #[must_use] - pub fn values(&self, key: impl AsRef<str>) -> Vec<Cow<'_, BStr>> { - let key = &Key::from_str_unchecked(key.as_ref()); + pub fn values(&self, key: &str) -> Vec<Cow<'_, BStr>> { + let key = &Key::from_str_unchecked(key); let mut values = Vec::new(); let mut expect_value = false; let mut concatenated_value = BString::default(); @@ -92,8 +92,8 @@ impl<'event> Body<'event> { /// Returns true if the section contains the provided key. #[must_use] - pub fn contains_key(&self, key: impl AsRef<str>) -> bool { - let key = &Key::from_str_unchecked(key.as_ref()); + pub fn contains_key(&self, key: &str) -> bool { + let key = &Key::from_str_unchecked(key); self.0.iter().any(|e| { matches!(e, Event::SectionKey(k) if k == key diff --git a/vendor/gix-config/src/file/section/mod.rs b/vendor/gix-config/src/file/section/mod.rs index f73405960..f07a145e3 100644 --- a/vendor/gix-config/src/file/section/mod.rs +++ b/vendor/gix-config/src/file/section/mod.rs @@ -74,7 +74,7 @@ impl<'a> Section<'a> { /// Stream ourselves to the given `out`, in order to reproduce this section mostly losslessly /// as it was parsed. - pub fn write_to(&self, mut out: impl std::io::Write) -> std::io::Result<()> { + pub fn write_to(&self, mut out: &mut dyn std::io::Write) -> std::io::Result<()> { self.header.write_to(&mut out)?; if self.body.0.is_empty() { diff --git a/vendor/gix-config/src/file/write.rs b/vendor/gix-config/src/file/write.rs index 29024170d..772054f95 100644 --- a/vendor/gix-config/src/file/write.rs +++ b/vendor/gix-config/src/file/write.rs @@ -17,8 +17,8 @@ impl File<'_> { /// as it was parsed, while writing only sections for which `filter` returns true. pub fn write_to_filter( &self, - mut out: impl std::io::Write, - mut filter: impl FnMut(&Section<'_>) -> bool, + mut out: &mut dyn std::io::Write, + mut filter: &mut dyn FnMut(&Section<'_>) -> bool, ) -> std::io::Result<()> { let nl = self.detect_newline_style(); @@ -65,8 +65,8 @@ impl File<'_> { /// Stream ourselves to the given `out`, in order to reproduce this file mostly losslessly /// as it was parsed. - pub fn write_to(&self, out: impl std::io::Write) -> std::io::Result<()> { - self.write_to_filter(out, |_| true) + pub fn write_to(&self, out: &mut dyn std::io::Write) -> std::io::Result<()> { + self.write_to_filter(out, &mut |_| true) } } @@ -76,7 +76,7 @@ pub(crate) fn ends_with_newline(e: &[crate::parse::Event<'_>], nl: impl AsRef<[u } e.iter() .rev() - .take_while(|e| e.to_bstr_lossy().iter().all(|b| b.is_ascii_whitespace())) + .take_while(|e| e.to_bstr_lossy().iter().all(u8::is_ascii_whitespace)) .find_map(|e| e.to_bstr_lossy().contains_str(nl.as_ref()).then_some(true)) .unwrap_or(false) } |