Unified · Split
| @@ -1,8 +1,7 @@ | |||
| 1 | use std::borrow::Cow; | 1 | use std::borrow::Cow; |
| 2 | 2 | ||
| 3 | use crate::file::rename_section; | ||
| 4 | use crate::{ | 3 | use crate::{ |
| 5 | file::{MutableSection, SectionBody}, | 4 | file::{rename_section, MutableSection, SectionBody}, |
| 6 | lookup, | 5 | lookup, |
| 7 | parse::section, | 6 | parse::section, |
| 8 | File, | 7 | File, |
| @@ -2,9 +2,8 @@ use std::{borrow::Cow, collections::HashMap}; · 1 unmodified line | |||
| 2 | 2 | ||
| 3 | use bstr::BStr; | 3 | use bstr::BStr; |
| 4 | 4 | ||
| 5 | use crate::file::mutable::value::EntryData; | ||
| 6 | use crate::{ | 5 | use crate::{ |
| 7 | file::{Index, MutableMultiValue, MutableSection, MutableValue, Size}, | 6 | file::{mutable::value::EntryData, Index, MutableMultiValue, MutableSection, MutableValue, Size}, |
| 8 | lookup, | 7 | lookup, |
| 9 | parse::{section, Event}, | 8 | parse::{section, Event}, |
| 10 | File, | 9 | File, |
| @@ -1,6 +1,7 @@ | |||
| 1 | use crate::File; | ||
| 2 | use bstr::BString; | 1 | use bstr::BString; |
| 3 | 2 | ||
| 3 | use crate::File; | ||
| 4 | |||
| 4 | impl File<'_> { | 5 | impl File<'_> { |
| 5 | /// Serialize this type into a `BString` for convenience. | 6 | /// Serialize this type into a `BString` for convenience. |
| 6 | /// | 7 | /// |
| @@ -1,5 +1,4 @@ | |||
| 1 | use std::str::FromStr; | 1 | use std::{convert::TryFrom, fmt::Display, str::FromStr}; |
| 2 | use std::{convert::TryFrom, fmt::Display}; | ||
| 3 | 2 | ||
| 4 | use bstr::{BStr, BString}; | 3 | use bstr::{BStr, BString}; |
| 5 | 4 | ||
| @@ -2,8 +2,12 @@ use std::{borrow::Cow, path::PathBuf}; · 1 unmodified line | |||
| 2 | 2 | ||
| 3 | use bstr::BString; | 3 | use bstr::BString; |
| 4 | 4 | ||
| 5 | use crate::file::from_paths; | 5 | use crate::{ |
| 6 | use crate::{file::init::resolve_includes, parse::section, path::interpolate, File}; | 6 | file::{from_paths, init::resolve_includes}, |
| 7 | parse::section, | ||
| 8 | path::interpolate, | ||
| 9 | File, | ||
| 10 | }; | ||
| 7 | 11 | ||
| 8 | /// Represents the errors that may occur when calling [`File::from_env`][crate::File::from_env()]. | 12 | /// Represents the errors that may occur when calling [`File::from_env`][crate::File::from_env()]. |
| 9 | #[derive(Debug, thiserror::Error)] | 13 | #[derive(Debug, thiserror::Error)] |
| @@ -6,9 +6,13 @@ use std::{ · 5 unmodified lines | |||
| 6 | use bstr::{BStr, BString, ByteSlice, ByteVec}; | 6 | use bstr::{BStr, BString, ByteSlice, ByteVec}; |
| 7 | use git_ref::Category; | 7 | use git_ref::Category; |
| 8 | 8 | ||
| 9 | use crate::file::init::from_paths; | 9 | use crate::{ |
| 10 | use crate::file::init::from_paths::Options; | 10 | file::{ |
| 11 | use crate::{file::SectionBodyId, File}; | 11 | init::{from_paths, from_paths::Options}, |
| 12 | SectionBodyId, | ||
| 13 | }, | ||
| 14 | File, | ||
| 15 | }; | ||
| 12 | 16 | ||
| 13 | pub(crate) fn resolve_includes( | 17 | pub(crate) fn resolve_includes( |
| 14 | conf: &mut File<'static>, | 18 | conf: &mut File<'static>, |
| @@ -1,9 +1,9 @@ | |||
| 1 | use crate::file::SectionBody; | ||
| 2 | use crate::parse::Event; | ||
| 3 | use bstr::{BStr, BString}; | ||
| 4 | use bstr::{ByteSlice, ByteVec}; | ||
| 5 | use std::borrow::Cow; | 1 | use std::borrow::Cow; |
| 6 | 2 | ||
| 3 | use bstr::{BStr, BString, ByteSlice, ByteVec}; | ||
| 4 | |||
| 5 | use crate::{file::SectionBody, parse::Event}; | ||
| 6 | |||
| 7 | fn escape_value(value: &BStr) -> BString { | 7 | fn escape_value(value: &BStr) -> BString { |
| 8 | let starts_with_whitespace = value.get(0).map_or(false, |b| b.is_ascii_whitespace()); | 8 | let starts_with_whitespace = value.get(0).map_or(false, |b| b.is_ascii_whitespace()); |
| 9 | let ends_with_whitespace = value | 9 | let ends_with_whitespace = value |
| @@ -6,9 +6,11 @@ use std::{ · 5 unmodified lines | |||
| 6 | 6 | ||
| 7 | use bstr::{BStr, BString, ByteVec}; | 7 | use bstr::{BStr, BString, ByteVec}; |
| 8 | 8 | ||
| 9 | use crate::file::mutable::{escape_value, Whitespace}; | ||
| 10 | use crate::{ | 9 | use crate::{ |
| 11 | file::{Index, Size}, | 10 | file::{ |
| 11 | mutable::{escape_value, Whitespace}, | ||
| 12 | Index, Size, | ||
| 13 | }, | ||
| 12 | lookup, parse, | 14 | lookup, parse, |
| 13 | parse::{section::Key, Event}, | 15 | parse::{section::Key, Event}, |
| 14 | value::{normalize, normalize_bstr, normalize_bstring}, | 16 | value::{normalize, normalize_bstr, normalize_bstring}, |
| @@ -2,10 +2,15 @@ use std::{borrow::Cow, collections::HashMap, ops::DerefMut}; · 1 unmodified line | |||
| 2 | 2 | ||
| 3 | use bstr::{BStr, BString, ByteVec}; | 3 | use bstr::{BStr, BString, ByteVec}; |
| 4 | 4 | ||
| 5 | use crate::file::mutable::section::{MutableSection, SectionBody}; | ||
| 6 | use crate::file::mutable::{escape_value, Whitespace}; | ||
| 7 | use crate::{ | 5 | use crate::{ |
| 8 | file::{Index, SectionBodyId, Size}, | 6 | file::{ |
| 7 | mutable::{ | ||
| 8 | escape_value, | ||
| 9 | section::{MutableSection, SectionBody}, | ||
| 10 | Whitespace, | ||
| 11 | }, | ||
| 12 | Index, SectionBodyId, Size, | ||
| 13 | }, | ||
| 9 | lookup, | 14 | lookup, |
| 10 | parse::{section, Event}, | 15 | parse::{section, Event}, |
| 11 | value::{normalize_bstr, normalize_bstring}, | 16 | value::{normalize_bstr, normalize_bstring}, |
| @@ -10,8 +10,10 @@ use std::{ · 9 unmodified lines | |||
| 10 | 10 | ||
| 11 | use bstr::BStr; | 11 | use bstr::BStr; |
| 12 | 12 | ||
| 13 | use crate::file::{from_env, from_paths}; | 13 | use crate::{ |
| 14 | use crate::{lookup, File}; | 14 | file::{from_env, from_paths}, |
| 15 | lookup, File, | ||
| 16 | }; | ||
| 15 | 17 | ||
| 16 | // TODO: how does this relate to `File::from_env_paths()`? | 18 | // TODO: how does this relate to `File::from_env_paths()`? |
| 17 | #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] | 19 | #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] |
| @@ -1,8 +1,11 @@ | |||
| 1 | use crate::parse::section::{into_cow_bstr, Header, Name}; | 1 | use std::{borrow::Cow, fmt::Display}; |
| 2 | use crate::parse::Event; | 2 | |
| 3 | use bstr::{BStr, BString, ByteSlice, ByteVec}; | 3 | use bstr::{BStr, BString, ByteSlice, ByteVec}; |
| 4 | use std::borrow::Cow; | 4 | |
| 5 | use std::fmt::Display; | 5 | use crate::parse::{ |
| 6 | section::{into_cow_bstr, Header, Name}, | ||
| 7 | Event, | ||
| 8 | }; | ||
| 6 | 9 | ||
| 7 | /// The error returned by [`Header::new(…)`][super::Header::new()]. | 10 | /// The error returned by [`Header::new(…)`][super::Header::new()]. |
| 8 | #[derive(Debug, PartialOrd, PartialEq, thiserror::Error)] | 11 | #[derive(Debug, PartialOrd, PartialEq, thiserror::Error)] |
| @@ -2,9 +2,10 @@ mod section { · 1 unmodified line | |||
| 2 | 2 | ||
| 3 | mod header { | 3 | mod header { |
| 4 | mod write_to { | 4 | mod write_to { |
| 5 | use crate::parse::section; | ||
| 6 | use std::borrow::Cow; | 5 | use std::borrow::Cow; |
| 7 | 6 | ||
| 7 | use crate::parse::section; | ||
| 8 | |||
| 8 | fn header(name: &str, subsection: impl Into<Option<(&'static str, &'static str)>>) -> section::Header<'_> { | 9 | fn header(name: &str, subsection: impl Into<Option<(&'static str, &'static str)>>) -> section::Header<'_> { |
| 9 | let name = section::Name(Cow::Borrowed(name.into())); | 10 | let name = section::Name(Cow::Borrowed(name.into())); |
| 10 | if let Some((separator, subsection_name)) = subsection.into() { | 11 | if let Some((separator, subsection_name)) = subsection.into() { |
| @@ -51,8 +52,7 @@ pub(crate) mod util { · 40 unmodified lines | |||
| 51 | //! This module is only included for tests, and contains common unit test helper | 52 | //! This module is only included for tests, and contains common unit test helper |
| 52 | //! functions. | 53 | //! functions. |
| 53 | 54 | ||
| 54 | use std::borrow::Cow; | 55 | use std::{borrow::Cow, convert::TryFrom}; |
| 55 | use std::convert::TryFrom; | ||
| 56 | 56 | ||
| 57 | use crate::parse::{section, Comment, Event}; | 57 | use crate::parse::{section, Comment, Event}; |
| 58 | 58 | ||
| @@ -1,8 +1,7 @@ | |||
| 1 | mod rename_section { | 1 | mod rename_section { |
| 2 | use git_config::file::rename_section; | 2 | use std::{borrow::Cow, convert::TryFrom}; |
| 3 | use git_config::parse::section; | 3 | |
| 4 | use std::borrow::Cow; | 4 | use git_config::{file::rename_section, parse::section}; |
| 5 | use std::convert::TryFrom; | ||
| 6 | 5 | ||
| 7 | #[test] | 6 | #[test] |
| 8 | fn section_renaming_validates_new_name() { | 7 | fn section_renaming_validates_new_name() { |
| @@ -1,8 +1,9 @@ | |||
| 1 | use std::{borrow::Cow, env, fs}; | 1 | use std::{borrow::Cow, env, fs}; |
| 2 | 2 | ||
| 3 | use git_config::file::from_paths::Options; | 3 | use git_config::{ |
| 4 | use git_config::file::{from_env, from_paths}; | 4 | file::{from_env, from_paths, from_paths::Options}, |
| 5 | use git_config::File; | 5 | File, |
| 6 | }; | ||
| 6 | use serial_test::serial; | 7 | use serial_test::serial; |
| 7 | use tempfile::tempdir; | 8 | use tempfile::tempdir; |
| 8 | 9 | ||
| @@ -8,8 +8,10 @@ use std::{ · 7 unmodified lines | |||
| 8 | 8 | ||
| 9 | use bstr::{BString, ByteSlice}; | 9 | use bstr::{BString, ByteSlice}; |
| 10 | 10 | ||
| 11 | use crate::file::cow_str; | 11 | use crate::file::{ |
| 12 | use crate::file::init::from_paths::{escape_backslashes, includes::conditional::options_with_git_dir}; | 12 | cow_str, |
| 13 | init::from_paths::{escape_backslashes, includes::conditional::options_with_git_dir}, | ||
| 14 | }; | ||
| 13 | 15 | ||
| 14 | #[derive(Debug)] | 16 | #[derive(Debug)] |
| 15 | pub struct GitEnv { | 17 | pub struct GitEnv { |
| @@ -1,11 +1,9 @@ | |||
| 1 | use std::{fs, path::Path}; | 1 | use std::{fs, path::Path}; |
| 2 | 2 | ||
| 3 | use git_config::file::from_paths; | 3 | use git_config::{file::from_paths, path, File}; |
| 4 | use git_config::{path, File}; | ||
| 5 | use tempfile::tempdir; | 4 | use tempfile::tempdir; |
| 6 | 5 | ||
| 7 | use crate::file::cow_str; | 6 | use crate::file::{cow_str, init::from_paths::escape_backslashes}; |
| 8 | use crate::file::init::from_paths::escape_backslashes; | ||
| 9 | 7 | ||
| 10 | mod gitdir; | 8 | mod gitdir; |
| 11 | mod onbranch; | 9 | mod onbranch; |
| @@ -1,11 +1,9 @@ | |||
| 1 | use std::fs; | 1 | use std::fs; |
| 2 | 2 | ||
| 3 | use git_config::file::from_paths; | 3 | use git_config::{file::from_paths, File}; |
| 4 | use git_config::File; | ||
| 5 | use tempfile::tempdir; | 4 | use tempfile::tempdir; |
| 6 | 5 | ||
| 7 | use crate::file::cow_str; | 6 | use crate::file::{cow_str, init::from_paths::escape_backslashes}; |
| 8 | use crate::file::init::from_paths::escape_backslashes; | ||
| 9 | 7 | ||
| 10 | #[test] | 8 | #[test] |
| 11 | fn multiple() -> crate::Result { | 9 | fn multiple() -> crate::Result { |
| @@ -1,6 +1,5 @@ | |||
| 1 | mod get { | 1 | mod get { |
| 2 | use crate::file::cow_str; | 2 | use crate::file::{cow_str, mutable::multi_value::init_config}; |
| 3 | use crate::file::mutable::multi_value::init_config; | ||
| 4 | 3 | ||
| 5 | #[test] | 4 | #[test] |
| 6 | fn single_lines() -> crate::Result { | 5 | fn single_lines() -> crate::Result { |
| @@ -50,8 +49,7 @@ mod access { · 43 unmodified lines | |||
| 50 | } | 49 | } |
| 51 | 50 | ||
| 52 | mod set { | 51 | mod set { |
| 53 | use crate::file::cow_str; | 52 | use crate::file::{cow_str, mutable::multi_value::init_config}; |
| 54 | use crate::file::mutable::multi_value::init_config; | ||
| 55 | 53 | ||
| 56 | #[test] | 54 | #[test] |
| 57 | fn values_are_escaped() -> crate::Result { | 55 | fn values_are_escaped() -> crate::Result { |
| @@ -1,8 +1,10 @@ | |||
| 1 | mod push { | 1 | mod push { |
| 2 | use crate::file::cow_str; | ||
| 3 | use git_config::parse::section::Key; | ||
| 4 | use std::convert::TryFrom; | 2 | use std::convert::TryFrom; |
| 5 | 3 | ||
| 4 | use git_config::parse::section::Key; | ||
| 5 | |||
| 6 | use crate::file::cow_str; | ||
| 7 | |||
| 6 | #[test] | 8 | #[test] |
| 7 | fn whitespace_is_derived_from_whitespace_before_first_value() -> crate::Result { | 9 | fn whitespace_is_derived_from_whitespace_before_first_value() -> crate::Result { |
| 8 | for (input, expected_pre_key, expected_sep) in [ | 10 | for (input, expected_pre_key, expected_sep) in [ |
| @@ -58,10 +60,12 @@ mod push { · 49 unmodified lines | |||
| 58 | } | 60 | } |
| 59 | 61 | ||
| 60 | mod set_leading_whitespace { | 62 | mod set_leading_whitespace { |
| 61 | use crate::file::cow_str; | ||
| 62 | use git_config::parse::section::Key; | ||
| 63 | use std::convert::TryFrom; | 63 | use std::convert::TryFrom; |
| 64 | 64 | ||
| 65 | use git_config::parse::section::Key; | ||
| 66 | |||
| 67 | use crate::file::cow_str; | ||
| 68 | |||
| 65 | #[test] | 69 | #[test] |
| 66 | fn any_whitespace_is_ok() -> crate::Result { | 70 | fn any_whitespace_is_ok() -> crate::Result { |
| 67 | let mut config = git_config::File::default(); | 71 | let mut config = git_config::File::default(); |
| @@ -1,7 +1,8 @@ | |||
| 1 | mod get { | 1 | mod get { |
| 2 | use crate::file::mutable::value::init_config; | ||
| 3 | use bstr::BString; | 2 | use bstr::BString; |
| 4 | 3 | ||
| 4 | use crate::file::mutable::value::init_config; | ||
| 5 | |||
| 5 | fn config_get(input: &str) -> BString { | 6 | fn config_get(input: &str) -> BString { |
| 6 | let mut file: git_config::File = input.parse().unwrap(); | 7 | let mut file: git_config::File = input.parse().unwrap(); |
| 7 | file.raw_value_mut("a", None, "k").unwrap().get().unwrap().into_owned() | 8 | file.raw_value_mut("a", None, "k").unwrap().get().unwrap().into_owned() |
| @@ -1,6 +1,7 @@ | |||
| 1 | use super::*; | ||
| 2 | use git_config::parse::Events; | 1 | use git_config::parse::Events; |
| 3 | 2 | ||
| 3 | use super::*; | ||
| 4 | |||
| 4 | #[test] | 5 | #[test] |
| 5 | #[rustfmt::skip] | 6 | #[rustfmt::skip] |
| 6 | fn complex() { | 7 | fn complex() { |
| @@ -1,5 +1,4 @@ | |||
| 1 | use std::borrow::Cow; | 1 | use std::{borrow::Cow, convert::TryFrom}; |
| 2 | use std::convert::TryFrom; | ||
| 3 | 2 | ||
| 4 | use git_config::parse::{Event, Events, Section}; | 3 | use git_config::parse::{Event, Events, Section}; |
| 5 | 4 | ||
| @@ -1,16 +1,17 @@ | |||
| 1 | use git_config::parse::section; | ||
| 2 | use git_config::parse::Event; | ||
| 3 | use std::borrow::Cow; | 1 | use std::borrow::Cow; |
| 4 | 2 | ||
| 3 | use git_config::parse::{section, Event}; | ||
| 4 | |||
| 5 | pub fn header_event(name: &'static str, subsection: impl Into<Option<&'static str>>) -> Event<'static> { | 5 | pub fn header_event(name: &'static str, subsection: impl Into<Option<&'static str>>) -> Event<'static> { |
| 6 | Event::SectionHeader(section::Header::new(name, subsection.into().map(Cow::Borrowed)).unwrap()) | 6 | Event::SectionHeader(section::Header::new(name, subsection.into().map(Cow::Borrowed)).unwrap()) |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | mod header { | 9 | mod header { |
| 10 | mod write_to { | 10 | mod write_to { |
| 11 | use git_config::parse::section; | ||
| 12 | use std::borrow::Cow; | 11 | use std::borrow::Cow; |
| 13 | 12 | ||
| 13 | use git_config::parse::section; | ||
| 14 | |||
| 14 | #[test] | 15 | #[test] |
| 15 | fn subsection_backslashes_and_quotes_are_escaped() -> crate::Result { | 16 | fn subsection_backslashes_and_quotes_are_escaped() -> crate::Result { |
| 16 | assert_eq!( | 17 | assert_eq!( |
| @@ -34,9 +35,10 @@ mod header { · 17 unmodified lines | |||
| 34 | } | 35 | } |
| 35 | } | 36 | } |
| 36 | mod new { | 37 | mod new { |
| 37 | use git_config::parse::section; | ||
| 38 | use std::borrow::Cow; | 38 | use std::borrow::Cow; |
| 39 | 39 | ||
| 40 | use git_config::parse::section; | ||
| 41 | |||
| 40 | #[test] | 42 | #[test] |
| 41 | fn names_must_be_mostly_ascii() { | 43 | fn names_must_be_mostly_ascii() { |
| 42 | for name in ["🤗", "x.y", "x y", "x\ny"] { | 44 | for name in ["🤗", "x.y", "x y", "x\ny"] { |
| @@ -61,9 +63,10 @@ mod header { · 18 unmodified lines | |||
| 61 | } | 63 | } |
| 62 | } | 64 | } |
| 63 | mod name { | 65 | mod name { |
| 64 | use git_config::parse::section::Name; | ||
| 65 | use std::convert::TryFrom; | 66 | use std::convert::TryFrom; |
| 66 | 67 | ||
| 68 | use git_config::parse::section::Name; | ||
| 69 | |||
| 67 | #[test] | 70 | #[test] |
| 68 | fn alphanum_and_dash_are_valid() { | 71 | fn alphanum_and_dash_are_valid() { |
| 69 | assert!(Name::try_from("1a").is_ok()); | 72 | assert!(Name::try_from("1a").is_ok()); |
| @@ -80,9 +83,9 @@ mod name { · 10 unmodified lines | |||
| 80 | } | 83 | } |
| 81 | 84 | ||
| 82 | mod key { | 85 | mod key { |
| 86 | use std::{cmp::Ordering, convert::TryFrom}; | ||
| 87 | |||
| 83 | use git_config::parse::section::Key; | 88 | use git_config::parse::section::Key; |
| 84 | use std::cmp::Ordering; | ||
| 85 | use std::convert::TryFrom; | ||
| 86 | 89 | ||
| 87 | fn key(k: &str) -> Key<'_> { | 90 | fn key(k: &str) -> Key<'_> { |
| 88 | Key::try_from(k).unwrap() | 91 | Key::try_from(k).unwrap() |