Mercurial > hg
changeset 45588:c35db907363d
rust: format with rustfmt
I suppose I ran the formatter on the tip but not on every patch.
Differential Revision: https://phab.mercurial-scm.org/D9093
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 28 Sep 2020 11:16:12 +0200 |
parents | 768412472663 |
children | 3d5b2b8e93fd |
files | rust/hg-core/src/dirstate/dirstate_map.rs rust/hg-core/src/dirstate/dirstate_tree/iter.rs rust/hg-core/src/dirstate/dirstate_tree/node.rs rust/hg-core/src/dirstate/dirstate_tree/tree.rs |
diffstat | 4 files changed, 160 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate/dirstate_map.rs Mon Aug 24 15:35:34 2020 +0530 +++ b/rust/hg-core/src/dirstate/dirstate_map.rs Mon Sep 28 11:16:12 2020 +0200 @@ -13,8 +13,8 @@ files::normalize_case, hg_path::{HgPath, HgPathBuf}, }, - CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateMapError, DirstateParents, - DirstateParseError, FastHashMap, StateMap, + CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateMapError, + DirstateParents, DirstateParseError, FastHashMap, StateMap, }; use core::borrow::Borrow; use micro_timer::timed; @@ -51,7 +51,9 @@ } impl FromIterator<(HgPathBuf, DirstateEntry)> for DirstateMap { - fn from_iter<I: IntoIterator<Item = (HgPathBuf, DirstateEntry)>>(iter: I) -> Self { + fn from_iter<I: IntoIterator<Item = (HgPathBuf, DirstateEntry)>>( + iter: I, + ) -> Self { Self { state_map: iter.into_iter().collect(), ..Self::default() @@ -83,7 +85,8 @@ old_state: EntryState, entry: DirstateEntry, ) -> Result<(), DirstateMapError> { - if old_state == EntryState::Unknown || old_state == EntryState::Removed { + if old_state == EntryState::Unknown || old_state == EntryState::Removed + { if let Some(ref mut dirs) = self.dirs { dirs.add_path(filename)?; } @@ -120,7 +123,8 @@ old_state: EntryState, size: i32, ) -> Result<(), DirstateMapError> { - if old_state != EntryState::Unknown && old_state != EntryState::Removed { + if old_state != EntryState::Unknown && old_state != EntryState::Removed + { if let Some(ref mut dirs) = self.dirs { dirs.delete_path(filename)?; } @@ -178,13 +182,18 @@ Ok(exists) } - pub fn clear_ambiguous_times(&mut self, filenames: Vec<HgPathBuf>, now: i32) { + pub fn clear_ambiguous_times( + &mut self, + filenames: Vec<HgPathBuf>, + now: i32, + ) { for filename in filenames { let mut changed = false; self.state_map .entry(filename.to_owned()) .and_modify(|entry| { - if entry.state == EntryState::Normal && entry.mtime == now { + if entry.state == EntryState::Normal && entry.mtime == now + { changed = true; *entry = DirstateEntry { mtime: MTIME_UNSET, @@ -200,12 +209,18 @@ } } - pub fn non_normal_entries_remove(&mut self, key: impl AsRef<HgPath>) -> bool { + pub fn non_normal_entries_remove( + &mut self, + key: impl AsRef<HgPath>, + ) -> bool { self.get_non_normal_other_parent_entries() .0 .remove(key.as_ref()) } - pub fn non_normal_entries_union(&mut self, other: HashSet<HgPathBuf>) -> Vec<HgPathBuf> { + pub fn non_normal_entries_union( + &mut self, + other: HashSet<HgPathBuf>, + ) -> Vec<HgPathBuf> { self.get_non_normal_other_parent_entries() .0 .union(&other) @@ -243,7 +258,10 @@ } pub fn set_non_normal_other_parent_entries(&mut self, force: bool) { - if !force && self.non_normal_set.is_some() && self.other_parent_set.is_some() { + if !force + && self.non_normal_set.is_some() + && self.other_parent_set.is_some() + { return; } let mut non_normal = HashSet::new(); @@ -259,7 +277,8 @@ if *state != EntryState::Normal || *mtime == MTIME_UNSET { non_normal.insert(filename.to_owned()); } - if *state == EntryState::Normal && *size == SIZE_FROM_OTHER_PARENT { + if *state == EntryState::Normal && *size == SIZE_FROM_OTHER_PARENT + { other_parent.insert(filename.to_owned()); } } @@ -273,7 +292,8 @@ /// good idea. pub fn set_all_dirs(&mut self) -> Result<(), DirstateMapError> { if self.all_dirs.is_none() { - self.all_dirs = Some(DirsMultiset::from_dirstate(&self.state_map, None)?); + self.all_dirs = + Some(DirsMultiset::from_dirstate(&self.state_map, None)?); } Ok(()) } @@ -288,17 +308,26 @@ Ok(()) } - pub fn has_tracked_dir(&mut self, directory: &HgPath) -> Result<bool, DirstateMapError> { + pub fn has_tracked_dir( + &mut self, + directory: &HgPath, + ) -> Result<bool, DirstateMapError> { self.set_dirs()?; Ok(self.dirs.as_ref().unwrap().contains(directory)) } - pub fn has_dir(&mut self, directory: &HgPath) -> Result<bool, DirstateMapError> { + pub fn has_dir( + &mut self, + directory: &HgPath, + ) -> Result<bool, DirstateMapError> { self.set_all_dirs()?; Ok(self.all_dirs.as_ref().unwrap().contains(directory)) } - pub fn parents(&mut self, file_contents: &[u8]) -> Result<&DirstateParents, DirstateError> { + pub fn parents( + &mut self, + file_contents: &[u8], + ) -> Result<&DirstateParents, DirstateError> { if let Some(ref parents) = self.parents { return Ok(parents); } @@ -329,7 +358,10 @@ } #[timed] - pub fn read(&mut self, file_contents: &[u8]) -> Result<Option<DirstateParents>, DirstateError> { + pub fn read( + &mut self, + file_contents: &[u8], + ) -> Result<Option<DirstateParents>, DirstateError> { if file_contents.is_empty() { return Ok(None); } @@ -358,7 +390,8 @@ parents: DirstateParents, now: Duration, ) -> Result<Vec<u8>, DirstateError> { - let packed = pack_dirstate(&mut self.state_map, &self.copy_map, parents, now)?; + let packed = + pack_dirstate(&mut self.state_map, &self.copy_map, parents, now)?; self.dirty_parents = false; @@ -371,9 +404,11 @@ return file_fold_map; } let mut new_file_fold_map = FileFoldMap::default(); - for (filename, DirstateEntry { state, .. }) in self.state_map.borrow() { + for (filename, DirstateEntry { state, .. }) in self.state_map.borrow() + { if *state == EntryState::Removed { - new_file_fold_map.insert(normalize_case(filename), filename.to_owned()); + new_file_fold_map + .insert(normalize_case(filename), filename.to_owned()); } } self.file_fold_map = Some(new_file_fold_map); @@ -462,6 +497,9 @@ other_parent.insert(HgPathBuf::from_bytes(b"f4")); let entries = map.get_non_normal_other_parent_entries(); - assert_eq!((&mut non_normal, &mut other_parent), (entries.0, entries.1)); + assert_eq!( + (&mut non_normal, &mut other_parent), + (entries.0, entries.1) + ); } }
--- a/rust/hg-core/src/dirstate/dirstate_tree/iter.rs Mon Aug 24 15:35:34 2020 +0530 +++ b/rust/hg-core/src/dirstate/dirstate_tree/iter.rs Mon Sep 28 11:16:12 2020 +0200 @@ -17,7 +17,9 @@ use std::path::PathBuf; impl FromIterator<(HgPathBuf, DirstateEntry)> for Tree { - fn from_iter<T: IntoIterator<Item = (HgPathBuf, DirstateEntry)>>(iter: T) -> Self { + fn from_iter<T: IntoIterator<Item = (HgPathBuf, DirstateEntry)>>( + iter: T, + ) -> Self { let mut tree = Self::new(); for (path, entry) in iter { tree.insert(path, entry); @@ -48,16 +50,30 @@ while let Some((base_path, node)) = self.to_visit.pop_front() { match &node.kind { NodeKind::Directory(dir) => { - add_children_to_visit(&mut self.to_visit, &base_path, &dir); + add_children_to_visit( + &mut self.to_visit, + &base_path, + &dir, + ); if let Some(file) = &dir.was_file { - return Some((HgPathBuf::from_bytes(&base_path), file.entry)); + return Some(( + HgPathBuf::from_bytes(&base_path), + file.entry, + )); } } NodeKind::File(file) => { if let Some(dir) = &file.was_directory { - add_children_to_visit(&mut self.to_visit, &base_path, &dir); + add_children_to_visit( + &mut self.to_visit, + &base_path, + &dir, + ); } - return Some((HgPathBuf::from_bytes(&base_path), file.entry)); + return Some(( + HgPathBuf::from_bytes(&base_path), + file.entry, + )); } } } @@ -107,10 +123,16 @@ /// ``` /// We need to dispatch the new symlink as `Unknown` and all the /// descendents of the directory it replace as `Deleted`. - fn dispatch_symlinked_directory(&mut self, path: impl AsRef<HgPath>, node: &Node) { + fn dispatch_symlinked_directory( + &mut self, + path: impl AsRef<HgPath>, + node: &Node, + ) { let path = path.as_ref(); - self.shortcuts - .push_back((path.to_owned(), StatusShortcut::Dispatch(Dispatch::Unknown))); + self.shortcuts.push_back(( + path.to_owned(), + StatusShortcut::Dispatch(Dispatch::Unknown), + )); for (file, _) in node.iter() { self.shortcuts.push_back(( path.join(&file), @@ -171,10 +193,17 @@ if self.directory_became_symlink(canonical_path) { // Potential security issue, don't do a normal // traversal, force the results. - self.dispatch_symlinked_directory(canonical_path, &node); + self.dispatch_symlinked_directory( + canonical_path, + &node, + ); continue; } - add_children_to_visit(&mut self.to_visit, &base_path, &dir); + add_children_to_visit( + &mut self.to_visit, + &base_path, + &dir, + ); if let Some(file) = &dir.was_file { return Some(( HgPathBuf::from_bytes(&base_path), @@ -184,7 +213,11 @@ } NodeKind::File(file) => { if let Some(dir) = &file.was_directory { - add_children_to_visit(&mut self.to_visit, &base_path, &dir); + add_children_to_visit( + &mut self.to_visit, + &base_path, + &dir, + ); } return Some(( HgPathBuf::from_bytes(&base_path), @@ -286,7 +319,8 @@ assert_eq!(tree.len(), 4); - let results: HashSet<_> = tree.iter().map(|(c, _)| c.to_owned()).collect(); + let results: HashSet<_> = + tree.iter().map(|(c, _)| c.to_owned()).collect(); dbg!(&results); assert!(results.contains(HgPath::new(b"foo2"))); assert!(results.contains(HgPath::new(b"foo/bar")));
--- a/rust/hg-core/src/dirstate/dirstate_tree/node.rs Mon Aug 24 15:35:34 2020 +0530 +++ b/rust/hg-core/src/dirstate/dirstate_tree/node.rs Mon Sep 28 11:16:12 2020 +0200 @@ -48,7 +48,11 @@ } impl Node { - pub fn insert(&mut self, path: &[u8], new_entry: DirstateEntry) -> InsertResult { + pub fn insert( + &mut self, + path: &[u8], + new_entry: DirstateEntry, + ) -> InsertResult { let mut split = path.splitn(2, |&c| c == b'/'); let head = split.next().unwrap_or(b""); let tail = split.next().unwrap_or(b""); @@ -76,16 +80,24 @@ children: Default::default(), }) } - _ => return Node::insert_in_file(file, new_entry, head, tail), + _ => { + return Node::insert_in_file( + file, new_entry, head, tail, + ) + } } } } match &mut self.kind { NodeKind::Directory(directory) => { - return Node::insert_in_directory(directory, new_entry, head, tail); + return Node::insert_in_directory( + directory, new_entry, head, tail, + ); } - NodeKind::File(_) => unreachable!("The file case has already been handled"), + NodeKind::File(_) => { + unreachable!("The file case has already been handled") + } } } @@ -104,7 +116,8 @@ was_file: None, children: FastHashMap::default(), }; - let res = Node::insert_in_directory(&mut dir, new_entry, head, tail); + let res = + Node::insert_in_directory(&mut dir, new_entry, head, tail); file.was_directory = Some(Box::new(dir)); res } @@ -130,7 +143,9 @@ entry: new_entry, }), }; - let old_entry = directory.children.insert(head.to_owned(), becomes_file); + let old_entry = directory + .children + .insert(head.to_owned(), becomes_file); return InsertResult { did_insert: true, old_entry, @@ -192,7 +207,8 @@ } NodeKind::File(f) => { if let Some(d) = &mut f.was_directory { - let RemoveResult { old_entry, .. } = Node::remove_from_directory(head, d); + let RemoveResult { old_entry, .. } = + Node::remove_from_directory(head, d); return RemoveResult { cleanup: false, old_entry, @@ -210,7 +226,8 @@ if res.cleanup { d.children.remove(head); } - res.cleanup = d.children.len() == 0 && d.was_file.is_none(); + res.cleanup = + d.children.len() == 0 && d.was_file.is_none(); res } else { empty_result @@ -219,7 +236,8 @@ NodeKind::File(f) => { if let Some(d) = &mut f.was_directory { if let Some(child) = d.children.get_mut(head) { - let RemoveResult { cleanup, old_entry } = child.remove(tail); + let RemoveResult { cleanup, old_entry } = + child.remove(tail); if cleanup { d.children.remove(head); }
--- a/rust/hg-core/src/dirstate/dirstate_tree/tree.rs Mon Aug 24 15:35:34 2020 +0530 +++ b/rust/hg-core/src/dirstate/dirstate_tree/tree.rs Mon Sep 28 11:16:12 2020 +0200 @@ -136,7 +136,11 @@ /// Low-level insertion method that returns the previous node (directories /// included). - fn insert_node(&mut self, path: impl AsRef<HgPath>, kind: DirstateEntry) -> Option<Node> { + fn insert_node( + &mut self, + path: impl AsRef<HgPath>, + kind: DirstateEntry, + ) -> Option<Node> { let InsertResult { did_insert, old_entry, @@ -154,7 +158,9 @@ pub fn get(&self, path: impl AsRef<HgPath>) -> Option<&DirstateEntry> { if let Some(node) = self.get_node(&path) { return match &node.kind { - NodeKind::Directory(d) => d.was_file.as_ref().map(|f| &f.entry), + NodeKind::Directory(d) => { + d.was_file.as_ref().map(|f| &f.entry) + } NodeKind::File(f) => Some(&f.entry), }; } @@ -168,10 +174,15 @@ /// Returns a mutable reference to the entry corresponding to `path` if it /// exists. - pub fn get_mut(&mut self, path: impl AsRef<HgPath>) -> Option<&mut DirstateEntry> { + pub fn get_mut( + &mut self, + path: impl AsRef<HgPath>, + ) -> Option<&mut DirstateEntry> { if let Some(kind) = self.root.get_mut(path.as_ref().as_bytes()) { return match kind { - NodeKind::Directory(d) => d.was_file.as_mut().map(|f| &mut f.entry), + NodeKind::Directory(d) => { + d.was_file.as_mut().map(|f| &mut f.entry) + } NodeKind::File(f) => Some(&mut f.entry), }; } @@ -192,8 +203,12 @@ } /// Remove the entry at `path` and returns it, if it exists. - pub fn remove(&mut self, path: impl AsRef<HgPath>) -> Option<DirstateEntry> { - let RemoveResult { old_entry, .. } = self.root.remove(path.as_ref().as_bytes()); + pub fn remove( + &mut self, + path: impl AsRef<HgPath>, + ) -> Option<DirstateEntry> { + let RemoveResult { old_entry, .. } = + self.root.remove(path.as_ref().as_bytes()); self.files_count = self .files_count .checked_sub(if old_entry.is_some() { 1 } else { 0 }) @@ -344,7 +359,10 @@ size: 30, }; assert_eq!(tree.insert_node(HgPath::new(b"foo"), entry), None); - assert_eq!(tree.insert_node(HgPath::new(b"foo/a"), removed_entry), None); + assert_eq!( + tree.insert_node(HgPath::new(b"foo/a"), removed_entry), + None + ); // The insert should not turn `foo` into a directory as `foo` is not // `Removed`. match tree.get_node(HgPath::new(b"foo")).unwrap().kind { @@ -516,7 +534,10 @@ ..entry }; assert_eq!(tree.insert(HgPath::new(b"a"), entry), None); - assert_eq!(tree.insert_node(HgPath::new(b"a/b/x"), removed_entry), None); + assert_eq!( + tree.insert_node(HgPath::new(b"a/b/x"), removed_entry), + None + ); assert_eq!(tree.files_count, 2); dbg!(&tree); assert_eq!(tree.remove(HgPath::new(b"a")), Some(entry));