dirstate-tree: Give to `status()` mutable access to the `DirstateMap`
authorSimon Sapin <simon.sapin@octobus.net>
Fri, 16 Apr 2021 12:12:04 +0200
changeset 47112 d5956136d19d
parent 47111 623c8e4ddc6d
child 47113 be579775c2d9
dirstate-tree: Give to `status()` mutable access to the `DirstateMap` Differential Revision: https://phab.mercurial-scm.org/D10546
rust/hg-core/src/dirstate/status.rs
rust/hg-core/src/dirstate_tree.rs
rust/hg-core/src/dirstate_tree/dirstate_map.rs
rust/hg-core/src/dirstate_tree/dispatch.rs
rust/hg-core/src/dirstate_tree/status.rs
rust/hg-cpython/src/dirstate/dirstate_map.rs
rust/hg-cpython/src/dirstate/status.rs
--- a/rust/hg-core/src/dirstate/status.rs	Tue Apr 06 15:49:01 2021 +0200
+++ b/rust/hg-core/src/dirstate/status.rs	Fri Apr 16 12:12:04 2021 +0200
@@ -97,7 +97,8 @@
 
 /// `Box<dyn Trait>` is syntactic sugar for `Box<dyn Trait, 'static>`, so add
 /// an explicit lifetime here to not fight `'static` bounds "out of nowhere".
-type IgnoreFnType<'a> = Box<dyn for<'r> Fn(&'r HgPath) -> bool + Sync + 'a>;
+pub type IgnoreFnType<'a> =
+    Box<dyn for<'r> Fn(&'r HgPath) -> bool + Sync + 'a>;
 
 /// We have a good mix of owned (from directory traversal) and borrowed (from
 /// the dirstate/explicit) paths, this comes up a lot.
--- a/rust/hg-core/src/dirstate_tree.rs	Tue Apr 06 15:49:01 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree.rs	Fri Apr 16 12:12:04 2021 +0200
@@ -1,3 +1,4 @@
 pub mod dirstate_map;
 pub mod dispatch;
 pub mod path_with_basename;
+mod status;
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Tue Apr 06 15:49:01 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Fri Apr 16 12:12:04 2021 +0200
@@ -576,14 +576,14 @@
     }
 
     fn status<'a>(
-        &'a self,
-        _matcher: &'a (dyn Matcher + Sync),
-        _root_dir: PathBuf,
-        _ignore_files: Vec<PathBuf>,
-        _options: StatusOptions,
+        &'a mut self,
+        matcher: &'a (dyn Matcher + Sync),
+        root_dir: PathBuf,
+        ignore_files: Vec<PathBuf>,
+        options: StatusOptions,
     ) -> Result<(DirstateStatus<'a>, Vec<PatternFileWarning>), StatusError>
     {
-        todo!()
+        super::status::status(self, matcher, root_dir, ignore_files, options)
     }
 
     fn copy_map_len(&self) -> usize {
--- a/rust/hg-core/src/dirstate_tree/dispatch.rs	Tue Apr 06 15:49:01 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/dispatch.rs	Fri Apr 16 12:12:04 2021 +0200
@@ -96,7 +96,7 @@
     fn set_dirs(&mut self) -> Result<(), DirstateMapError>;
 
     fn status<'a>(
-        &'a self,
+        &'a mut self,
         matcher: &'a (dyn Matcher + Sync),
         root_dir: PathBuf,
         ignore_files: Vec<PathBuf>,
@@ -258,7 +258,7 @@
     }
 
     fn status<'a>(
-        &'a self,
+        &'a mut self,
         matcher: &'a (dyn Matcher + Sync),
         root_dir: PathBuf,
         ignore_files: Vec<PathBuf>,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rust/hg-core/src/dirstate_tree/status.rs	Fri Apr 16 12:12:04 2021 +0200
@@ -0,0 +1,17 @@
+use crate::dirstate_tree::dirstate_map::DirstateMap;
+use crate::matchers::Matcher;
+use crate::DirstateStatus;
+use crate::PatternFileWarning;
+use crate::StatusError;
+use crate::StatusOptions;
+use std::path::PathBuf;
+
+pub fn status<'a>(
+    _dmap: &'a mut DirstateMap,
+    _matcher: &'a (dyn Matcher + Sync),
+    _root_dir: PathBuf,
+    _ignore_files: Vec<PathBuf>,
+    _options: StatusOptions,
+) -> Result<(DirstateStatus<'a>, Vec<PatternFileWarning>), StatusError> {
+    todo!()
+}
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs	Tue Apr 06 15:49:01 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs	Fri Apr 16 12:12:04 2021 +0200
@@ -8,7 +8,7 @@
 //! Bindings for the `hg::dirstate::dirstate_map` file provided by the
 //! `hg-core` package.
 
-use std::cell::{Ref, RefCell};
+use std::cell::{RefCell, RefMut};
 use std::convert::TryInto;
 
 use cpython::{
@@ -527,11 +527,11 @@
 });
 
 impl DirstateMap {
-    pub fn get_inner<'a>(
+    pub fn get_inner_mut<'a>(
         &'a self,
         py: Python<'a>,
-    ) -> Ref<'a, Box<dyn DirstateMapMethods + Send>> {
-        self.inner(py).borrow()
+    ) -> RefMut<'a, Box<dyn DirstateMapMethods + Send>> {
+        self.inner(py).borrow_mut()
     }
     fn translate_key(
         py: Python,
--- a/rust/hg-cpython/src/dirstate/status.rs	Tue Apr 06 15:49:01 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/status.rs	Fri Apr 16 12:12:04 2021 +0200
@@ -112,7 +112,7 @@
     let root_dir = get_path_from_bytes(bytes.data(py));
 
     let dmap: DirstateMap = dmap.to_py_object(py);
-    let dmap = dmap.get_inner(py);
+    let mut dmap = dmap.get_inner_mut(py);
 
     let ignore_files: PyResult<Vec<_>> = ignore_files
         .iter(py)