]>
git.proxmox.com Git - rustc.git/blob - vendor/gix-attributes/src/lib.rs
1 //! Parse `.gitattribute` files and provide utilities to match against them.
5 feature
= "document-features",
6 cfg_attr(doc
, doc
= ::document_features
::document_features
!())
8 #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
9 #![deny(missing_docs, rust_2018_idioms, unsafe_code)]
11 use byteyarn
::{Yarn, YarnRef}
;
12 pub use gix_glob
as glob
;
26 /// Parse attribute assignments line by line from `bytes`, and fail the operation on error.
28 /// For leniency, ignore errors using `filter_map(Result::ok)` for example.
29 pub fn parse(bytes
: &[u8]) -> parse
::Lines
<'_
> {
30 parse
::Lines
::new(bytes
)
33 /// The state an attribute can be in, referencing the value.
35 /// Note that this doesn't contain the name.
36 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
37 pub enum StateRef
<'a
> {
38 /// The attribute is listed, or has the special value 'true'
40 /// The attribute has the special value 'false', or was prefixed with a `-` sign.
42 /// The attribute is set to the given value, which followed the `=` sign.
43 /// Note that values can be empty.
44 Value(state
::ValueRef
<'a
>),
45 /// The attribute isn't mentioned with a given path or is explicitly set to `Unspecified` using the `!` sign.
49 /// The state an attribute can be in, owning the value.
51 /// Note that this doesn't contain the name.
52 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
54 /// The attribute is listed, or has the special value 'true'
56 /// The attribute has the special value 'false', or was prefixed with a `-` sign.
58 /// The attribute is set to the given value, which followed the `=` sign.
59 /// Note that values can be empty.
61 /// The attribute isn't mentioned with a given path or is explicitly set to `Unspecified` using the `!` sign.
65 /// Represents a validated attribute name
66 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
67 pub struct Name(pub(crate) Yarn
);
69 /// Holds a validated attribute name as a reference
70 #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Ord, PartialOrd)]
71 pub struct NameRef
<'a
>(YarnRef
<'a
, str>);
73 /// Name an attribute and describe it's assigned state.
74 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
75 pub struct Assignment
{
76 /// The validated name of the attribute.
78 /// The state of the attribute.
82 /// Holds validated attribute data as a reference
83 #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Ord, PartialOrd)]
84 pub struct AssignmentRef
<'a
> {
85 /// The name of the attribute.
86 pub name
: NameRef
<'a
>,
87 /// The state of the attribute.
88 pub state
: StateRef
<'a
>,
91 /// A grouping of lists of patterns while possibly keeping associated to their base path in order to find matches.
93 /// Pattern lists with base path are queryable relative to that base, otherwise they are relative to the repository root.
94 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Default)]
96 /// A list of pattern lists, each representing a patterns from a file or specified by hand, in the order they were
99 /// When matching, this order is reversed.
100 patterns
: Vec
<gix_glob
::search
::pattern
::List
<search
::Attributes
>>,
103 /// A list of known global sources for git attribute files in order of ascending precedence.
105 /// This means that values from the first variant will be returned first.
106 #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
108 /// The attribute file that the installation itself ships with.
110 /// System-wide attributes file. This is typically defined as
111 /// `$(prefix)/etc/gitattributes` (where prefix is the git-installation directory).
113 /// This is `<xdg-config-home>/git/attributes` and is git application configuration per user.
115 /// Note that there is no `~/.gitattributes` file.
117 /// The configuration of the repository itself, located in `$GIT_DIR/info/attributes`.