dirstate-tree: Downgrade `&mut Node` to `&Node` in status and serialization
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)
Differential Revision: https://phab.mercurial-scm.org/D10745
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs Wed May 19 13:15:00 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs Wed May 19 13:15:00 2021 +0200
@@ -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));
--- a/rust/hg-core/src/dirstate_tree/on_disk.rs Wed May 19 13:15:00 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/on_disk.rs Wed May 19 13:15:00 2021 +0200
@@ -258,7 +258,7 @@
}
fn write_nodes(
- nodes: &mut dirstate_map::ChildNodes,
+ nodes: &dirstate_map::ChildNodes,
out: &mut Vec<u8>,
) -> Result<ChildNodes, DirstateError> {
// `dirstate_map::ChildNodes` is a `HashMap` with undefined iteration
@@ -269,7 +269,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::<u8>(
full_path.full_path().as_bytes(),
@@ -287,7 +287,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(),
--- a/rust/hg-core/src/dirstate_tree/status.rs Wed May 19 13:15:00 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/status.rs Wed May 19 13:15:00 2021 +0200
@@ -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.par_iter().for_each(
|(child_hg_path, child_node)| {
self.traverse_dirstate_only(
child_hg_path.full_path(),