Show More
@@ -0,0 +1,1 b'' | |||||
|
1 | pub mod dispatch; |
@@ -0,0 +1,310 b'' | |||||
|
1 | use std::collections::HashSet; | |||
|
2 | use std::path::PathBuf; | |||
|
3 | use std::time::Duration; | |||
|
4 | ||||
|
5 | use crate::matchers::Matcher; | |||
|
6 | use crate::utils::hg_path::{HgPath, HgPathBuf}; | |||
|
7 | use crate::CopyMapIter; | |||
|
8 | use crate::DirstateEntry; | |||
|
9 | use crate::DirstateError; | |||
|
10 | use crate::DirstateMap; | |||
|
11 | use crate::DirstateMapError; | |||
|
12 | use crate::DirstateParents; | |||
|
13 | use crate::DirstateStatus; | |||
|
14 | use crate::EntryState; | |||
|
15 | use crate::FastHashMap; | |||
|
16 | use crate::HgPathCow; | |||
|
17 | use crate::PatternFileWarning; | |||
|
18 | use crate::StateMapIter; | |||
|
19 | use crate::StatusError; | |||
|
20 | use crate::StatusOptions; | |||
|
21 | ||||
|
22 | pub trait DirstateMapMethods { | |||
|
23 | fn clear(&mut self); | |||
|
24 | ||||
|
25 | fn add_file( | |||
|
26 | &mut self, | |||
|
27 | filename: &HgPath, | |||
|
28 | old_state: EntryState, | |||
|
29 | entry: DirstateEntry, | |||
|
30 | ) -> Result<(), DirstateMapError>; | |||
|
31 | ||||
|
32 | fn remove_file( | |||
|
33 | &mut self, | |||
|
34 | filename: &HgPath, | |||
|
35 | old_state: EntryState, | |||
|
36 | size: i32, | |||
|
37 | ) -> Result<(), DirstateMapError>; | |||
|
38 | ||||
|
39 | fn drop_file( | |||
|
40 | &mut self, | |||
|
41 | filename: &HgPath, | |||
|
42 | old_state: EntryState, | |||
|
43 | ) -> Result<bool, DirstateMapError>; | |||
|
44 | ||||
|
45 | fn clear_ambiguous_times(&mut self, filenames: Vec<HgPathBuf>, now: i32); | |||
|
46 | ||||
|
47 | fn non_normal_entries_remove(&mut self, key: &HgPath) -> bool; | |||
|
48 | ||||
|
49 | fn non_normal_entries_union( | |||
|
50 | &mut self, | |||
|
51 | other: HashSet<HgPathBuf>, | |||
|
52 | ) -> Vec<HgPathBuf>; | |||
|
53 | ||||
|
54 | fn set_non_normal_other_parent_entries(&mut self, force: bool); | |||
|
55 | ||||
|
56 | fn get_non_normal_other_parent_entries_panic( | |||
|
57 | &self, | |||
|
58 | ) -> (&HashSet<HgPathBuf>, &HashSet<HgPathBuf>); | |||
|
59 | ||||
|
60 | fn get_non_normal_other_parent_entries( | |||
|
61 | &mut self, | |||
|
62 | ) -> (&mut HashSet<HgPathBuf>, &mut HashSet<HgPathBuf>); | |||
|
63 | ||||
|
64 | fn has_tracked_dir( | |||
|
65 | &mut self, | |||
|
66 | directory: &HgPath, | |||
|
67 | ) -> Result<bool, DirstateMapError>; | |||
|
68 | ||||
|
69 | fn has_dir( | |||
|
70 | &mut self, | |||
|
71 | directory: &HgPath, | |||
|
72 | ) -> Result<bool, DirstateMapError>; | |||
|
73 | ||||
|
74 | fn parents( | |||
|
75 | &mut self, | |||
|
76 | file_contents: &[u8], | |||
|
77 | ) -> Result<&DirstateParents, DirstateError>; | |||
|
78 | ||||
|
79 | fn set_parents(&mut self, parents: &DirstateParents); | |||
|
80 | ||||
|
81 | fn read<'a>( | |||
|
82 | &mut self, | |||
|
83 | file_contents: &'a [u8], | |||
|
84 | ) -> Result<Option<&'a DirstateParents>, DirstateError>; | |||
|
85 | ||||
|
86 | fn pack( | |||
|
87 | &mut self, | |||
|
88 | parents: DirstateParents, | |||
|
89 | now: Duration, | |||
|
90 | ) -> Result<Vec<u8>, DirstateError>; | |||
|
91 | ||||
|
92 | fn build_file_fold_map(&mut self) -> &FastHashMap<HgPathBuf, HgPathBuf>; | |||
|
93 | ||||
|
94 | fn set_all_dirs(&mut self) -> Result<(), DirstateMapError>; | |||
|
95 | ||||
|
96 | fn set_dirs(&mut self) -> Result<(), DirstateMapError>; | |||
|
97 | ||||
|
98 | fn status<'a>( | |||
|
99 | &'a self, | |||
|
100 | matcher: &'a (dyn Matcher + Sync), | |||
|
101 | root_dir: PathBuf, | |||
|
102 | ignore_files: Vec<PathBuf>, | |||
|
103 | options: StatusOptions, | |||
|
104 | ) -> Result< | |||
|
105 | ( | |||
|
106 | (Vec<HgPathCow<'a>>, DirstateStatus<'a>), | |||
|
107 | Vec<PatternFileWarning>, | |||
|
108 | ), | |||
|
109 | StatusError, | |||
|
110 | >; | |||
|
111 | ||||
|
112 | fn copy_map_len(&self) -> usize; | |||
|
113 | ||||
|
114 | fn copy_map_iter(&self) -> CopyMapIter<'_>; | |||
|
115 | ||||
|
116 | fn copy_map_contains_key(&self, key: &HgPath) -> bool; | |||
|
117 | ||||
|
118 | fn copy_map_get(&self, key: &HgPath) -> Option<&HgPathBuf>; | |||
|
119 | ||||
|
120 | fn copy_map_remove(&mut self, key: &HgPath) -> Option<HgPathBuf>; | |||
|
121 | ||||
|
122 | fn copy_map_insert( | |||
|
123 | &mut self, | |||
|
124 | key: HgPathBuf, | |||
|
125 | value: HgPathBuf, | |||
|
126 | ) -> Option<HgPathBuf>; | |||
|
127 | ||||
|
128 | fn len(&self) -> usize; | |||
|
129 | ||||
|
130 | fn contains_key(&self, key: &HgPath) -> bool; | |||
|
131 | ||||
|
132 | fn get(&self, key: &HgPath) -> Option<&DirstateEntry>; | |||
|
133 | ||||
|
134 | fn iter(&self) -> StateMapIter<'_>; | |||
|
135 | } | |||
|
136 | ||||
|
137 | impl DirstateMapMethods for DirstateMap { | |||
|
138 | fn clear(&mut self) { | |||
|
139 | self.clear() | |||
|
140 | } | |||
|
141 | ||||
|
142 | fn add_file( | |||
|
143 | &mut self, | |||
|
144 | filename: &HgPath, | |||
|
145 | old_state: EntryState, | |||
|
146 | entry: DirstateEntry, | |||
|
147 | ) -> Result<(), DirstateMapError> { | |||
|
148 | self.add_file(filename, old_state, entry) | |||
|
149 | } | |||
|
150 | ||||
|
151 | fn remove_file( | |||
|
152 | &mut self, | |||
|
153 | filename: &HgPath, | |||
|
154 | old_state: EntryState, | |||
|
155 | size: i32, | |||
|
156 | ) -> Result<(), DirstateMapError> { | |||
|
157 | self.remove_file(filename, old_state, size) | |||
|
158 | } | |||
|
159 | ||||
|
160 | fn drop_file( | |||
|
161 | &mut self, | |||
|
162 | filename: &HgPath, | |||
|
163 | old_state: EntryState, | |||
|
164 | ) -> Result<bool, DirstateMapError> { | |||
|
165 | self.drop_file(filename, old_state) | |||
|
166 | } | |||
|
167 | ||||
|
168 | fn clear_ambiguous_times(&mut self, filenames: Vec<HgPathBuf>, now: i32) { | |||
|
169 | self.clear_ambiguous_times(filenames, now) | |||
|
170 | } | |||
|
171 | ||||
|
172 | fn non_normal_entries_remove(&mut self, key: &HgPath) -> bool { | |||
|
173 | self.non_normal_entries_remove(key) | |||
|
174 | } | |||
|
175 | ||||
|
176 | fn non_normal_entries_union( | |||
|
177 | &mut self, | |||
|
178 | other: HashSet<HgPathBuf>, | |||
|
179 | ) -> Vec<HgPathBuf> { | |||
|
180 | self.non_normal_entries_union(other) | |||
|
181 | } | |||
|
182 | ||||
|
183 | fn set_non_normal_other_parent_entries(&mut self, force: bool) { | |||
|
184 | self.set_non_normal_other_parent_entries(force) | |||
|
185 | } | |||
|
186 | ||||
|
187 | fn get_non_normal_other_parent_entries_panic( | |||
|
188 | &self, | |||
|
189 | ) -> (&HashSet<HgPathBuf>, &HashSet<HgPathBuf>) { | |||
|
190 | self.get_non_normal_other_parent_entries_panic() | |||
|
191 | } | |||
|
192 | ||||
|
193 | fn get_non_normal_other_parent_entries( | |||
|
194 | &mut self, | |||
|
195 | ) -> (&mut HashSet<HgPathBuf>, &mut HashSet<HgPathBuf>) { | |||
|
196 | self.get_non_normal_other_parent_entries() | |||
|
197 | } | |||
|
198 | ||||
|
199 | fn has_tracked_dir( | |||
|
200 | &mut self, | |||
|
201 | directory: &HgPath, | |||
|
202 | ) -> Result<bool, DirstateMapError> { | |||
|
203 | self.has_tracked_dir(directory) | |||
|
204 | } | |||
|
205 | ||||
|
206 | fn has_dir( | |||
|
207 | &mut self, | |||
|
208 | directory: &HgPath, | |||
|
209 | ) -> Result<bool, DirstateMapError> { | |||
|
210 | self.has_dir(directory) | |||
|
211 | } | |||
|
212 | ||||
|
213 | fn parents( | |||
|
214 | &mut self, | |||
|
215 | file_contents: &[u8], | |||
|
216 | ) -> Result<&DirstateParents, DirstateError> { | |||
|
217 | self.parents(file_contents) | |||
|
218 | } | |||
|
219 | ||||
|
220 | fn set_parents(&mut self, parents: &DirstateParents) { | |||
|
221 | self.set_parents(parents) | |||
|
222 | } | |||
|
223 | ||||
|
224 | fn read<'a>( | |||
|
225 | &mut self, | |||
|
226 | file_contents: &'a [u8], | |||
|
227 | ) -> Result<Option<&'a DirstateParents>, DirstateError> { | |||
|
228 | self.read(file_contents) | |||
|
229 | } | |||
|
230 | ||||
|
231 | fn pack( | |||
|
232 | &mut self, | |||
|
233 | parents: DirstateParents, | |||
|
234 | now: Duration, | |||
|
235 | ) -> Result<Vec<u8>, DirstateError> { | |||
|
236 | self.pack(parents, now) | |||
|
237 | } | |||
|
238 | ||||
|
239 | fn build_file_fold_map(&mut self) -> &FastHashMap<HgPathBuf, HgPathBuf> { | |||
|
240 | self.build_file_fold_map() | |||
|
241 | } | |||
|
242 | ||||
|
243 | fn set_all_dirs(&mut self) -> Result<(), DirstateMapError> { | |||
|
244 | self.set_all_dirs() | |||
|
245 | } | |||
|
246 | ||||
|
247 | fn set_dirs(&mut self) -> Result<(), DirstateMapError> { | |||
|
248 | self.set_dirs() | |||
|
249 | } | |||
|
250 | ||||
|
251 | fn status<'a>( | |||
|
252 | &'a self, | |||
|
253 | matcher: &'a (dyn Matcher + Sync), | |||
|
254 | root_dir: PathBuf, | |||
|
255 | ignore_files: Vec<PathBuf>, | |||
|
256 | options: StatusOptions, | |||
|
257 | ) -> Result< | |||
|
258 | ( | |||
|
259 | (Vec<HgPathCow<'a>>, DirstateStatus<'a>), | |||
|
260 | Vec<PatternFileWarning>, | |||
|
261 | ), | |||
|
262 | StatusError, | |||
|
263 | > { | |||
|
264 | crate::status(self, matcher, root_dir, ignore_files, options) | |||
|
265 | } | |||
|
266 | ||||
|
267 | fn copy_map_len(&self) -> usize { | |||
|
268 | self.copy_map.len() | |||
|
269 | } | |||
|
270 | ||||
|
271 | fn copy_map_iter(&self) -> CopyMapIter<'_> { | |||
|
272 | Box::new(self.copy_map.iter()) | |||
|
273 | } | |||
|
274 | ||||
|
275 | fn copy_map_contains_key(&self, key: &HgPath) -> bool { | |||
|
276 | self.copy_map.contains_key(key) | |||
|
277 | } | |||
|
278 | ||||
|
279 | fn copy_map_get(&self, key: &HgPath) -> Option<&HgPathBuf> { | |||
|
280 | self.copy_map.get(key) | |||
|
281 | } | |||
|
282 | ||||
|
283 | fn copy_map_remove(&mut self, key: &HgPath) -> Option<HgPathBuf> { | |||
|
284 | self.copy_map.remove(key) | |||
|
285 | } | |||
|
286 | ||||
|
287 | fn copy_map_insert( | |||
|
288 | &mut self, | |||
|
289 | key: HgPathBuf, | |||
|
290 | value: HgPathBuf, | |||
|
291 | ) -> Option<HgPathBuf> { | |||
|
292 | self.copy_map.insert(key, value) | |||
|
293 | } | |||
|
294 | ||||
|
295 | fn len(&self) -> usize { | |||
|
296 | (&**self).len() | |||
|
297 | } | |||
|
298 | ||||
|
299 | fn contains_key(&self, key: &HgPath) -> bool { | |||
|
300 | (&**self).contains_key(key) | |||
|
301 | } | |||
|
302 | ||||
|
303 | fn get(&self, key: &HgPath) -> Option<&DirstateEntry> { | |||
|
304 | (&**self).get(key) | |||
|
305 | } | |||
|
306 | ||||
|
307 | fn iter(&self) -> StateMapIter<'_> { | |||
|
308 | Box::new((&**self).iter()) | |||
|
309 | } | |||
|
310 | } |
@@ -9,7 +9,6 b' use crate::errors::HgError;' | |||||
9 | use crate::revlog::Node; |
|
9 | use crate::revlog::Node; | |
10 | use crate::{utils::hg_path::HgPathBuf, FastHashMap}; |
|
10 | use crate::{utils::hg_path::HgPathBuf, FastHashMap}; | |
11 | use bytes_cast::{unaligned, BytesCast}; |
|
11 | use bytes_cast::{unaligned, BytesCast}; | |
12 | use std::collections::hash_map; |
|
|||
13 | use std::convert::TryFrom; |
|
12 | use std::convert::TryFrom; | |
14 |
|
13 | |||
15 | pub mod dirs_multiset; |
|
14 | pub mod dirs_multiset; | |
@@ -51,10 +50,12 b' struct RawEntry {' | |||||
51 | pub const SIZE_FROM_OTHER_PARENT: i32 = -2; |
|
50 | pub const SIZE_FROM_OTHER_PARENT: i32 = -2; | |
52 |
|
51 | |||
53 | pub type StateMap = FastHashMap<HgPathBuf, DirstateEntry>; |
|
52 | pub type StateMap = FastHashMap<HgPathBuf, DirstateEntry>; | |
54 | pub type StateMapIter<'a> = hash_map::Iter<'a, HgPathBuf, DirstateEntry>; |
|
53 | pub type StateMapIter<'a> = | |
|
54 | Box<dyn Iterator<Item = (&'a HgPathBuf, &'a DirstateEntry)> + Send + 'a>; | |||
55 |
|
55 | |||
56 | pub type CopyMap = FastHashMap<HgPathBuf, HgPathBuf>; |
|
56 | pub type CopyMap = FastHashMap<HgPathBuf, HgPathBuf>; | |
57 | pub type CopyMapIter<'a> = hash_map::Iter<'a, HgPathBuf, HgPathBuf>; |
|
57 | pub type CopyMapIter<'a> = | |
|
58 | Box<dyn Iterator<Item = (&'a HgPathBuf, &'a HgPathBuf)> + Send + 'a>; | |||
58 |
|
59 | |||
59 | #[derive(Copy, Clone, Debug, Eq, PartialEq)] |
|
60 | #[derive(Copy, Clone, Debug, Eq, PartialEq)] | |
60 | pub enum EntryState { |
|
61 | pub enum EntryState { |
@@ -14,7 +14,7 b' use crate::{' | |||||
14 | files, |
|
14 | files, | |
15 | hg_path::{HgPath, HgPathBuf, HgPathError}, |
|
15 | hg_path::{HgPath, HgPathBuf, HgPathError}, | |
16 | }, |
|
16 | }, | |
17 |
DirstateEntry, DirstateMapError, FastHashMap, |
|
17 | DirstateEntry, DirstateMapError, FastHashMap, | |
18 | }; |
|
18 | }; | |
19 | use std::collections::{hash_map, hash_map::Entry, HashMap, HashSet}; |
|
19 | use std::collections::{hash_map, hash_map::Entry, HashMap, HashSet}; | |
20 |
|
20 | |||
@@ -30,14 +30,14 b' impl DirsMultiset {' | |||||
30 | /// Initializes the multiset from a dirstate. |
|
30 | /// Initializes the multiset from a dirstate. | |
31 | /// |
|
31 | /// | |
32 | /// If `skip_state` is provided, skips dirstate entries with equal state. |
|
32 | /// If `skip_state` is provided, skips dirstate entries with equal state. | |
33 | pub fn from_dirstate( |
|
33 | pub fn from_dirstate<'a>( | |
34 | dirstate: &StateMap, |
|
34 | dirstate: impl IntoIterator<Item = (&'a HgPathBuf, &'a DirstateEntry)>, | |
35 | skip_state: Option<EntryState>, |
|
35 | skip_state: Option<EntryState>, | |
36 | ) -> Result<Self, DirstateMapError> { |
|
36 | ) -> Result<Self, DirstateMapError> { | |
37 | let mut multiset = DirsMultiset { |
|
37 | let mut multiset = DirsMultiset { | |
38 | inner: FastHashMap::default(), |
|
38 | inner: FastHashMap::default(), | |
39 | }; |
|
39 | }; | |
40 |
for (filename, DirstateEntry { state, .. }) in dirstate |
|
40 | for (filename, DirstateEntry { state, .. }) in dirstate { | |
41 | // This `if` is optimized out of the loop |
|
41 | // This `if` is optimized out of the loop | |
42 | if let Some(skip) = skip_state { |
|
42 | if let Some(skip) = skip_state { | |
43 | if skip != *state { |
|
43 | if skip != *state { | |
@@ -207,6 +207,7 b" impl<'a> DirsChildrenMultiset<'a> {" | |||||
207 | #[cfg(test)] |
|
207 | #[cfg(test)] | |
208 | mod tests { |
|
208 | mod tests { | |
209 | use super::*; |
|
209 | use super::*; | |
|
210 | use crate::StateMap; | |||
210 |
|
211 | |||
211 | #[test] |
|
212 | #[test] | |
212 | fn test_delete_path_path_not_found() { |
|
213 | fn test_delete_path_path_not_found() { | |
@@ -356,7 +357,7 b' mod tests {' | |||||
356 | }; |
|
357 | }; | |
357 | assert_eq!(expected, new); |
|
358 | assert_eq!(expected, new); | |
358 |
|
359 | |||
359 | let input_map = ["b/x", "a/c", "a/d/x"] |
|
360 | let input_map: HashMap<_, _> = ["b/x", "a/c", "a/d/x"] | |
360 | .iter() |
|
361 | .iter() | |
361 | .map(|f| { |
|
362 | .map(|f| { | |
362 | ( |
|
363 | ( | |
@@ -384,7 +385,7 b' mod tests {' | |||||
384 |
|
385 | |||
385 | #[test] |
|
386 | #[test] | |
386 | fn test_dirsmultiset_new_skip() { |
|
387 | fn test_dirsmultiset_new_skip() { | |
387 | let input_map = [ |
|
388 | let input_map: HashMap<_, _> = [ | |
388 | ("a/", EntryState::Normal), |
|
389 | ("a/", EntryState::Normal), | |
389 | ("a/b", EntryState::Normal), |
|
390 | ("a/b", EntryState::Normal), | |
390 | ("a/c", EntryState::Removed), |
|
391 | ("a/c", EntryState::Removed), |
@@ -289,8 +289,10 b' impl DirstateMap {' | |||||
289 | /// good idea. |
|
289 | /// good idea. | |
290 | pub fn set_all_dirs(&mut self) -> Result<(), DirstateMapError> { |
|
290 | pub fn set_all_dirs(&mut self) -> Result<(), DirstateMapError> { | |
291 | if self.all_dirs.is_none() { |
|
291 | if self.all_dirs.is_none() { | |
292 | self.all_dirs = |
|
292 | self.all_dirs = Some(DirsMultiset::from_dirstate( | |
293 | Some(DirsMultiset::from_dirstate(&self.state_map, None)?); |
|
293 | self.state_map.iter(), | |
|
294 | None, | |||
|
295 | )?); | |||
294 | } |
|
296 | } | |
295 | Ok(()) |
|
297 | Ok(()) | |
296 | } |
|
298 | } |
@@ -292,7 +292,7 b' impl fmt::Display for StatusError {' | |||||
292 |
|
292 | |||
293 | /// Gives information about which files are changed in the working directory |
|
293 | /// Gives information about which files are changed in the working directory | |
294 | /// and how, compared to the revision we're based on |
|
294 | /// and how, compared to the revision we're based on | |
295 | pub struct Status<'a, M: Matcher + Sync> { |
|
295 | pub struct Status<'a, M: ?Sized + Matcher + Sync> { | |
296 | dmap: &'a DirstateMap, |
|
296 | dmap: &'a DirstateMap, | |
297 | pub(crate) matcher: &'a M, |
|
297 | pub(crate) matcher: &'a M, | |
298 | root_dir: PathBuf, |
|
298 | root_dir: PathBuf, | |
@@ -302,7 +302,7 b" pub struct Status<'a, M: Matcher + Sync>" | |||||
302 |
|
302 | |||
303 | impl<'a, M> Status<'a, M> |
|
303 | impl<'a, M> Status<'a, M> | |
304 | where |
|
304 | where | |
305 | M: Matcher + Sync, |
|
305 | M: ?Sized + Matcher + Sync, | |
306 | { |
|
306 | { | |
307 | pub fn new( |
|
307 | pub fn new( | |
308 | dmap: &'a DirstateMap, |
|
308 | dmap: &'a DirstateMap, | |
@@ -898,7 +898,7 b" pub fn build_response<'a>(" | |||||
898 | #[timed] |
|
898 | #[timed] | |
899 | pub fn status<'a>( |
|
899 | pub fn status<'a>( | |
900 | dmap: &'a DirstateMap, |
|
900 | dmap: &'a DirstateMap, | |
901 |
matcher: &'a ( |
|
901 | matcher: &'a (dyn Matcher + Sync), | |
902 | root_dir: PathBuf, |
|
902 | root_dir: PathBuf, | |
903 | ignore_files: Vec<PathBuf>, |
|
903 | ignore_files: Vec<PathBuf>, | |
904 | options: StatusOptions, |
|
904 | options: StatusOptions, |
@@ -9,6 +9,7 b' pub mod dagops;' | |||||
9 | pub mod errors; |
|
9 | pub mod errors; | |
10 | pub use ancestors::{AncestorsIterator, LazyAncestors, MissingAncestors}; |
|
10 | pub use ancestors::{AncestorsIterator, LazyAncestors, MissingAncestors}; | |
11 | mod dirstate; |
|
11 | mod dirstate; | |
|
12 | pub mod dirstate_tree; | |||
12 | pub mod discovery; |
|
13 | pub mod discovery; | |
13 | pub mod requirements; |
|
14 | pub mod requirements; | |
14 | pub mod testing; // unconditionally built, for use from integration tests |
|
15 | pub mod testing; // unconditionally built, for use from integration tests |
@@ -14,7 +14,7 b' use crate::{DirstateStatus, StatusError}' | |||||
14 | /// files. |
|
14 | /// files. | |
15 | pub type LookupAndStatus<'a> = (Vec<HgPathCow<'a>>, DirstateStatus<'a>); |
|
15 | pub type LookupAndStatus<'a> = (Vec<HgPathCow<'a>>, DirstateStatus<'a>); | |
16 |
|
16 | |||
17 | impl<'a, M: Matcher + Sync> Status<'a, M> { |
|
17 | impl<'a, M: ?Sized + Matcher + Sync> Status<'a, M> { | |
18 | pub(crate) fn run(&self) -> Result<LookupAndStatus<'a>, StatusError> { |
|
18 | pub(crate) fn run(&self) -> Result<LookupAndStatus<'a>, StatusError> { | |
19 | let (traversed_sender, traversed_receiver) = |
|
19 | let (traversed_sender, traversed_receiver) = | |
20 | crossbeam_channel::unbounded(); |
|
20 | crossbeam_channel::unbounded(); |
@@ -27,6 +27,7 b' use crate::{' | |||||
27 | parsers::dirstate_parents_to_pytuple, |
|
27 | parsers::dirstate_parents_to_pytuple, | |
28 | }; |
|
28 | }; | |
29 | use hg::{ |
|
29 | use hg::{ | |
|
30 | dirstate_tree::dispatch::DirstateMapMethods, | |||
30 | errors::HgError, |
|
31 | errors::HgError, | |
31 | revlog::Node, |
|
32 | revlog::Node, | |
32 | utils::hg_path::{HgPath, HgPathBuf}, |
|
33 | utils::hg_path::{HgPath, HgPathBuf}, | |
@@ -47,10 +48,10 b' use hg::{' | |||||
47 | // All attributes also have to have a separate refcount data attribute for |
|
48 | // All attributes also have to have a separate refcount data attribute for | |
48 | // leaks, with all methods that go along for reference sharing. |
|
49 | // leaks, with all methods that go along for reference sharing. | |
49 | py_class!(pub class DirstateMap |py| { |
|
50 | py_class!(pub class DirstateMap |py| { | |
50 |
@shared data inner: |
|
51 | @shared data inner: Box<dyn DirstateMapMethods + Send>; | |
51 |
|
52 | |||
52 | def __new__(_cls, _root: PyObject) -> PyResult<Self> { |
|
53 | def __new__(_cls, _root: PyObject) -> PyResult<Self> { | |
53 | let inner = RustDirstateMap::default(); |
|
54 | let inner = Box::new(RustDirstateMap::default()); | |
54 | Self::create_instance(py, inner) |
|
55 | Self::create_instance(py, inner) | |
55 | } |
|
56 | } | |
56 |
|
57 | |||
@@ -404,7 +405,7 b' py_class!(pub class DirstateMap |py| {' | |||||
404 | Dirs::from_inner( |
|
405 | Dirs::from_inner( | |
405 | py, |
|
406 | py, | |
406 | DirsMultiset::from_dirstate( |
|
407 | DirsMultiset::from_dirstate( | |
407 |
|
|
408 | self.inner(py).borrow().iter(), | |
408 | Some(EntryState::Removed), |
|
409 | Some(EntryState::Removed), | |
409 | ) |
|
410 | ) | |
410 | .map_err(|e| { |
|
411 | .map_err(|e| { | |
@@ -421,7 +422,7 b' py_class!(pub class DirstateMap |py| {' | |||||
421 | Dirs::from_inner( |
|
422 | Dirs::from_inner( | |
422 | py, |
|
423 | py, | |
423 | DirsMultiset::from_dirstate( |
|
424 | DirsMultiset::from_dirstate( | |
424 |
|
|
425 | self.inner(py).borrow().iter(), | |
425 | None, |
|
426 | None, | |
426 | ).map_err(|e| { |
|
427 | ).map_err(|e| { | |
427 | PyErr::new::<exc::ValueError, _>(py, e.to_string()) |
|
428 | PyErr::new::<exc::ValueError, _>(py, e.to_string()) | |
@@ -432,7 +433,7 b' py_class!(pub class DirstateMap |py| {' | |||||
432 | // TODO all copymap* methods, see docstring above |
|
433 | // TODO all copymap* methods, see docstring above | |
433 | def copymapcopy(&self) -> PyResult<PyDict> { |
|
434 | def copymapcopy(&self) -> PyResult<PyDict> { | |
434 | let dict = PyDict::new(py); |
|
435 | let dict = PyDict::new(py); | |
435 |
for (key, value) in self.inner(py).borrow().copy_map |
|
436 | for (key, value) in self.inner(py).borrow().copy_map_iter() { | |
436 | dict.set_item( |
|
437 | dict.set_item( | |
437 | py, |
|
438 | py, | |
438 | PyBytes::new(py, key.as_bytes()), |
|
439 | PyBytes::new(py, key.as_bytes()), | |
@@ -444,7 +445,7 b' py_class!(pub class DirstateMap |py| {' | |||||
444 |
|
445 | |||
445 | def copymapgetitem(&self, key: PyObject) -> PyResult<PyBytes> { |
|
446 | def copymapgetitem(&self, key: PyObject) -> PyResult<PyBytes> { | |
446 | let key = key.extract::<PyBytes>(py)?; |
|
447 | let key = key.extract::<PyBytes>(py)?; | |
447 |
match self.inner(py).borrow().copy_map |
|
448 | match self.inner(py).borrow().copy_map_get(HgPath::new(key.data(py))) { | |
448 | Some(copy) => Ok(PyBytes::new(py, copy.as_bytes())), |
|
449 | Some(copy) => Ok(PyBytes::new(py, copy.as_bytes())), | |
449 | None => Err(PyErr::new::<exc::KeyError, _>( |
|
450 | None => Err(PyErr::new::<exc::KeyError, _>( | |
450 | py, |
|
451 | py, | |
@@ -457,15 +458,14 b' py_class!(pub class DirstateMap |py| {' | |||||
457 | } |
|
458 | } | |
458 |
|
459 | |||
459 | def copymaplen(&self) -> PyResult<usize> { |
|
460 | def copymaplen(&self) -> PyResult<usize> { | |
460 |
Ok(self.inner(py).borrow().copy_map |
|
461 | Ok(self.inner(py).borrow().copy_map_len()) | |
461 | } |
|
462 | } | |
462 | def copymapcontains(&self, key: PyObject) -> PyResult<bool> { |
|
463 | def copymapcontains(&self, key: PyObject) -> PyResult<bool> { | |
463 | let key = key.extract::<PyBytes>(py)?; |
|
464 | let key = key.extract::<PyBytes>(py)?; | |
464 | Ok(self |
|
465 | Ok(self | |
465 | .inner(py) |
|
466 | .inner(py) | |
466 | .borrow() |
|
467 | .borrow() | |
467 | .copy_map |
|
468 | .copy_map_contains_key(HgPath::new(key.data(py)))) | |
468 | .contains_key(HgPath::new(key.data(py)))) |
|
|||
469 | } |
|
469 | } | |
470 | def copymapget( |
|
470 | def copymapget( | |
471 | &self, |
|
471 | &self, | |
@@ -476,8 +476,7 b' py_class!(pub class DirstateMap |py| {' | |||||
476 | match self |
|
476 | match self | |
477 | .inner(py) |
|
477 | .inner(py) | |
478 | .borrow() |
|
478 | .borrow() | |
479 | .copy_map |
|
479 | .copy_map_get(HgPath::new(key.data(py))) | |
480 | .get(HgPath::new(key.data(py))) |
|
|||
481 | { |
|
480 | { | |
482 | Some(copy) => Ok(Some( |
|
481 | Some(copy) => Ok(Some( | |
483 | PyBytes::new(py, copy.as_bytes()).into_object(), |
|
482 | PyBytes::new(py, copy.as_bytes()).into_object(), | |
@@ -492,7 +491,7 b' py_class!(pub class DirstateMap |py| {' | |||||
492 | ) -> PyResult<PyObject> { |
|
491 | ) -> PyResult<PyObject> { | |
493 | let key = key.extract::<PyBytes>(py)?; |
|
492 | let key = key.extract::<PyBytes>(py)?; | |
494 | let value = value.extract::<PyBytes>(py)?; |
|
493 | let value = value.extract::<PyBytes>(py)?; | |
495 |
self.inner(py).borrow_mut().copy_map |
|
494 | self.inner(py).borrow_mut().copy_map_insert( | |
496 | HgPathBuf::from_bytes(key.data(py)), |
|
495 | HgPathBuf::from_bytes(key.data(py)), | |
497 | HgPathBuf::from_bytes(value.data(py)), |
|
496 | HgPathBuf::from_bytes(value.data(py)), | |
498 | ); |
|
497 | ); | |
@@ -507,8 +506,7 b' py_class!(pub class DirstateMap |py| {' | |||||
507 | match self |
|
506 | match self | |
508 | .inner(py) |
|
507 | .inner(py) | |
509 | .borrow_mut() |
|
508 | .borrow_mut() | |
510 | .copy_map |
|
509 | .copy_map_remove(HgPath::new(key.data(py))) | |
511 | .remove(HgPath::new(key.data(py))) |
|
|||
512 | { |
|
510 | { | |
513 | Some(_) => Ok(None), |
|
511 | Some(_) => Ok(None), | |
514 | None => Ok(default), |
|
512 | None => Ok(default), | |
@@ -519,7 +517,7 b' py_class!(pub class DirstateMap |py| {' | |||||
519 | let leaked_ref = self.inner(py).leak_immutable(); |
|
517 | let leaked_ref = self.inner(py).leak_immutable(); | |
520 | CopyMapKeysIterator::from_inner( |
|
518 | CopyMapKeysIterator::from_inner( | |
521 | py, |
|
519 | py, | |
522 |
unsafe { leaked_ref.map(py, |o| o.copy_map |
|
520 | unsafe { leaked_ref.map(py, |o| o.copy_map_iter()) }, | |
523 | ) |
|
521 | ) | |
524 | } |
|
522 | } | |
525 |
|
523 | |||
@@ -527,7 +525,7 b' py_class!(pub class DirstateMap |py| {' | |||||
527 | let leaked_ref = self.inner(py).leak_immutable(); |
|
525 | let leaked_ref = self.inner(py).leak_immutable(); | |
528 | CopyMapItemsIterator::from_inner( |
|
526 | CopyMapItemsIterator::from_inner( | |
529 | py, |
|
527 | py, | |
530 |
unsafe { leaked_ref.map(py, |o| o.copy_map |
|
528 | unsafe { leaked_ref.map(py, |o| o.copy_map_iter()) }, | |
531 | ) |
|
529 | ) | |
532 | } |
|
530 | } | |
533 |
|
531 | |||
@@ -537,7 +535,7 b' impl DirstateMap {' | |||||
537 | pub fn get_inner<'a>( |
|
535 | pub fn get_inner<'a>( | |
538 | &'a self, |
|
536 | &'a self, | |
539 | py: Python<'a>, |
|
537 | py: Python<'a>, | |
540 |
) -> Ref<'a, |
|
538 | ) -> Ref<'a, Box<dyn DirstateMapMethods + Send>> { | |
541 | self.inner(py).borrow() |
|
539 | self.inner(py).borrow() | |
542 | } |
|
540 | } | |
543 | fn translate_key( |
|
541 | fn translate_key( |
@@ -17,7 +17,7 b' use cpython::{' | |||||
17 | }; |
|
17 | }; | |
18 | use hg::{ |
|
18 | use hg::{ | |
19 | matchers::{AlwaysMatcher, FileMatcher, IncludeMatcher}, |
|
19 | matchers::{AlwaysMatcher, FileMatcher, IncludeMatcher}, | |
20 |
parse_pattern_syntax, |
|
20 | parse_pattern_syntax, | |
21 | utils::{ |
|
21 | utils::{ | |
22 | files::{get_bytes_from_path, get_path_from_bytes}, |
|
22 | files::{get_bytes_from_path, get_path_from_bytes}, | |
23 | hg_path::{HgPath, HgPathBuf}, |
|
23 | hg_path::{HgPath, HgPathBuf}, | |
@@ -126,21 +126,21 b' pub fn status_wrapper(' | |||||
126 | match matcher.get_type(py).name(py).borrow() { |
|
126 | match matcher.get_type(py).name(py).borrow() { | |
127 | "alwaysmatcher" => { |
|
127 | "alwaysmatcher" => { | |
128 | let matcher = AlwaysMatcher; |
|
128 | let matcher = AlwaysMatcher; | |
129 |
let ((lookup, status_res), warnings) = |
|
129 | let ((lookup, status_res), warnings) = dmap | |
130 |
|
|
130 | .status( | |
131 | &matcher, |
|
131 | &matcher, | |
132 | root_dir.to_path_buf(), |
|
132 | root_dir.to_path_buf(), | |
133 | ignore_files, |
|
133 | ignore_files, | |
134 | StatusOptions { |
|
134 | StatusOptions { | |
135 | check_exec, |
|
135 | check_exec, | |
136 | last_normal_time, |
|
136 | last_normal_time, | |
137 | list_clean, |
|
137 | list_clean, | |
138 | list_ignored, |
|
138 | list_ignored, | |
139 | list_unknown, |
|
139 | list_unknown, | |
140 | collect_traversed_dirs, |
|
140 | collect_traversed_dirs, | |
141 | }, |
|
141 | }, | |
142 | ) |
|
142 | ) | |
143 | .map_err(|e| handle_fallback(py, e))?; |
|
143 | .map_err(|e| handle_fallback(py, e))?; | |
144 | build_response(py, lookup, status_res, warnings) |
|
144 | build_response(py, lookup, status_res, warnings) | |
145 | } |
|
145 | } | |
146 | "exactmatcher" => { |
|
146 | "exactmatcher" => { | |
@@ -163,21 +163,21 b' pub fn status_wrapper(' | |||||
163 | let files = files?; |
|
163 | let files = files?; | |
164 | let matcher = FileMatcher::new(files.as_ref()) |
|
164 | let matcher = FileMatcher::new(files.as_ref()) | |
165 | .map_err(|e| PyErr::new::<ValueError, _>(py, e.to_string()))?; |
|
165 | .map_err(|e| PyErr::new::<ValueError, _>(py, e.to_string()))?; | |
166 |
let ((lookup, status_res), warnings) = |
|
166 | let ((lookup, status_res), warnings) = dmap | |
167 |
|
|
167 | .status( | |
168 | &matcher, |
|
168 | &matcher, | |
169 | root_dir.to_path_buf(), |
|
169 | root_dir.to_path_buf(), | |
170 | ignore_files, |
|
170 | ignore_files, | |
171 | StatusOptions { |
|
171 | StatusOptions { | |
172 | check_exec, |
|
172 | check_exec, | |
173 | last_normal_time, |
|
173 | last_normal_time, | |
174 | list_clean, |
|
174 | list_clean, | |
175 | list_ignored, |
|
175 | list_ignored, | |
176 | list_unknown, |
|
176 | list_unknown, | |
177 | collect_traversed_dirs, |
|
177 | collect_traversed_dirs, | |
178 | }, |
|
178 | }, | |
179 | ) |
|
179 | ) | |
180 | .map_err(|e| handle_fallback(py, e))?; |
|
180 | .map_err(|e| handle_fallback(py, e))?; | |
181 | build_response(py, lookup, status_res, warnings) |
|
181 | build_response(py, lookup, status_res, warnings) | |
182 | } |
|
182 | } | |
183 | "includematcher" => { |
|
183 | "includematcher" => { | |
@@ -218,21 +218,21 b' pub fn status_wrapper(' | |||||
218 | .map_err(|e| handle_fallback(py, e.into()))?; |
|
218 | .map_err(|e| handle_fallback(py, e.into()))?; | |
219 | all_warnings.extend(warnings); |
|
219 | all_warnings.extend(warnings); | |
220 |
|
220 | |||
221 |
let ((lookup, status_res), warnings) = |
|
221 | let ((lookup, status_res), warnings) = dmap | |
222 |
|
|
222 | .status( | |
223 | &matcher, |
|
223 | &matcher, | |
224 | root_dir.to_path_buf(), |
|
224 | root_dir.to_path_buf(), | |
225 | ignore_files, |
|
225 | ignore_files, | |
226 | StatusOptions { |
|
226 | StatusOptions { | |
227 | check_exec, |
|
227 | check_exec, | |
228 | last_normal_time, |
|
228 | last_normal_time, | |
229 | list_clean, |
|
229 | list_clean, | |
230 | list_ignored, |
|
230 | list_ignored, | |
231 | list_unknown, |
|
231 | list_unknown, | |
232 | collect_traversed_dirs, |
|
232 | collect_traversed_dirs, | |
233 | }, |
|
233 | }, | |
234 | ) |
|
234 | ) | |
235 | .map_err(|e| handle_fallback(py, e))?; |
|
235 | .map_err(|e| handle_fallback(py, e))?; | |
236 |
|
236 | |||
237 | all_warnings.extend(warnings); |
|
237 | all_warnings.extend(warnings); | |
238 |
|
238 |
General Comments 0
You need to be logged in to leave comments.
Login now