Patchwork D10546: dirstate-tree: Give to `status()` mutable access to the `DirstateMap`

login
register
mail settings
Submitter phabricator
Date May 3, 2021, 10:28 a.m.
Message ID <differential-rev-PHID-DREV-pgnb5vla2hftsttje25j-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48869/
State Superseded
Headers show

Comments

phabricator - May 3, 2021, 10:28 a.m.
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10546

AFFECTED FILES
  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

CHANGE DETAILS




To: SimonSapin, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/rust/hg-cpython/src/dirstate/status.rs b/rust/hg-cpython/src/dirstate/status.rs
--- a/rust/hg-cpython/src/dirstate/status.rs
+++ b/rust/hg-cpython/src/dirstate/status.rs
@@ -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(py);
 
     let ignore_files: PyResult<Vec<_>> = ignore_files
         .iter(py)
diff --git a/rust/hg-cpython/src/dirstate/dirstate_map.rs b/rust/hg-cpython/src/dirstate/dirstate_map.rs
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs
@@ -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::{
@@ -530,8 +530,8 @@ 
     pub fn get_inner<'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,
diff --git a/rust/hg-core/src/dirstate_tree/status.rs b/rust/hg-core/src/dirstate_tree/status.rs
new file mode 100644
--- /dev/null
+++ b/rust/hg-core/src/dirstate_tree/status.rs
@@ -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!()
+}
diff --git a/rust/hg-core/src/dirstate_tree/dispatch.rs b/rust/hg-core/src/dirstate_tree/dispatch.rs
--- a/rust/hg-core/src/dirstate_tree/dispatch.rs
+++ b/rust/hg-core/src/dirstate_tree/dispatch.rs
@@ -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>,
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
@@ -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 {
diff --git a/rust/hg-core/src/dirstate_tree.rs b/rust/hg-core/src/dirstate_tree.rs
--- a/rust/hg-core/src/dirstate_tree.rs
+++ b/rust/hg-core/src/dirstate_tree.rs
@@ -1,3 +1,4 @@ 
 pub mod dirstate_map;
 pub mod dispatch;
 pub mod path_with_basename;
+mod status;
diff --git a/rust/hg-core/src/dirstate/status.rs b/rust/hg-core/src/dirstate/status.rs
--- a/rust/hg-core/src/dirstate/status.rs
+++ b/rust/hg-core/src/dirstate/status.rs
@@ -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.