Show More
@@ -0,0 +1,9 b'' | |||||
|
1 | /// An interface for high-level hg operations. | |||
|
2 | /// | |||
|
3 | /// A distinction is made between operation and commands. | |||
|
4 | /// An operation is what can be done whereas a command is what is exposed by | |||
|
5 | /// the cli. A single command can use several operations to achieve its goal. | |||
|
6 | pub trait Operation<T> { | |||
|
7 | type Error; | |||
|
8 | fn run(&self) -> Result<T, Self::Error>; | |||
|
9 | } |
@@ -1,190 +1,191 b'' | |||||
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::{ |
|
16 | status::{ | |
17 | status, BadMatch, BadType, DirstateStatus, StatusError, StatusOptions, |
|
17 | status, BadMatch, BadType, DirstateStatus, StatusError, StatusOptions, | |
18 | }, |
|
18 | }, | |
19 | CopyMap, CopyMapIter, DirstateEntry, DirstateParents, EntryState, |
|
19 | CopyMap, CopyMapIter, DirstateEntry, DirstateParents, EntryState, | |
20 | StateMap, StateMapIter, |
|
20 | StateMap, StateMapIter, | |
21 | }; |
|
21 | }; | |
22 | mod filepatterns; |
|
22 | mod filepatterns; | |
23 | pub mod matchers; |
|
23 | pub mod matchers; | |
24 | pub mod revlog; |
|
24 | pub mod revlog; | |
25 | pub use revlog::*; |
|
25 | pub use revlog::*; | |
|
26 | pub mod operations; | |||
26 | pub mod utils; |
|
27 | pub mod utils; | |
27 |
|
28 | |||
28 | // Remove this to see (potential) non-artificial compile failures. MacOS |
|
29 | // Remove this to see (potential) non-artificial compile failures. MacOS | |
29 | // *should* compile, but fail to compile tests for example as of 2020-03-06 |
|
30 | // *should* compile, but fail to compile tests for example as of 2020-03-06 | |
30 | #[cfg(not(target_os = "linux"))] |
|
31 | #[cfg(not(target_os = "linux"))] | |
31 | compile_error!( |
|
32 | compile_error!( | |
32 | "`hg-core` has only been tested on Linux and will most \ |
|
33 | "`hg-core` has only been tested on Linux and will most \ | |
33 | likely not behave correctly on other platforms." |
|
34 | likely not behave correctly on other platforms." | |
34 | ); |
|
35 | ); | |
35 |
|
36 | |||
36 | use crate::utils::hg_path::{HgPathBuf, HgPathError}; |
|
37 | use crate::utils::hg_path::{HgPathBuf, HgPathError}; | |
37 | pub use filepatterns::{ |
|
38 | pub use filepatterns::{ | |
38 | parse_pattern_syntax, read_pattern_file, IgnorePattern, |
|
39 | parse_pattern_syntax, read_pattern_file, IgnorePattern, | |
39 | PatternFileWarning, PatternSyntax, |
|
40 | PatternFileWarning, PatternSyntax, | |
40 | }; |
|
41 | }; | |
41 | use std::collections::HashMap; |
|
42 | use std::collections::HashMap; | |
42 | use twox_hash::RandomXxHashBuilder64; |
|
43 | use twox_hash::RandomXxHashBuilder64; | |
43 |
|
44 | |||
44 | /// This is a contract between the `micro-timer` crate and us, to expose |
|
45 | /// This is a contract between the `micro-timer` crate and us, to expose | |
45 | /// the `log` crate as `crate::log`. |
|
46 | /// the `log` crate as `crate::log`. | |
46 | use log; |
|
47 | use log; | |
47 |
|
48 | |||
48 | pub type LineNumber = usize; |
|
49 | pub type LineNumber = usize; | |
49 |
|
50 | |||
50 | /// Rust's default hasher is too slow because it tries to prevent collision |
|
51 | /// Rust's default hasher is too slow because it tries to prevent collision | |
51 | /// attacks. We are not concerned about those: if an ill-minded person has |
|
52 | /// attacks. We are not concerned about those: if an ill-minded person has | |
52 | /// write access to your repository, you have other issues. |
|
53 | /// write access to your repository, you have other issues. | |
53 | pub type FastHashMap<K, V> = HashMap<K, V, RandomXxHashBuilder64>; |
|
54 | pub type FastHashMap<K, V> = HashMap<K, V, RandomXxHashBuilder64>; | |
54 |
|
55 | |||
55 | #[derive(Clone, Debug, PartialEq)] |
|
56 | #[derive(Clone, Debug, PartialEq)] | |
56 | pub enum DirstateParseError { |
|
57 | pub enum DirstateParseError { | |
57 | TooLittleData, |
|
58 | TooLittleData, | |
58 | Overflow, |
|
59 | Overflow, | |
59 | CorruptedEntry(String), |
|
60 | CorruptedEntry(String), | |
60 | Damaged, |
|
61 | Damaged, | |
61 | } |
|
62 | } | |
62 |
|
63 | |||
63 | impl From<std::io::Error> for DirstateParseError { |
|
64 | impl From<std::io::Error> for DirstateParseError { | |
64 | fn from(e: std::io::Error) -> Self { |
|
65 | fn from(e: std::io::Error) -> Self { | |
65 | DirstateParseError::CorruptedEntry(e.to_string()) |
|
66 | DirstateParseError::CorruptedEntry(e.to_string()) | |
66 | } |
|
67 | } | |
67 | } |
|
68 | } | |
68 |
|
69 | |||
69 | impl ToString for DirstateParseError { |
|
70 | impl ToString for DirstateParseError { | |
70 | fn to_string(&self) -> String { |
|
71 | fn to_string(&self) -> String { | |
71 | use crate::DirstateParseError::*; |
|
72 | use crate::DirstateParseError::*; | |
72 | match self { |
|
73 | match self { | |
73 | TooLittleData => "Too little data for dirstate.".to_string(), |
|
74 | TooLittleData => "Too little data for dirstate.".to_string(), | |
74 | Overflow => "Overflow in dirstate.".to_string(), |
|
75 | Overflow => "Overflow in dirstate.".to_string(), | |
75 | CorruptedEntry(e) => format!("Corrupted entry: {:?}.", e), |
|
76 | CorruptedEntry(e) => format!("Corrupted entry: {:?}.", e), | |
76 | Damaged => "Dirstate appears to be damaged.".to_string(), |
|
77 | Damaged => "Dirstate appears to be damaged.".to_string(), | |
77 | } |
|
78 | } | |
78 | } |
|
79 | } | |
79 | } |
|
80 | } | |
80 |
|
81 | |||
81 | #[derive(Debug, PartialEq)] |
|
82 | #[derive(Debug, PartialEq)] | |
82 | pub enum DirstatePackError { |
|
83 | pub enum DirstatePackError { | |
83 | CorruptedEntry(String), |
|
84 | CorruptedEntry(String), | |
84 | CorruptedParent, |
|
85 | CorruptedParent, | |
85 | BadSize(usize, usize), |
|
86 | BadSize(usize, usize), | |
86 | } |
|
87 | } | |
87 |
|
88 | |||
88 | impl From<std::io::Error> for DirstatePackError { |
|
89 | impl From<std::io::Error> for DirstatePackError { | |
89 | fn from(e: std::io::Error) -> Self { |
|
90 | fn from(e: std::io::Error) -> Self { | |
90 | DirstatePackError::CorruptedEntry(e.to_string()) |
|
91 | DirstatePackError::CorruptedEntry(e.to_string()) | |
91 | } |
|
92 | } | |
92 | } |
|
93 | } | |
93 | #[derive(Debug, PartialEq)] |
|
94 | #[derive(Debug, PartialEq)] | |
94 | pub enum DirstateMapError { |
|
95 | pub enum DirstateMapError { | |
95 | PathNotFound(HgPathBuf), |
|
96 | PathNotFound(HgPathBuf), | |
96 | EmptyPath, |
|
97 | EmptyPath, | |
97 | InvalidPath(HgPathError), |
|
98 | InvalidPath(HgPathError), | |
98 | } |
|
99 | } | |
99 |
|
100 | |||
100 | impl ToString for DirstateMapError { |
|
101 | impl ToString for DirstateMapError { | |
101 | fn to_string(&self) -> String { |
|
102 | fn to_string(&self) -> String { | |
102 | match self { |
|
103 | match self { | |
103 | DirstateMapError::PathNotFound(_) => { |
|
104 | DirstateMapError::PathNotFound(_) => { | |
104 | "expected a value, found none".to_string() |
|
105 | "expected a value, found none".to_string() | |
105 | } |
|
106 | } | |
106 | DirstateMapError::EmptyPath => "Overflow in dirstate.".to_string(), |
|
107 | DirstateMapError::EmptyPath => "Overflow in dirstate.".to_string(), | |
107 | DirstateMapError::InvalidPath(e) => e.to_string(), |
|
108 | DirstateMapError::InvalidPath(e) => e.to_string(), | |
108 | } |
|
109 | } | |
109 | } |
|
110 | } | |
110 | } |
|
111 | } | |
111 |
|
112 | |||
112 | #[derive(Debug)] |
|
113 | #[derive(Debug)] | |
113 | pub enum DirstateError { |
|
114 | pub enum DirstateError { | |
114 | Parse(DirstateParseError), |
|
115 | Parse(DirstateParseError), | |
115 | Pack(DirstatePackError), |
|
116 | Pack(DirstatePackError), | |
116 | Map(DirstateMapError), |
|
117 | Map(DirstateMapError), | |
117 | IO(std::io::Error), |
|
118 | IO(std::io::Error), | |
118 | } |
|
119 | } | |
119 |
|
120 | |||
120 | impl From<DirstateParseError> for DirstateError { |
|
121 | impl From<DirstateParseError> for DirstateError { | |
121 | fn from(e: DirstateParseError) -> Self { |
|
122 | fn from(e: DirstateParseError) -> Self { | |
122 | DirstateError::Parse(e) |
|
123 | DirstateError::Parse(e) | |
123 | } |
|
124 | } | |
124 | } |
|
125 | } | |
125 |
|
126 | |||
126 | impl From<DirstatePackError> for DirstateError { |
|
127 | impl From<DirstatePackError> for DirstateError { | |
127 | fn from(e: DirstatePackError) -> Self { |
|
128 | fn from(e: DirstatePackError) -> Self { | |
128 | DirstateError::Pack(e) |
|
129 | DirstateError::Pack(e) | |
129 | } |
|
130 | } | |
130 | } |
|
131 | } | |
131 |
|
132 | |||
132 | #[derive(Debug)] |
|
133 | #[derive(Debug)] | |
133 | pub enum PatternError { |
|
134 | pub enum PatternError { | |
134 | Path(HgPathError), |
|
135 | Path(HgPathError), | |
135 | UnsupportedSyntax(String), |
|
136 | UnsupportedSyntax(String), | |
136 | UnsupportedSyntaxInFile(String, String, usize), |
|
137 | UnsupportedSyntaxInFile(String, String, usize), | |
137 | TooLong(usize), |
|
138 | TooLong(usize), | |
138 | IO(std::io::Error), |
|
139 | IO(std::io::Error), | |
139 | /// Needed a pattern that can be turned into a regex but got one that |
|
140 | /// Needed a pattern that can be turned into a regex but got one that | |
140 | /// can't. This should only happen through programmer error. |
|
141 | /// can't. This should only happen through programmer error. | |
141 | NonRegexPattern(IgnorePattern), |
|
142 | NonRegexPattern(IgnorePattern), | |
142 | } |
|
143 | } | |
143 |
|
144 | |||
144 | impl ToString for PatternError { |
|
145 | impl ToString for PatternError { | |
145 | fn to_string(&self) -> String { |
|
146 | fn to_string(&self) -> String { | |
146 | match self { |
|
147 | match self { | |
147 | PatternError::UnsupportedSyntax(syntax) => { |
|
148 | PatternError::UnsupportedSyntax(syntax) => { | |
148 | format!("Unsupported syntax {}", syntax) |
|
149 | format!("Unsupported syntax {}", syntax) | |
149 | } |
|
150 | } | |
150 | PatternError::UnsupportedSyntaxInFile(syntax, file_path, line) => { |
|
151 | PatternError::UnsupportedSyntaxInFile(syntax, file_path, line) => { | |
151 | format!( |
|
152 | format!( | |
152 | "{}:{}: unsupported syntax {}", |
|
153 | "{}:{}: unsupported syntax {}", | |
153 | file_path, line, syntax |
|
154 | file_path, line, syntax | |
154 | ) |
|
155 | ) | |
155 | } |
|
156 | } | |
156 | PatternError::TooLong(size) => { |
|
157 | PatternError::TooLong(size) => { | |
157 | format!("matcher pattern is too long ({} bytes)", size) |
|
158 | format!("matcher pattern is too long ({} bytes)", size) | |
158 | } |
|
159 | } | |
159 | PatternError::IO(e) => e.to_string(), |
|
160 | PatternError::IO(e) => e.to_string(), | |
160 | PatternError::Path(e) => e.to_string(), |
|
161 | PatternError::Path(e) => e.to_string(), | |
161 | PatternError::NonRegexPattern(pattern) => { |
|
162 | PatternError::NonRegexPattern(pattern) => { | |
162 | format!("'{:?}' cannot be turned into a regex", pattern) |
|
163 | format!("'{:?}' cannot be turned into a regex", pattern) | |
163 | } |
|
164 | } | |
164 | } |
|
165 | } | |
165 | } |
|
166 | } | |
166 | } |
|
167 | } | |
167 |
|
168 | |||
168 | impl From<DirstateMapError> for DirstateError { |
|
169 | impl From<DirstateMapError> for DirstateError { | |
169 | fn from(e: DirstateMapError) -> Self { |
|
170 | fn from(e: DirstateMapError) -> Self { | |
170 | DirstateError::Map(e) |
|
171 | DirstateError::Map(e) | |
171 | } |
|
172 | } | |
172 | } |
|
173 | } | |
173 |
|
174 | |||
174 | impl From<std::io::Error> for DirstateError { |
|
175 | impl From<std::io::Error> for DirstateError { | |
175 | fn from(e: std::io::Error) -> Self { |
|
176 | fn from(e: std::io::Error) -> Self { | |
176 | DirstateError::IO(e) |
|
177 | DirstateError::IO(e) | |
177 | } |
|
178 | } | |
178 | } |
|
179 | } | |
179 |
|
180 | |||
180 | impl From<std::io::Error> for PatternError { |
|
181 | impl From<std::io::Error> for PatternError { | |
181 | fn from(e: std::io::Error) -> Self { |
|
182 | fn from(e: std::io::Error) -> Self { | |
182 | PatternError::IO(e) |
|
183 | PatternError::IO(e) | |
183 | } |
|
184 | } | |
184 | } |
|
185 | } | |
185 |
|
186 | |||
186 | impl From<HgPathError> for PatternError { |
|
187 | impl From<HgPathError> for PatternError { | |
187 | fn from(e: HgPathError) -> Self { |
|
188 | fn from(e: HgPathError) -> Self { | |
188 | PatternError::Path(e) |
|
189 | PatternError::Path(e) | |
189 | } |
|
190 | } | |
190 | } |
|
191 | } |
General Comments 0
You need to be logged in to leave comments.
Login now