Show More
@@ -1,144 +1,152 | |||||
1 | // Copyright 2018-2020 Georges Racinet <georges.racinet@octobus.net> |
|
1 | // Copyright 2018-2020 Georges Racinet <georges.racinet@octobus.net> | |
2 | // and Mercurial contributors |
|
2 | // and Mercurial contributors | |
3 | // |
|
3 | // | |
4 | // This software may be used and distributed according to the terms of the |
|
4 | // This software may be used and distributed according to the terms of the | |
5 | // GNU General Public License version 2 or any later version. |
|
5 | // GNU General Public License version 2 or any later version. | |
6 | mod ancestors; |
|
6 | mod ancestors; | |
7 | pub mod dagops; |
|
7 | pub mod dagops; | |
8 | pub use ancestors::{AncestorsIterator, LazyAncestors, MissingAncestors}; |
|
8 | pub use ancestors::{AncestorsIterator, LazyAncestors, MissingAncestors}; | |
9 | mod dirstate; |
|
9 | mod dirstate; | |
10 | pub mod discovery; |
|
10 | pub mod discovery; | |
11 | pub mod testing; // unconditionally built, for use from integration tests |
|
11 | pub mod testing; // unconditionally built, for use from integration tests | |
12 | pub use dirstate::{ |
|
12 | pub use dirstate::{ | |
13 | dirs_multiset::{DirsMultiset, DirsMultisetIter}, |
|
13 | dirs_multiset::{DirsMultiset, DirsMultisetIter}, | |
14 | dirstate_map::DirstateMap, |
|
14 | dirstate_map::DirstateMap, | |
15 | parsers::{pack_dirstate, parse_dirstate, PARENT_SIZE}, |
|
15 | parsers::{pack_dirstate, parse_dirstate, PARENT_SIZE}, | |
16 | status::{status, StatusResult}, |
|
16 | status::{status, StatusResult}, | |
17 | CopyMap, CopyMapIter, DirstateEntry, DirstateParents, EntryState, |
|
17 | CopyMap, CopyMapIter, DirstateEntry, DirstateParents, EntryState, | |
18 | StateMap, StateMapIter, |
|
18 | StateMap, StateMapIter, | |
19 | }; |
|
19 | }; | |
20 | mod filepatterns; |
|
20 | mod filepatterns; | |
21 | pub mod matchers; |
|
21 | pub mod matchers; | |
22 | pub mod revlog; |
|
22 | pub mod revlog; | |
23 | pub use revlog::*; |
|
23 | pub use revlog::*; | |
24 | pub mod utils; |
|
24 | pub mod utils; | |
25 |
|
25 | |||
|
26 | /// Remove this to see (potential) non-artificial compile failures. MacOS | |||
|
27 | /// *should* compile, but fail to compile tests for example as of 2020-03-06 | |||
|
28 | #[cfg(not(target_os = "linux"))] | |||
|
29 | compile_error!( | |||
|
30 | "`hg-core` has only been tested on Linux and will most \ | |||
|
31 | likely not behave correctly on other platforms." | |||
|
32 | ); | |||
|
33 | ||||
26 | use crate::utils::hg_path::HgPathBuf; |
|
34 | use crate::utils::hg_path::HgPathBuf; | |
27 | pub use filepatterns::{ |
|
35 | pub use filepatterns::{ | |
28 | build_single_regex, read_pattern_file, PatternSyntax, PatternTuple, |
|
36 | build_single_regex, read_pattern_file, PatternSyntax, PatternTuple, | |
29 | }; |
|
37 | }; | |
30 | use std::collections::HashMap; |
|
38 | use std::collections::HashMap; | |
31 | use twox_hash::RandomXxHashBuilder64; |
|
39 | use twox_hash::RandomXxHashBuilder64; | |
32 |
|
40 | |||
33 | pub type LineNumber = usize; |
|
41 | pub type LineNumber = usize; | |
34 |
|
42 | |||
35 | /// Rust's default hasher is too slow because it tries to prevent collision |
|
43 | /// Rust's default hasher is too slow because it tries to prevent collision | |
36 | /// attacks. We are not concerned about those: if an ill-minded person has |
|
44 | /// attacks. We are not concerned about those: if an ill-minded person has | |
37 | /// write access to your repository, you have other issues. |
|
45 | /// write access to your repository, you have other issues. | |
38 | pub type FastHashMap<K, V> = HashMap<K, V, RandomXxHashBuilder64>; |
|
46 | pub type FastHashMap<K, V> = HashMap<K, V, RandomXxHashBuilder64>; | |
39 |
|
47 | |||
40 | #[derive(Clone, Debug, PartialEq)] |
|
48 | #[derive(Clone, Debug, PartialEq)] | |
41 | pub enum DirstateParseError { |
|
49 | pub enum DirstateParseError { | |
42 | TooLittleData, |
|
50 | TooLittleData, | |
43 | Overflow, |
|
51 | Overflow, | |
44 | CorruptedEntry(String), |
|
52 | CorruptedEntry(String), | |
45 | Damaged, |
|
53 | Damaged, | |
46 | } |
|
54 | } | |
47 |
|
55 | |||
48 | impl From<std::io::Error> for DirstateParseError { |
|
56 | impl From<std::io::Error> for DirstateParseError { | |
49 | fn from(e: std::io::Error) -> Self { |
|
57 | fn from(e: std::io::Error) -> Self { | |
50 | DirstateParseError::CorruptedEntry(e.to_string()) |
|
58 | DirstateParseError::CorruptedEntry(e.to_string()) | |
51 | } |
|
59 | } | |
52 | } |
|
60 | } | |
53 |
|
61 | |||
54 | impl ToString for DirstateParseError { |
|
62 | impl ToString for DirstateParseError { | |
55 | fn to_string(&self) -> String { |
|
63 | fn to_string(&self) -> String { | |
56 | use crate::DirstateParseError::*; |
|
64 | use crate::DirstateParseError::*; | |
57 | match self { |
|
65 | match self { | |
58 | TooLittleData => "Too little data for dirstate.".to_string(), |
|
66 | TooLittleData => "Too little data for dirstate.".to_string(), | |
59 | Overflow => "Overflow in dirstate.".to_string(), |
|
67 | Overflow => "Overflow in dirstate.".to_string(), | |
60 | CorruptedEntry(e) => format!("Corrupted entry: {:?}.", e), |
|
68 | CorruptedEntry(e) => format!("Corrupted entry: {:?}.", e), | |
61 | Damaged => "Dirstate appears to be damaged.".to_string(), |
|
69 | Damaged => "Dirstate appears to be damaged.".to_string(), | |
62 | } |
|
70 | } | |
63 | } |
|
71 | } | |
64 | } |
|
72 | } | |
65 |
|
73 | |||
66 | #[derive(Debug, PartialEq)] |
|
74 | #[derive(Debug, PartialEq)] | |
67 | pub enum DirstatePackError { |
|
75 | pub enum DirstatePackError { | |
68 | CorruptedEntry(String), |
|
76 | CorruptedEntry(String), | |
69 | CorruptedParent, |
|
77 | CorruptedParent, | |
70 | BadSize(usize, usize), |
|
78 | BadSize(usize, usize), | |
71 | } |
|
79 | } | |
72 |
|
80 | |||
73 | impl From<std::io::Error> for DirstatePackError { |
|
81 | impl From<std::io::Error> for DirstatePackError { | |
74 | fn from(e: std::io::Error) -> Self { |
|
82 | fn from(e: std::io::Error) -> Self { | |
75 | DirstatePackError::CorruptedEntry(e.to_string()) |
|
83 | DirstatePackError::CorruptedEntry(e.to_string()) | |
76 | } |
|
84 | } | |
77 | } |
|
85 | } | |
78 | #[derive(Debug, PartialEq)] |
|
86 | #[derive(Debug, PartialEq)] | |
79 | pub enum DirstateMapError { |
|
87 | pub enum DirstateMapError { | |
80 | PathNotFound(HgPathBuf), |
|
88 | PathNotFound(HgPathBuf), | |
81 | EmptyPath, |
|
89 | EmptyPath, | |
82 | ConsecutiveSlashes, |
|
90 | ConsecutiveSlashes, | |
83 | } |
|
91 | } | |
84 |
|
92 | |||
85 | impl ToString for DirstateMapError { |
|
93 | impl ToString for DirstateMapError { | |
86 | fn to_string(&self) -> String { |
|
94 | fn to_string(&self) -> String { | |
87 | use crate::DirstateMapError::*; |
|
95 | use crate::DirstateMapError::*; | |
88 | match self { |
|
96 | match self { | |
89 | PathNotFound(_) => "expected a value, found none".to_string(), |
|
97 | PathNotFound(_) => "expected a value, found none".to_string(), | |
90 | EmptyPath => "Overflow in dirstate.".to_string(), |
|
98 | EmptyPath => "Overflow in dirstate.".to_string(), | |
91 | ConsecutiveSlashes => { |
|
99 | ConsecutiveSlashes => { | |
92 | "found invalid consecutive slashes in path".to_string() |
|
100 | "found invalid consecutive slashes in path".to_string() | |
93 | } |
|
101 | } | |
94 | } |
|
102 | } | |
95 | } |
|
103 | } | |
96 | } |
|
104 | } | |
97 |
|
105 | |||
98 | pub enum DirstateError { |
|
106 | pub enum DirstateError { | |
99 | Parse(DirstateParseError), |
|
107 | Parse(DirstateParseError), | |
100 | Pack(DirstatePackError), |
|
108 | Pack(DirstatePackError), | |
101 | Map(DirstateMapError), |
|
109 | Map(DirstateMapError), | |
102 | IO(std::io::Error), |
|
110 | IO(std::io::Error), | |
103 | } |
|
111 | } | |
104 |
|
112 | |||
105 | impl From<DirstateParseError> for DirstateError { |
|
113 | impl From<DirstateParseError> for DirstateError { | |
106 | fn from(e: DirstateParseError) -> Self { |
|
114 | fn from(e: DirstateParseError) -> Self { | |
107 | DirstateError::Parse(e) |
|
115 | DirstateError::Parse(e) | |
108 | } |
|
116 | } | |
109 | } |
|
117 | } | |
110 |
|
118 | |||
111 | impl From<DirstatePackError> for DirstateError { |
|
119 | impl From<DirstatePackError> for DirstateError { | |
112 | fn from(e: DirstatePackError) -> Self { |
|
120 | fn from(e: DirstatePackError) -> Self { | |
113 | DirstateError::Pack(e) |
|
121 | DirstateError::Pack(e) | |
114 | } |
|
122 | } | |
115 | } |
|
123 | } | |
116 |
|
124 | |||
117 | #[derive(Debug)] |
|
125 | #[derive(Debug)] | |
118 | pub enum PatternError { |
|
126 | pub enum PatternError { | |
119 | UnsupportedSyntax(String), |
|
127 | UnsupportedSyntax(String), | |
120 | } |
|
128 | } | |
121 |
|
129 | |||
122 | #[derive(Debug)] |
|
130 | #[derive(Debug)] | |
123 | pub enum PatternFileError { |
|
131 | pub enum PatternFileError { | |
124 | IO(std::io::Error), |
|
132 | IO(std::io::Error), | |
125 | Pattern(PatternError, LineNumber), |
|
133 | Pattern(PatternError, LineNumber), | |
126 | } |
|
134 | } | |
127 |
|
135 | |||
128 | impl From<std::io::Error> for PatternFileError { |
|
136 | impl From<std::io::Error> for PatternFileError { | |
129 | fn from(e: std::io::Error) -> Self { |
|
137 | fn from(e: std::io::Error) -> Self { | |
130 | PatternFileError::IO(e) |
|
138 | PatternFileError::IO(e) | |
131 | } |
|
139 | } | |
132 | } |
|
140 | } | |
133 |
|
141 | |||
134 | impl From<DirstateMapError> for DirstateError { |
|
142 | impl From<DirstateMapError> for DirstateError { | |
135 | fn from(e: DirstateMapError) -> Self { |
|
143 | fn from(e: DirstateMapError) -> Self { | |
136 | DirstateError::Map(e) |
|
144 | DirstateError::Map(e) | |
137 | } |
|
145 | } | |
138 | } |
|
146 | } | |
139 |
|
147 | |||
140 | impl From<std::io::Error> for DirstateError { |
|
148 | impl From<std::io::Error> for DirstateError { | |
141 | fn from(e: std::io::Error) -> Self { |
|
149 | fn from(e: std::io::Error) -> Self { | |
142 | DirstateError::IO(e) |
|
150 | DirstateError::IO(e) | |
143 | } |
|
151 | } | |
144 | } |
|
152 | } |
General Comments 0
You need to be logged in to leave comments.
Login now