History

Merge branch 'yarn'

Sebastian Thiel committed 3 years ago

Commit 53bbd062 parents 14312b6 0fac1b910 files · +64 −47Browse files

Unified · Split

10 files
  1. Cargo.lock +7 −2
  2. gitoxide-core/src/repository/index/entries.rs +16 −3
  3. gix-attributes/Cargo.toml +2 −2
  4. gix-attributes/src/lib.rs +3 −8
  5. gix-attributes/src/name.rs +7 −3
  6. gix-attributes/src/parse.rs +2 −3
  7. gix-attributes/src/search/mod.rs +3 −3
  8. gix-attributes/src/search/outcome.rs +10 −7
  9. gix-attributes/src/state.rs +13 −15
  10. gix-attributes/tests/search/mod.rs +1 −1
Cargo.lock+7−2
@@ -395,6 +395,12 @@ dependencies = [ · 394 unmodified lines
395 "serde",395 "serde",
396]396]
397 397
398[[package]]
399name = "byteyarn"
400version = "0.2.3"
401source = "registry+https://github.com/rust-lang/crates.io-index"
402checksum = "a7534301c0ea17abb4db06d75efc7b4b0fa360fce8e175a4330d721c71c942ff"
403
398[[package]]404[[package]]
399name = "cassowary"405name = "cassowary"
400version = "0.3.0"406version = "0.3.0"
@@ -1336,6 +1342,7 @@ name = "gix-attributes" · 935 unmodified lines
1336version = "0.18.0"1342version = "0.18.0"
1337dependencies = [1343dependencies = [
1338 "bstr",1344 "bstr",
1345 "byteyarn",
1339 "document-features",1346 "document-features",
1340 "gix-fs 0.6.0",1347 "gix-fs 0.6.0",
1341 "gix-glob 0.12.0",1348 "gix-glob 0.12.0",
@@ -1343,7 +1350,6 @@ dependencies = [ · 1 unmodified line
1343 "gix-quote 0.4.7",1350 "gix-quote 0.4.7",
1344 "gix-testtools",1351 "gix-testtools",
1345 "gix-trace 0.1.3",1352 "gix-trace 0.1.3",
1346 "kstring",
1347 "serde",1353 "serde",
1348 "smallvec",1354 "smallvec",
1349 "thiserror",1355 "thiserror",
@@ -2962,7 +2968,6 @@ version = "2.0.0" · 1612 unmodified lines
2962source = "registry+https://github.com/rust-lang/crates.io-index"2968source = "registry+https://github.com/rust-lang/crates.io-index"
2963checksum = "ec3066350882a1cd6d950d055997f379ac37fd39f81cd4d8ed186032eb3c5747"2969checksum = "ec3066350882a1cd6d950d055997f379ac37fd39f81cd4d8ed186032eb3c5747"
2964dependencies = [2970dependencies = [
2965 "serde",
2966 "static_assertions",2971 "static_assertions",
2967]2972]
2968 2973
gitoxide-core/src/repository/index/entries.rs+16−3
@@ -294,7 +294,13 @@ pub(crate) mod function { · 293 unmodified lines
294 Ok((pathspec.into_parts().0, index, cache))294 Ok((pathspec.into_parts().0, index, cache))
295 }295 }
296 296
297 #[cfg_attr(feature = "serde", derive(serde::Serialize))]297 #[cfg(feature = "serde")]
298 #[derive(serde::Serialize)]
299 struct AttrsForSerde {
300 is_excluded: bool,
301 attributes: Vec<String>,
302 }
303
298 struct Attrs {304 struct Attrs {
299 is_excluded: bool,305 is_excluded: bool,
300 attributes: Vec<gix::attrs::Assignment>,306 attributes: Vec<gix::attrs::Assignment>,
@@ -331,7 +337,7 @@ pub(crate) mod function { · 30 unmodified lines
331 flags: u32,337 flags: u32,
332 mode: u32,338 mode: u32,
333 path: std::borrow::Cow<'a, str>,339 path: std::borrow::Cow<'a, str>,
334 meta: Option<Attrs>,340 meta: Option<AttrsForSerde>,
335 }341 }
336 342
337 serde_json::to_writer(343 serde_json::to_writer(
@@ -348,7 +354,14 @@ pub(crate) mod function { · 10 unmodified lines
348 path.extend_from_slice(entry.path(index));354 path.extend_from_slice(entry.path(index));
349 path.to_string().into()355 path.to_string().into()
350 },356 },
351 meta: attrs,357 meta: attrs.map(|attrs| AttrsForSerde {
358 is_excluded: attrs.is_excluded,
359 attributes: attrs
360 .attributes
361 .into_iter()
362 .map(|attr| attr.as_ref().to_string())
363 .collect(),
364 }),
352 },365 },
353 )?;366 )?;
354 367
gix-attributes/Cargo.toml+2−2
@@ -14,7 +14,7 @@ doctest = false · 13 unmodified lines
14 14
15[features]15[features]
16## Data structures implement `serde::Serialize` and `serde::Deserialize`.16## Data structures implement `serde::Serialize` and `serde::Deserialize`.
17serde = ["dep:serde", "bstr/serde", "gix-glob/serde", "kstring/serde"]17serde = ["dep:serde", "bstr/serde", "gix-glob/serde"]
18 18
19[dependencies]19[dependencies]
20gix-path = { version = "^0.10.0", path = "../gix-path" }20gix-path = { version = "^0.10.0", path = "../gix-path" }
@@ -24,7 +24,7 @@ gix-trace = { version = "^0.1.3", path = "../gix-trace" } · 3 unmodified lines
24 24
25bstr = { version = "1.3.0", default-features = false, features = ["std", "unicode"]}25bstr = { version = "1.3.0", default-features = false, features = ["std", "unicode"]}
26smallvec = "1.10.0"26smallvec = "1.10.0"
27kstring = "2.0.0"27byteyarn = "0.2.3"
28unicode-bom = "2.0.2"28unicode-bom = "2.0.2"
29thiserror = "1.0.26"29thiserror = "1.0.26"
30serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}30serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}
gix-attributes/src/lib.rs+3−8
@@ -8,8 +8,8 @@ · 7 unmodified lines
8#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]8#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
9#![deny(missing_docs, rust_2018_idioms, unsafe_code)]9#![deny(missing_docs, rust_2018_idioms, unsafe_code)]
10 10
11use byteyarn::{Yarn, YarnRef};
11pub use gix_glob as glob;12pub use gix_glob as glob;
12use kstring::{KString, KStringRef};
13 13
14mod assignment;14mod assignment;
15///15///
@@ -34,7 +34,6 @@ pub fn parse(bytes: &[u8]) -> parse::Lines<'_> { · 18 unmodified lines
34///34///
35/// Note that this doesn't contain the name.35/// Note that this doesn't contain the name.
36#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]36#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
37#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
38pub enum StateRef<'a> {37pub enum StateRef<'a> {
39 /// The attribute is listed, or has the special value 'true'38 /// The attribute is listed, or has the special value 'true'
40 Set,39 Set,
@@ -42,7 +41,6 @@ pub enum StateRef<'a> { · 1 unmodified line
42 Unset,41 Unset,
43 /// The attribute is set to the given value, which followed the `=` sign.42 /// The attribute is set to the given value, which followed the `=` sign.
44 /// Note that values can be empty.43 /// Note that values can be empty.
45 #[cfg_attr(feature = "serde", serde(borrow))]
46 Value(state::ValueRef<'a>),44 Value(state::ValueRef<'a>),
47 /// The attribute isn't mentioned with a given path or is explicitly set to `Unspecified` using the `!` sign.45 /// The attribute isn't mentioned with a given path or is explicitly set to `Unspecified` using the `!` sign.
48 Unspecified,46 Unspecified,
@@ -52,7 +50,6 @@ pub enum StateRef<'a> { · 3 unmodified lines
52///50///
53/// Note that this doesn't contain the name.51/// Note that this doesn't contain the name.
54#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]52#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
55#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
56pub enum State {53pub enum State {
57 /// The attribute is listed, or has the special value 'true'54 /// The attribute is listed, or has the special value 'true'
58 Set,55 Set,
@@ -67,16 +64,14 @@ pub enum State { · 8 unmodified lines
67 64
68/// Represents a validated attribute name65/// Represents a validated attribute name
69#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]66#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
70#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]67pub struct Name(pub(crate) Yarn);
71pub struct Name(pub(crate) KString);
72 68
73/// Holds a validated attribute name as a reference69/// Holds a validated attribute name as a reference
74#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Ord, PartialOrd)]70#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Ord, PartialOrd)]
75pub struct NameRef<'a>(KStringRef<'a>);71pub struct NameRef<'a>(YarnRef<'a, str>);
76 72
77/// Name an attribute and describe it's assigned state.73/// Name an attribute and describe it's assigned state.
78#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]74#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
79#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
80pub struct Assignment {75pub struct Assignment {
81 /// The validated name of the attribute.76 /// The validated name of the attribute.
82 pub name: Name,77 pub name: Name,
gix-attributes/src/name.rs+7−3
@@ -1,12 +1,16 @@
1use bstr::{BStr, BString, ByteSlice};1use bstr::{BStr, BString, ByteSlice};
2use kstring::KStringRef;2use byteyarn::YarnRef;
3 3
4use crate::{Name, NameRef};4use crate::{Name, NameRef};
5 5
6impl<'a> NameRef<'a> {6impl<'a> NameRef<'a> {
7 /// Turn this ref into its owned counterpart.7 /// Turn this ref into its owned counterpart.
8 pub fn to_owned(self) -> Name {8 pub fn to_owned(self) -> Name {
9 Name(self.0.into())9 Name(
10 self.0
11 .immortalize()
12 .map_or_else(|| self.0.to_boxed_str().into(), YarnRef::to_box),
13 )
10 }14 }
11 15
12 /// Return the inner `str`.16 /// Return the inner `str`.
@@ -35,7 +39,7 @@ impl<'a> TryFrom<&'a BStr> for NameRef<'a> { · 22 unmodified lines
35 }39 }
36 40
37 attr_valid(attr)41 attr_valid(attr)
38 .then(|| NameRef(KStringRef::from_ref(attr.to_str().expect("no illformed utf8"))))42 .then(|| NameRef(YarnRef::from(attr.to_str().expect("no illformed utf8"))))
39 .ok_or_else(|| Error { attribute: attr.into() })43 .ok_or_else(|| Error { attribute: attr.into() })
40 }44 }
41}45}
gix-attributes/src/parse.rs+2−3
@@ -1,13 +1,12 @@
1use std::borrow::Cow;1use std::borrow::Cow;
2 2
3use bstr::{BStr, ByteSlice};3use bstr::{BStr, ByteSlice};
4use kstring::KStringRef;4use byteyarn::YarnRef;
5 5
6use crate::{name, AssignmentRef, Name, NameRef, StateRef};6use crate::{name, AssignmentRef, Name, NameRef, StateRef};
7 7
8/// The kind of attribute that was parsed.8/// The kind of attribute that was parsed.
9#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]9#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub enum Kind {10pub enum Kind {
12 /// A pattern to match paths against11 /// A pattern to match paths against
13 Pattern(gix_glob::Pattern),12 Pattern(gix_glob::Pattern),
@@ -76,7 +75,7 @@ fn check_attr(attr: &BStr) -> Result<NameRef<'_>, name::Error> { · 62 unmodified lines
76 }75 }
77 76
78 attr_valid(attr)77 attr_valid(attr)
79 .then(|| NameRef(KStringRef::from_ref(attr.to_str().expect("no illformed utf8"))))78 .then(|| NameRef(YarnRef::from(attr.to_str().expect("no illformed utf8"))))
80 .ok_or_else(|| name::Error { attribute: attr.into() })79 .ok_or_else(|| name::Error { attribute: attr.into() })
81}80}
82 81
gix-attributes/src/search/mod.rs+3−3
@@ -1,6 +1,6 @@
1use std::collections::HashMap;1use std::collections::HashMap;
2 2
3use kstring::KString;3use byteyarn::Yarn;
4use smallvec::SmallVec;4use smallvec::SmallVec;
5 5
6use crate::{Assignment, AssignmentRef};6use crate::{Assignment, AssignmentRef};
@@ -99,7 +99,7 @@ pub struct Outcome { · 92 unmodified lines
99 /// A stack of attributes to use for processing attributes of matched patterns and for resolving their macros.99 /// A stack of attributes to use for processing attributes of matched patterns and for resolving their macros.
100 attrs_stack: SmallVec<[(AttributeId, Assignment, Option<AttributeId>); 8]>,100 attrs_stack: SmallVec<[(AttributeId, Assignment, Option<AttributeId>); 8]>,
101 /// A set of attributes we should limit ourselves to, or empty if we should fill in all attributes, made of101 /// A set of attributes we should limit ourselves to, or empty if we should fill in all attributes, made of
102 selected: SmallVec<[(KString, Option<AttributeId>); AVERAGE_NUM_ATTRS]>,102 selected: SmallVec<[(Yarn, Option<AttributeId>); AVERAGE_NUM_ATTRS]>,
103 /// storage for all patterns we have matched so far (in order to avoid referencing them, we copy them, but only once).103 /// storage for all patterns we have matched so far (in order to avoid referencing them, we copy them, but only once).
104 patterns: RefMap<gix_glob::Pattern>,104 patterns: RefMap<gix_glob::Pattern>,
105 /// storage for all assignments we have matched so far (in order to avoid referencing them, we copy them, but only once).105 /// storage for all assignments we have matched so far (in order to avoid referencing them, we copy them, but only once).
@@ -135,7 +135,7 @@ pub struct MetadataCollection { · 29 unmodified lines
135 /// A mapping of an attribute or macro name to its order, that is the time when it was *first* seen.135 /// A mapping of an attribute or macro name to its order, that is the time when it was *first* seen.
136 ///136 ///
137 /// This is the inverse of the order attributes are searched.137 /// This is the inverse of the order attributes are searched.
138 name_to_meta: HashMap<KString, Metadata>,138 name_to_meta: HashMap<Yarn, Metadata>,
139}139}
140 140
141/// Metadata associated with an attribute or macro name.141/// Metadata associated with an attribute or macro name.
gix-attributes/src/search/outcome.rs+10−7
@@ -1,6 +1,6 @@
1use bstr::{BString, ByteSlice};1use bstr::{BString, ByteSlice};
2use byteyarn::Yarn;
2use gix_glob::Pattern;3use gix_glob::Pattern;
3use kstring::{KString, KStringRef};
4 4
5use crate::{5use crate::{
6 search::{6 search::{
@@ -44,7 +44,7 @@ impl Outcome { · 37 unmodified lines
44 pub fn initialize_with_selection<'a>(44 pub fn initialize_with_selection<'a>(
45 &mut self,45 &mut self,
46 collection: &MetadataCollection,46 collection: &MetadataCollection,
47 attribute_names: impl IntoIterator<Item = impl Into<KStringRef<'a>>>,47 attribute_names: impl IntoIterator<Item = impl Into<&'a str>>,
48 ) {48 ) {
49 self.initialize_with_selection_inner(collection, &mut attribute_names.into_iter().map(Into::into))49 self.initialize_with_selection_inner(collection, &mut attribute_names.into_iter().map(Into::into))
50 }50 }
@@ -52,15 +52,15 @@ impl Outcome { · 1 unmodified line
52 fn initialize_with_selection_inner(52 fn initialize_with_selection_inner(
53 &mut self,53 &mut self,
54 collection: &MetadataCollection,54 collection: &MetadataCollection,
55 attribute_names: &mut dyn Iterator<Item = KStringRef<'_>>,55 attribute_names: &mut dyn Iterator<Item = &str>,
56 ) {56 ) {
57 self.initialize(collection);57 self.initialize(collection);
58 58
59 self.selected.clear();59 self.selected.clear();
60 self.selected.extend(attribute_names.map(|name| {60 self.selected.extend(attribute_names.map(|name| {
61 (61 (
62 name.to_owned(),62 Yarn::inlined(name).unwrap_or_else(|| name.to_string().into_boxed_str().into()),
63 collection.name_to_meta.get(name.as_str()).map(|meta| meta.id),63 collection.name_to_meta.get(name).map(|meta| meta.id),
64 )64 )
65 }));65 }));
66 self.reset_remaining();66 self.reset_remaining();
@@ -315,7 +315,7 @@ impl MetadataCollection { · 248 unmodified lines
315 None => {315 None => {
316 let order = AttributeId(self.name_to_meta.len());316 let order = AttributeId(self.name_to_meta.len());
317 self.name_to_meta.insert(317 self.name_to_meta.insert(
318 KString::from_ref(name),318 Yarn::inlined(name).unwrap_or_else(|| name.to_string().into_boxed_str().into()),
319 Metadata {319 Metadata {
320 id: order,320 id: order,
321 macro_attributes: Default::default(),321 macro_attributes: Default::default(),
@@ -335,7 +335,10 @@ impl MetadataCollection { · 13 unmodified lines
335 Some(meta) => meta.id,335 Some(meta) => meta.id,
336 None => {336 None => {
337 let order = AttributeId(self.name_to_meta.len());337 let order = AttributeId(self.name_to_meta.len());
338 self.name_to_meta.insert(KString::from_ref(name), order.into());338 self.name_to_meta.insert(
339 Yarn::inlined(name).unwrap_or_else(|| name.to_string().into_boxed_str().into()),
340 order.into(),
341 );
339 order342 order
340 }343 }
341 }344 }
gix-attributes/src/state.rs+13−15
@@ -1,29 +1,21 @@
1use bstr::{BStr, ByteSlice};1use bstr::{BStr, ByteSlice};
2use kstring::{KString, KStringRef};2use byteyarn::{ByteYarn, YarnRef};
3 3
4use crate::{State, StateRef};4use crate::{State, StateRef};
5 5
6/// A container to encapsulate a tightly packed and typically unallocated byte value that isn't necessarily UTF8 encoded.6/// A container to encapsulate a tightly packed and typically unallocated byte value that isn't necessarily UTF8 encoded.
7#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]7#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]8pub struct Value(ByteYarn);
9pub struct Value(KString);
10 9
11/// A reference container to encapsulate a tightly packed and typically unallocated byte value that isn't necessarily UTF8 encoded.10/// A reference container to encapsulate a tightly packed and typically unallocated byte value that isn't necessarily UTF8 encoded.
12#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]11#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
13#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]12pub struct ValueRef<'a>(YarnRef<'a, [u8]>);
14pub struct ValueRef<'a>(#[cfg_attr(feature = "serde", serde(borrow))] KStringRef<'a>);
15 13
16/// Lifecycle14/// Lifecycle
17impl<'a> ValueRef<'a> {15impl<'a> ValueRef<'a> {
18 /// Keep `input` as our value.16 /// Keep `input` as our value.
19 pub fn from_bytes(input: &'a [u8]) -> Self {17 pub fn from_bytes(input: &'a [u8]) -> Self {
20 Self(KStringRef::from_ref(18 Self(YarnRef::from(input))
21 // SAFETY: our API makes accessing that value as `str` impossible, so illformed UTF8 is never exposed as such.
22 #[allow(unsafe_code)]
23 unsafe {
24 std::str::from_utf8_unchecked(input)
25 },
26 ))
27 }19 }
28}20}
29 21
@@ -42,19 +34,25 @@ impl ValueRef<'_> { · 12 unmodified lines
42 34
43impl<'a> From<&'a str> for ValueRef<'a> {35impl<'a> From<&'a str> for ValueRef<'a> {
44 fn from(v: &'a str) -> Self {36 fn from(v: &'a str) -> Self {
45 ValueRef(v.into())37 ValueRef(v.as_bytes().into())
46 }38 }
47}39}
48 40
49impl<'a> From<ValueRef<'a>> for Value {41impl<'a> From<ValueRef<'a>> for Value {
50 fn from(v: ValueRef<'a>) -> Self {42 fn from(v: ValueRef<'a>) -> Self {
51 Value(v.0.into())43 Value(
44 v.0.immortalize()
45 .map_or_else(|| v.0.to_boxed_bytes().into(), YarnRef::to_box),
46 )
52 }47 }
53}48}
54 49
55impl From<&str> for Value {50impl From<&str> for Value {
56 fn from(v: &str) -> Self {51 fn from(v: &str) -> Self {
57 Value(KString::from_ref(v))52 Value(
53 ByteYarn::inlined(v.as_bytes())
54 .unwrap_or_else(|| ByteYarn::from_boxed_bytes(v.as_bytes().to_vec().into_boxed_slice())),
55 )
58 }56 }
59}57}
60 58
gix-attributes/tests/search/mod.rs+1−1
@@ -270,7 +270,7 @@ fn given_attributes_are_made_available_in_given_order() -> crate::Result { · 269 unmodified lines
270fn size_of_outcome() {270fn size_of_outcome() {
271 assert_eq!(271 assert_eq!(
272 std::mem::size_of::<Outcome>(),272 std::mem::size_of::<Outcome>(),
273 904,273 752,
274 "it's quite big, shouldn't change without us noticing"274 "it's quite big, shouldn't change without us noticing"
275 )275 )
276}276}