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