From patchwork Wed May 19 16:38:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: D10745: dirstate-tree: Downgrade `&mut Node` to `&Node` in status and serialization From: phabricator X-Patchwork-Id: 49064 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Wed, 19 May 2021 16:38:31 +0000 SimonSapin created this revision. Herald added a reviewer: hg-reviewers. Herald added a subscriber: mercurial-patches. REVISION SUMMARY Mutable access is not used, and upcoming changes will make it more costly (with copy-on-write nodes that can be read from disk representation) REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D10745 AFFECTED FILES rust/hg-core/src/dirstate_tree/dirstate_map.rs rust/hg-core/src/dirstate_tree/on_disk.rs rust/hg-core/src/dirstate_tree/status.rs CHANGE DETAILS To: SimonSapin, #hg-reviewers Cc: mercurial-patches, mercurial-devel diff --git a/rust/hg-core/src/dirstate_tree/status.rs b/rust/hg-core/src/dirstate_tree/status.rs --- a/rust/hg-core/src/dirstate_tree/status.rs +++ b/rust/hg-core/src/dirstate_tree/status.rs @@ -56,7 +56,7 @@ let has_ignored_ancestor = false; common.traverse_fs_directory_and_dirstate( has_ignored_ancestor, - &mut dmap.root, + &dmap.root, hg_path, &root_dir, is_at_repo_root, @@ -93,7 +93,7 @@ fn traverse_fs_directory_and_dirstate( &self, has_ignored_ancestor: bool, - dirstate_nodes: &'tree mut ChildNodes, + dirstate_nodes: &'tree ChildNodes, directory_hg_path: &'tree HgPath, directory_fs_path: &Path, is_at_repo_root: bool, @@ -151,7 +151,7 @@ &self, fs_entry: &DirEntry, hg_path: &'tree HgPath, - dirstate_node: &'tree mut Node, + dirstate_node: &'tree Node, has_ignored_ancestor: bool, ) { let file_type = fs_entry.metadata.file_type(); @@ -173,7 +173,7 @@ let is_at_repo_root = false; self.traverse_fs_directory_and_dirstate( is_ignored, - &mut dirstate_node.children, + &dirstate_node.children, hg_path, &fs_entry.full_path, is_at_repo_root, @@ -220,7 +220,7 @@ } } - for (child_hg_path, child_node) in &mut dirstate_node.children { + for (child_hg_path, child_node) in &dirstate_node.children { self.traverse_dirstate_only( child_hg_path.full_path(), child_node, @@ -278,10 +278,10 @@ fn traverse_dirstate_only( &self, hg_path: &'tree HgPath, - dirstate_node: &'tree mut Node, + dirstate_node: &'tree Node, ) { self.mark_removed_or_deleted_if_file(hg_path, dirstate_node.state()); - dirstate_node.children.par_iter_mut().for_each( + dirstate_node.children.iter().for_each( |(child_hg_path, child_node)| { self.traverse_dirstate_only( child_hg_path.full_path(), diff --git a/rust/hg-core/src/dirstate_tree/on_disk.rs b/rust/hg-core/src/dirstate_tree/on_disk.rs --- a/rust/hg-core/src/dirstate_tree/on_disk.rs +++ b/rust/hg-core/src/dirstate_tree/on_disk.rs @@ -259,7 +259,7 @@ /// Serialize the dirstate to the `v2` format after clearing ambigous `mtime`s. fn write_nodes( - nodes: &mut dirstate_map::ChildNodes, + nodes: &dirstate_map::ChildNodes, out: &mut Vec, ) -> Result { // `dirstate_map::ChildNodes` is a `HashMap` with undefined iteration @@ -270,7 +270,7 @@ let mut on_disk_nodes = Vec::with_capacity(nodes.len()); for (full_path, node) in nodes { on_disk_nodes.push(Node { - children: write_nodes(&mut node.children, out)?, + children: write_nodes(&node.children, out)?, tracked_descendants_count: node.tracked_descendants_count.into(), full_path: write_slice::( full_path.full_path().as_bytes(), @@ -288,7 +288,7 @@ len: 0.into(), } }, - entry: if let Some(entry) = &mut node.entry { + entry: if let Some(entry) = &node.entry { OptEntry { state: entry.state.into(), mode: entry.mode.into(), diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs b/rust/hg-core/src/dirstate_tree/dirstate_map.rs --- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs +++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs @@ -68,9 +68,9 @@ } pub(super) fn sorted<'tree>( - nodes: &'tree mut ChildNodes<'on_disk>, - ) -> Vec<(&'tree NodeKey<'on_disk>, &'tree mut Self)> { - let mut vec: Vec<_> = nodes.iter_mut().collect(); + nodes: &'tree ChildNodes<'on_disk>, + ) -> Vec<(&'tree NodeKey<'on_disk>, &'tree Self)> { + let mut vec: Vec<_> = nodes.iter().collect(); // `sort_unstable_by_key` doesn’t allow keys borrowing from the value: // https://github.com/rust-lang/rust/issues/34162 vec.sort_unstable_by(|(path1, _), (path2, _)| path1.cmp(path2));