]> git.proxmox.com Git - rustc.git/blob - vendor/gix-attributes/src/lib.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / vendor / gix-attributes / src / lib.rs
1 //! Parse `.gitattribute` files and provide utilities to match against them.
2 //!
3 //! ## Feature Flags
4 #![cfg_attr(
5 feature = "document-features",
6 cfg_attr(doc, doc = ::document_features::document_features!())
7 )]
8 #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
9 #![deny(missing_docs, rust_2018_idioms, unsafe_code)]
10
11 use byteyarn::{Yarn, YarnRef};
12 pub use gix_glob as glob;
13
14 mod assignment;
15 ///
16 pub mod name;
17 ///
18 pub mod state;
19
20 ///
21 pub mod search;
22
23 ///
24 pub mod parse;
25
26 /// Parse attribute assignments line by line from `bytes`, and fail the operation on error.
27 ///
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)
31 }
32
33 /// The state an attribute can be in, referencing the value.
34 ///
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'
39 Set,
40 /// The attribute has the special value 'false', or was prefixed with a `-` sign.
41 Unset,
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.
46 Unspecified,
47 }
48
49 /// The state an attribute can be in, owning the value.
50 ///
51 /// Note that this doesn't contain the name.
52 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
53 pub enum State {
54 /// The attribute is listed, or has the special value 'true'
55 Set,
56 /// The attribute has the special value 'false', or was prefixed with a `-` sign.
57 Unset,
58 /// The attribute is set to the given value, which followed the `=` sign.
59 /// Note that values can be empty.
60 Value(state::Value),
61 /// The attribute isn't mentioned with a given path or is explicitly set to `Unspecified` using the `!` sign.
62 Unspecified,
63 }
64
65 /// Represents a validated attribute name
66 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
67 pub struct Name(pub(crate) Yarn);
68
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>);
72
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.
77 pub name: Name,
78 /// The state of the attribute.
79 pub state: State,
80 }
81
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>,
89 }
90
91 /// A grouping of lists of patterns while possibly keeping associated to their base path in order to find matches.
92 ///
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)]
95 pub struct Search {
96 /// A list of pattern lists, each representing a patterns from a file or specified by hand, in the order they were
97 /// specified in.
98 ///
99 /// When matching, this order is reversed.
100 patterns: Vec<gix_glob::search::pattern::List<search::Attributes>>,
101 }
102
103 /// A list of known global sources for git attribute files in order of ascending precedence.
104 ///
105 /// This means that values from the first variant will be returned first.
106 #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
107 pub enum Source {
108 /// The attribute file that the installation itself ships with.
109 GitInstallation,
110 /// System-wide attributes file. This is typically defined as
111 /// `$(prefix)/etc/gitattributes` (where prefix is the git-installation directory).
112 System,
113 /// This is `<xdg-config-home>/git/attributes` and is git application configuration per user.
114 ///
115 /// Note that there is no `~/.gitattributes` file.
116 Git,
117 /// The configuration of the repository itself, located in `$GIT_DIR/info/attributes`.
118 Local,
119 }
120
121 mod source;