Show More
@@ -1,173 +1,174 b'' | |||||
1 |
// Copyright 2018 Georges Racinet <gracinet@ |
|
1 | // Copyright 2018-2020 Georges Racinet <georges.racinet@octobus.net> | |
|
2 | // and Mercurial contributors | |||
2 | // |
|
3 | // | |
3 | // 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 | |
4 | // GNU General Public License version 2 or any later version. |
|
5 | // GNU General Public License version 2 or any later version. | |
5 | mod ancestors; |
|
6 | mod ancestors; | |
6 | pub mod dagops; |
|
7 | pub mod dagops; | |
7 | pub use ancestors::{AncestorsIterator, LazyAncestors, MissingAncestors}; |
|
8 | pub use ancestors::{AncestorsIterator, LazyAncestors, MissingAncestors}; | |
8 | mod dirstate; |
|
9 | mod dirstate; | |
9 | pub mod discovery; |
|
10 | pub mod discovery; | |
10 | pub mod testing; // unconditionally built, for use from integration tests |
|
11 | pub mod testing; // unconditionally built, for use from integration tests | |
11 | pub use dirstate::{ |
|
12 | pub use dirstate::{ | |
12 | dirs_multiset::{DirsMultiset, DirsMultisetIter}, |
|
13 | dirs_multiset::{DirsMultiset, DirsMultisetIter}, | |
13 | dirstate_map::DirstateMap, |
|
14 | dirstate_map::DirstateMap, | |
14 | parsers::{pack_dirstate, parse_dirstate, PARENT_SIZE}, |
|
15 | parsers::{pack_dirstate, parse_dirstate, PARENT_SIZE}, | |
15 | status::{status, StatusResult}, |
|
16 | status::{status, StatusResult}, | |
16 | CopyMap, CopyMapIter, DirstateEntry, DirstateParents, EntryState, |
|
17 | CopyMap, CopyMapIter, DirstateEntry, DirstateParents, EntryState, | |
17 | StateMap, StateMapIter, |
|
18 | StateMap, StateMapIter, | |
18 | }; |
|
19 | }; | |
19 | mod filepatterns; |
|
20 | mod filepatterns; | |
20 | pub mod matchers; |
|
21 | pub mod matchers; | |
21 | pub mod utils; |
|
22 | pub mod utils; | |
22 |
|
23 | |||
23 | use crate::utils::hg_path::HgPathBuf; |
|
24 | use crate::utils::hg_path::HgPathBuf; | |
24 | pub use filepatterns::{ |
|
25 | pub use filepatterns::{ | |
25 | build_single_regex, read_pattern_file, PatternSyntax, PatternTuple, |
|
26 | build_single_regex, read_pattern_file, PatternSyntax, PatternTuple, | |
26 | }; |
|
27 | }; | |
27 | use std::collections::HashMap; |
|
28 | use std::collections::HashMap; | |
28 | use twox_hash::RandomXxHashBuilder64; |
|
29 | use twox_hash::RandomXxHashBuilder64; | |
29 |
|
30 | |||
30 | /// Mercurial revision numbers |
|
31 | /// Mercurial revision numbers | |
31 | /// |
|
32 | /// | |
32 | /// As noted in revlog.c, revision numbers are actually encoded in |
|
33 | /// As noted in revlog.c, revision numbers are actually encoded in | |
33 | /// 4 bytes, and are liberally converted to ints, whence the i32 |
|
34 | /// 4 bytes, and are liberally converted to ints, whence the i32 | |
34 | pub type Revision = i32; |
|
35 | pub type Revision = i32; | |
35 |
|
36 | |||
36 | /// Marker expressing the absence of a parent |
|
37 | /// Marker expressing the absence of a parent | |
37 | /// |
|
38 | /// | |
38 | /// Independently of the actual representation, `NULL_REVISION` is guaranteed |
|
39 | /// Independently of the actual representation, `NULL_REVISION` is guaranteed | |
39 | /// to be smaller that all existing revisions. |
|
40 | /// to be smaller that all existing revisions. | |
40 | pub const NULL_REVISION: Revision = -1; |
|
41 | pub const NULL_REVISION: Revision = -1; | |
41 |
|
42 | |||
42 | /// Same as `mercurial.node.wdirrev` |
|
43 | /// Same as `mercurial.node.wdirrev` | |
43 | /// |
|
44 | /// | |
44 | /// This is also equal to `i32::max_value()`, but it's better to spell |
|
45 | /// This is also equal to `i32::max_value()`, but it's better to spell | |
45 | /// it out explicitely, same as in `mercurial.node` |
|
46 | /// it out explicitely, same as in `mercurial.node` | |
46 | pub const WORKING_DIRECTORY_REVISION: Revision = 0x7fffffff; |
|
47 | pub const WORKING_DIRECTORY_REVISION: Revision = 0x7fffffff; | |
47 |
|
48 | |||
48 | /// The simplest expression of what we need of Mercurial DAGs. |
|
49 | /// The simplest expression of what we need of Mercurial DAGs. | |
49 | pub trait Graph { |
|
50 | pub trait Graph { | |
50 | /// Return the two parents of the given `Revision`. |
|
51 | /// Return the two parents of the given `Revision`. | |
51 | /// |
|
52 | /// | |
52 | /// Each of the parents can be independently `NULL_REVISION` |
|
53 | /// Each of the parents can be independently `NULL_REVISION` | |
53 | fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError>; |
|
54 | fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError>; | |
54 | } |
|
55 | } | |
55 |
|
56 | |||
56 | pub type LineNumber = usize; |
|
57 | pub type LineNumber = usize; | |
57 |
|
58 | |||
58 | /// Rust's default hasher is too slow because it tries to prevent collision |
|
59 | /// Rust's default hasher is too slow because it tries to prevent collision | |
59 | /// attacks. We are not concerned about those: if an ill-minded person has |
|
60 | /// attacks. We are not concerned about those: if an ill-minded person has | |
60 | /// write access to your repository, you have other issues. |
|
61 | /// write access to your repository, you have other issues. | |
61 | pub type FastHashMap<K, V> = HashMap<K, V, RandomXxHashBuilder64>; |
|
62 | pub type FastHashMap<K, V> = HashMap<K, V, RandomXxHashBuilder64>; | |
62 |
|
63 | |||
63 | #[derive(Clone, Debug, PartialEq)] |
|
64 | #[derive(Clone, Debug, PartialEq)] | |
64 | pub enum GraphError { |
|
65 | pub enum GraphError { | |
65 | ParentOutOfRange(Revision), |
|
66 | ParentOutOfRange(Revision), | |
66 | WorkingDirectoryUnsupported, |
|
67 | WorkingDirectoryUnsupported, | |
67 | } |
|
68 | } | |
68 |
|
69 | |||
69 | #[derive(Clone, Debug, PartialEq)] |
|
70 | #[derive(Clone, Debug, PartialEq)] | |
70 | pub enum DirstateParseError { |
|
71 | pub enum DirstateParseError { | |
71 | TooLittleData, |
|
72 | TooLittleData, | |
72 | Overflow, |
|
73 | Overflow, | |
73 | CorruptedEntry(String), |
|
74 | CorruptedEntry(String), | |
74 | Damaged, |
|
75 | Damaged, | |
75 | } |
|
76 | } | |
76 |
|
77 | |||
77 | impl From<std::io::Error> for DirstateParseError { |
|
78 | impl From<std::io::Error> for DirstateParseError { | |
78 | fn from(e: std::io::Error) -> Self { |
|
79 | fn from(e: std::io::Error) -> Self { | |
79 | DirstateParseError::CorruptedEntry(e.to_string()) |
|
80 | DirstateParseError::CorruptedEntry(e.to_string()) | |
80 | } |
|
81 | } | |
81 | } |
|
82 | } | |
82 |
|
83 | |||
83 | impl ToString for DirstateParseError { |
|
84 | impl ToString for DirstateParseError { | |
84 | fn to_string(&self) -> String { |
|
85 | fn to_string(&self) -> String { | |
85 | use crate::DirstateParseError::*; |
|
86 | use crate::DirstateParseError::*; | |
86 | match self { |
|
87 | match self { | |
87 | TooLittleData => "Too little data for dirstate.".to_string(), |
|
88 | TooLittleData => "Too little data for dirstate.".to_string(), | |
88 | Overflow => "Overflow in dirstate.".to_string(), |
|
89 | Overflow => "Overflow in dirstate.".to_string(), | |
89 | CorruptedEntry(e) => format!("Corrupted entry: {:?}.", e), |
|
90 | CorruptedEntry(e) => format!("Corrupted entry: {:?}.", e), | |
90 | Damaged => "Dirstate appears to be damaged.".to_string(), |
|
91 | Damaged => "Dirstate appears to be damaged.".to_string(), | |
91 | } |
|
92 | } | |
92 | } |
|
93 | } | |
93 | } |
|
94 | } | |
94 |
|
95 | |||
95 | #[derive(Debug, PartialEq)] |
|
96 | #[derive(Debug, PartialEq)] | |
96 | pub enum DirstatePackError { |
|
97 | pub enum DirstatePackError { | |
97 | CorruptedEntry(String), |
|
98 | CorruptedEntry(String), | |
98 | CorruptedParent, |
|
99 | CorruptedParent, | |
99 | BadSize(usize, usize), |
|
100 | BadSize(usize, usize), | |
100 | } |
|
101 | } | |
101 |
|
102 | |||
102 | impl From<std::io::Error> for DirstatePackError { |
|
103 | impl From<std::io::Error> for DirstatePackError { | |
103 | fn from(e: std::io::Error) -> Self { |
|
104 | fn from(e: std::io::Error) -> Self { | |
104 | DirstatePackError::CorruptedEntry(e.to_string()) |
|
105 | DirstatePackError::CorruptedEntry(e.to_string()) | |
105 | } |
|
106 | } | |
106 | } |
|
107 | } | |
107 | #[derive(Debug, PartialEq)] |
|
108 | #[derive(Debug, PartialEq)] | |
108 | pub enum DirstateMapError { |
|
109 | pub enum DirstateMapError { | |
109 | PathNotFound(HgPathBuf), |
|
110 | PathNotFound(HgPathBuf), | |
110 | EmptyPath, |
|
111 | EmptyPath, | |
111 | ConsecutiveSlashes, |
|
112 | ConsecutiveSlashes, | |
112 | } |
|
113 | } | |
113 |
|
114 | |||
114 | impl ToString for DirstateMapError { |
|
115 | impl ToString for DirstateMapError { | |
115 | fn to_string(&self) -> String { |
|
116 | fn to_string(&self) -> String { | |
116 | use crate::DirstateMapError::*; |
|
117 | use crate::DirstateMapError::*; | |
117 | match self { |
|
118 | match self { | |
118 | PathNotFound(_) => "expected a value, found none".to_string(), |
|
119 | PathNotFound(_) => "expected a value, found none".to_string(), | |
119 | EmptyPath => "Overflow in dirstate.".to_string(), |
|
120 | EmptyPath => "Overflow in dirstate.".to_string(), | |
120 | ConsecutiveSlashes => { |
|
121 | ConsecutiveSlashes => { | |
121 | "found invalid consecutive slashes in path".to_string() |
|
122 | "found invalid consecutive slashes in path".to_string() | |
122 | } |
|
123 | } | |
123 | } |
|
124 | } | |
124 | } |
|
125 | } | |
125 | } |
|
126 | } | |
126 |
|
127 | |||
127 | pub enum DirstateError { |
|
128 | pub enum DirstateError { | |
128 | Parse(DirstateParseError), |
|
129 | Parse(DirstateParseError), | |
129 | Pack(DirstatePackError), |
|
130 | Pack(DirstatePackError), | |
130 | Map(DirstateMapError), |
|
131 | Map(DirstateMapError), | |
131 | IO(std::io::Error), |
|
132 | IO(std::io::Error), | |
132 | } |
|
133 | } | |
133 |
|
134 | |||
134 | impl From<DirstateParseError> for DirstateError { |
|
135 | impl From<DirstateParseError> for DirstateError { | |
135 | fn from(e: DirstateParseError) -> Self { |
|
136 | fn from(e: DirstateParseError) -> Self { | |
136 | DirstateError::Parse(e) |
|
137 | DirstateError::Parse(e) | |
137 | } |
|
138 | } | |
138 | } |
|
139 | } | |
139 |
|
140 | |||
140 | impl From<DirstatePackError> for DirstateError { |
|
141 | impl From<DirstatePackError> for DirstateError { | |
141 | fn from(e: DirstatePackError) -> Self { |
|
142 | fn from(e: DirstatePackError) -> Self { | |
142 | DirstateError::Pack(e) |
|
143 | DirstateError::Pack(e) | |
143 | } |
|
144 | } | |
144 | } |
|
145 | } | |
145 |
|
146 | |||
146 | #[derive(Debug)] |
|
147 | #[derive(Debug)] | |
147 | pub enum PatternError { |
|
148 | pub enum PatternError { | |
148 | UnsupportedSyntax(String), |
|
149 | UnsupportedSyntax(String), | |
149 | } |
|
150 | } | |
150 |
|
151 | |||
151 | #[derive(Debug)] |
|
152 | #[derive(Debug)] | |
152 | pub enum PatternFileError { |
|
153 | pub enum PatternFileError { | |
153 | IO(std::io::Error), |
|
154 | IO(std::io::Error), | |
154 | Pattern(PatternError, LineNumber), |
|
155 | Pattern(PatternError, LineNumber), | |
155 | } |
|
156 | } | |
156 |
|
157 | |||
157 | impl From<std::io::Error> for PatternFileError { |
|
158 | impl From<std::io::Error> for PatternFileError { | |
158 | fn from(e: std::io::Error) -> Self { |
|
159 | fn from(e: std::io::Error) -> Self { | |
159 | PatternFileError::IO(e) |
|
160 | PatternFileError::IO(e) | |
160 | } |
|
161 | } | |
161 | } |
|
162 | } | |
162 |
|
163 | |||
163 | impl From<DirstateMapError> for DirstateError { |
|
164 | impl From<DirstateMapError> for DirstateError { | |
164 | fn from(e: DirstateMapError) -> Self { |
|
165 | fn from(e: DirstateMapError) -> Self { | |
165 | DirstateError::Map(e) |
|
166 | DirstateError::Map(e) | |
166 | } |
|
167 | } | |
167 | } |
|
168 | } | |
168 |
|
169 | |||
169 | impl From<std::io::Error> for DirstateError { |
|
170 | impl From<std::io::Error> for DirstateError { | |
170 | fn from(e: std::io::Error) -> Self { |
|
171 | fn from(e: std::io::Error) -> Self { | |
171 | DirstateError::IO(e) |
|
172 | DirstateError::IO(e) | |
172 | } |
|
173 | } | |
173 | } |
|
174 | } |
General Comments 0
You need to be logged in to leave comments.
Login now