Show More
@@ -13,10 +13,11 b' use crate::{' | |||||
13 | files::normalize_case, |
|
13 | files::normalize_case, | |
14 | hg_path::{HgPath, HgPathBuf}, |
|
14 | hg_path::{HgPath, HgPathBuf}, | |
15 | }, |
|
15 | }, | |
16 | CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateMapError, |
|
16 | CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateMapError, DirstateParents, | |
17 |
|
|
17 | DirstateParseError, FastHashMap, StateMap, | |
18 | }; |
|
18 | }; | |
19 | use core::borrow::Borrow; |
|
19 | use core::borrow::Borrow; | |
|
20 | use micro_timer::timed; | |||
20 | use std::collections::HashSet; |
|
21 | use std::collections::HashSet; | |
21 | use std::convert::TryInto; |
|
22 | use std::convert::TryInto; | |
22 | use std::iter::FromIterator; |
|
23 | use std::iter::FromIterator; | |
@@ -50,9 +51,7 b' impl Deref for DirstateMap {' | |||||
50 | } |
|
51 | } | |
51 |
|
52 | |||
52 | impl FromIterator<(HgPathBuf, DirstateEntry)> for DirstateMap { |
|
53 | impl FromIterator<(HgPathBuf, DirstateEntry)> for DirstateMap { | |
53 | fn from_iter<I: IntoIterator<Item = (HgPathBuf, DirstateEntry)>>( |
|
54 | fn from_iter<I: IntoIterator<Item = (HgPathBuf, DirstateEntry)>>(iter: I) -> Self { | |
54 | iter: I, |
|
|||
55 | ) -> Self { |
|
|||
56 | Self { |
|
55 | Self { | |
57 | state_map: iter.into_iter().collect(), |
|
56 | state_map: iter.into_iter().collect(), | |
58 | ..Self::default() |
|
57 | ..Self::default() | |
@@ -84,8 +83,7 b' impl DirstateMap {' | |||||
84 | old_state: EntryState, |
|
83 | old_state: EntryState, | |
85 | entry: DirstateEntry, |
|
84 | entry: DirstateEntry, | |
86 | ) -> Result<(), DirstateMapError> { |
|
85 | ) -> Result<(), DirstateMapError> { | |
87 | if old_state == EntryState::Unknown || old_state == EntryState::Removed |
|
86 | if old_state == EntryState::Unknown || old_state == EntryState::Removed { | |
88 | { |
|
|||
89 | if let Some(ref mut dirs) = self.dirs { |
|
87 | if let Some(ref mut dirs) = self.dirs { | |
90 | dirs.add_path(filename)?; |
|
88 | dirs.add_path(filename)?; | |
91 | } |
|
89 | } | |
@@ -122,8 +120,7 b' impl DirstateMap {' | |||||
122 | old_state: EntryState, |
|
120 | old_state: EntryState, | |
123 | size: i32, |
|
121 | size: i32, | |
124 | ) -> Result<(), DirstateMapError> { |
|
122 | ) -> Result<(), DirstateMapError> { | |
125 | if old_state != EntryState::Unknown && old_state != EntryState::Removed |
|
123 | if old_state != EntryState::Unknown && old_state != EntryState::Removed { | |
126 | { |
|
|||
127 | if let Some(ref mut dirs) = self.dirs { |
|
124 | if let Some(ref mut dirs) = self.dirs { | |
128 | dirs.delete_path(filename)?; |
|
125 | dirs.delete_path(filename)?; | |
129 | } |
|
126 | } | |
@@ -181,18 +178,13 b' impl DirstateMap {' | |||||
181 | Ok(exists) |
|
178 | Ok(exists) | |
182 | } |
|
179 | } | |
183 |
|
180 | |||
184 | pub fn clear_ambiguous_times( |
|
181 | pub fn clear_ambiguous_times(&mut self, filenames: Vec<HgPathBuf>, now: i32) { | |
185 | &mut self, |
|
|||
186 | filenames: Vec<HgPathBuf>, |
|
|||
187 | now: i32, |
|
|||
188 | ) { |
|
|||
189 | for filename in filenames { |
|
182 | for filename in filenames { | |
190 | let mut changed = false; |
|
183 | let mut changed = false; | |
191 | self.state_map |
|
184 | self.state_map | |
192 | .entry(filename.to_owned()) |
|
185 | .entry(filename.to_owned()) | |
193 | .and_modify(|entry| { |
|
186 | .and_modify(|entry| { | |
194 | if entry.state == EntryState::Normal && entry.mtime == now |
|
187 | if entry.state == EntryState::Normal && entry.mtime == now { | |
195 | { |
|
|||
196 | changed = true; |
|
188 | changed = true; | |
197 | *entry = DirstateEntry { |
|
189 | *entry = DirstateEntry { | |
198 | mtime: MTIME_UNSET, |
|
190 | mtime: MTIME_UNSET, | |
@@ -208,18 +200,12 b' impl DirstateMap {' | |||||
208 | } |
|
200 | } | |
209 | } |
|
201 | } | |
210 |
|
202 | |||
211 | pub fn non_normal_entries_remove( |
|
203 | pub fn non_normal_entries_remove(&mut self, key: impl AsRef<HgPath>) -> bool { | |
212 | &mut self, |
|
|||
213 | key: impl AsRef<HgPath>, |
|
|||
214 | ) -> bool { |
|
|||
215 | self.get_non_normal_other_parent_entries() |
|
204 | self.get_non_normal_other_parent_entries() | |
216 | .0 |
|
205 | .0 | |
217 | .remove(key.as_ref()) |
|
206 | .remove(key.as_ref()) | |
218 | } |
|
207 | } | |
219 | pub fn non_normal_entries_union( |
|
208 | pub fn non_normal_entries_union(&mut self, other: HashSet<HgPathBuf>) -> Vec<HgPathBuf> { | |
220 | &mut self, |
|
|||
221 | other: HashSet<HgPathBuf>, |
|
|||
222 | ) -> Vec<HgPathBuf> { |
|
|||
223 | self.get_non_normal_other_parent_entries() |
|
209 | self.get_non_normal_other_parent_entries() | |
224 | .0 |
|
210 | .0 | |
225 | .union(&other) |
|
211 | .union(&other) | |
@@ -257,10 +243,7 b' impl DirstateMap {' | |||||
257 | } |
|
243 | } | |
258 |
|
244 | |||
259 | pub fn set_non_normal_other_parent_entries(&mut self, force: bool) { |
|
245 | pub fn set_non_normal_other_parent_entries(&mut self, force: bool) { | |
260 | if !force |
|
246 | if !force && self.non_normal_set.is_some() && self.other_parent_set.is_some() { | |
261 | && self.non_normal_set.is_some() |
|
|||
262 | && self.other_parent_set.is_some() |
|
|||
263 | { |
|
|||
264 | return; |
|
247 | return; | |
265 | } |
|
248 | } | |
266 | let mut non_normal = HashSet::new(); |
|
249 | let mut non_normal = HashSet::new(); | |
@@ -276,8 +259,7 b' impl DirstateMap {' | |||||
276 | if *state != EntryState::Normal || *mtime == MTIME_UNSET { |
|
259 | if *state != EntryState::Normal || *mtime == MTIME_UNSET { | |
277 | non_normal.insert(filename.to_owned()); |
|
260 | non_normal.insert(filename.to_owned()); | |
278 | } |
|
261 | } | |
279 | if *state == EntryState::Normal && *size == SIZE_FROM_OTHER_PARENT |
|
262 | if *state == EntryState::Normal && *size == SIZE_FROM_OTHER_PARENT { | |
280 | { |
|
|||
281 | other_parent.insert(filename.to_owned()); |
|
263 | other_parent.insert(filename.to_owned()); | |
282 | } |
|
264 | } | |
283 | } |
|
265 | } | |
@@ -291,8 +273,7 b' impl DirstateMap {' | |||||
291 | /// good idea. |
|
273 | /// good idea. | |
292 | pub fn set_all_dirs(&mut self) -> Result<(), DirstateMapError> { |
|
274 | pub fn set_all_dirs(&mut self) -> Result<(), DirstateMapError> { | |
293 | if self.all_dirs.is_none() { |
|
275 | if self.all_dirs.is_none() { | |
294 | self.all_dirs = |
|
276 | self.all_dirs = Some(DirsMultiset::from_dirstate(&self.state_map, None)?); | |
295 | Some(DirsMultiset::from_dirstate(&self.state_map, None)?); |
|
|||
296 | } |
|
277 | } | |
297 | Ok(()) |
|
278 | Ok(()) | |
298 | } |
|
279 | } | |
@@ -307,26 +288,17 b' impl DirstateMap {' | |||||
307 | Ok(()) |
|
288 | Ok(()) | |
308 | } |
|
289 | } | |
309 |
|
290 | |||
310 | pub fn has_tracked_dir( |
|
291 | pub fn has_tracked_dir(&mut self, directory: &HgPath) -> Result<bool, DirstateMapError> { | |
311 | &mut self, |
|
|||
312 | directory: &HgPath, |
|
|||
313 | ) -> Result<bool, DirstateMapError> { |
|
|||
314 | self.set_dirs()?; |
|
292 | self.set_dirs()?; | |
315 | Ok(self.dirs.as_ref().unwrap().contains(directory)) |
|
293 | Ok(self.dirs.as_ref().unwrap().contains(directory)) | |
316 | } |
|
294 | } | |
317 |
|
295 | |||
318 | pub fn has_dir( |
|
296 | pub fn has_dir(&mut self, directory: &HgPath) -> Result<bool, DirstateMapError> { | |
319 | &mut self, |
|
|||
320 | directory: &HgPath, |
|
|||
321 | ) -> Result<bool, DirstateMapError> { |
|
|||
322 | self.set_all_dirs()?; |
|
297 | self.set_all_dirs()?; | |
323 | Ok(self.all_dirs.as_ref().unwrap().contains(directory)) |
|
298 | Ok(self.all_dirs.as_ref().unwrap().contains(directory)) | |
324 | } |
|
299 | } | |
325 |
|
300 | |||
326 | pub fn parents( |
|
301 | pub fn parents(&mut self, file_contents: &[u8]) -> Result<&DirstateParents, DirstateError> { | |
327 | &mut self, |
|
|||
328 | file_contents: &[u8], |
|
|||
329 | ) -> Result<&DirstateParents, DirstateError> { |
|
|||
330 | if let Some(ref parents) = self.parents { |
|
302 | if let Some(ref parents) = self.parents { | |
331 | return Ok(parents); |
|
303 | return Ok(parents); | |
332 | } |
|
304 | } | |
@@ -356,10 +328,8 b' impl DirstateMap {' | |||||
356 | self.dirty_parents = true; |
|
328 | self.dirty_parents = true; | |
357 | } |
|
329 | } | |
358 |
|
330 | |||
359 | pub fn read( |
|
331 | #[timed] | |
360 | &mut self, |
|
332 | pub fn read(&mut self, file_contents: &[u8]) -> Result<Option<DirstateParents>, DirstateError> { | |
361 | file_contents: &[u8], |
|
|||
362 | ) -> Result<Option<DirstateParents>, DirstateError> { |
|
|||
363 | if file_contents.is_empty() { |
|
333 | if file_contents.is_empty() { | |
364 | return Ok(None); |
|
334 | return Ok(None); | |
365 | } |
|
335 | } | |
@@ -388,8 +358,7 b' impl DirstateMap {' | |||||
388 | parents: DirstateParents, |
|
358 | parents: DirstateParents, | |
389 | now: Duration, |
|
359 | now: Duration, | |
390 | ) -> Result<Vec<u8>, DirstateError> { |
|
360 | ) -> Result<Vec<u8>, DirstateError> { | |
391 | let packed = |
|
361 | let packed = pack_dirstate(&mut self.state_map, &self.copy_map, parents, now)?; | |
392 | pack_dirstate(&mut self.state_map, &self.copy_map, parents, now)?; |
|
|||
393 |
|
362 | |||
394 | self.dirty_parents = false; |
|
363 | self.dirty_parents = false; | |
395 |
|
364 | |||
@@ -402,11 +371,9 b' impl DirstateMap {' | |||||
402 | return file_fold_map; |
|
371 | return file_fold_map; | |
403 | } |
|
372 | } | |
404 | let mut new_file_fold_map = FileFoldMap::default(); |
|
373 | let mut new_file_fold_map = FileFoldMap::default(); | |
405 | for (filename, DirstateEntry { state, .. }) in self.state_map.borrow() |
|
374 | for (filename, DirstateEntry { state, .. }) in self.state_map.borrow() { | |
406 | { |
|
|||
407 | if *state == EntryState::Removed { |
|
375 | if *state == EntryState::Removed { | |
408 | new_file_fold_map |
|
376 | new_file_fold_map.insert(normalize_case(filename), filename.to_owned()); | |
409 | .insert(normalize_case(filename), filename.to_owned()); |
|
|||
410 | } |
|
377 | } | |
411 | } |
|
378 | } | |
412 | self.file_fold_map = Some(new_file_fold_map); |
|
379 | self.file_fold_map = Some(new_file_fold_map); | |
@@ -495,9 +462,6 b' mod tests {' | |||||
495 | other_parent.insert(HgPathBuf::from_bytes(b"f4")); |
|
462 | other_parent.insert(HgPathBuf::from_bytes(b"f4")); | |
496 | let entries = map.get_non_normal_other_parent_entries(); |
|
463 | let entries = map.get_non_normal_other_parent_entries(); | |
497 |
|
464 | |||
498 | assert_eq!( |
|
465 | assert_eq!((&mut non_normal, &mut other_parent), (entries.0, entries.1)); | |
499 | (&mut non_normal, &mut other_parent), |
|
|||
500 | (entries.0, entries.1) |
|
|||
501 | ); |
|
|||
502 | } |
|
466 | } | |
503 | } |
|
467 | } |
General Comments 0
You need to be logged in to leave comments.
Login now