Patchwork D10364: dirstate-tree: Empty shell for a second Rust DirstateMap implementation

login
register
mail settings
Submitter phabricator
Date April 12, 2021, 12:24 p.m.
Message ID <differential-rev-PHID-DREV-z6dd7ryxp3tarsxrx4wc-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48683/
State Superseded
Headers show

Comments

phabricator - April 12, 2021, 12:24 p.m.
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  For background see description of the previous changeset
  "Make Rust DirstateMap bindings go through a trait object".
  
  Add an empty shell for a opt-in second Rust implementation of the
  `DirstateMap` type and the `status` function. For now all methods panic.
  This can be seen in "action" with:
  
    ./hg status --config experimental.dirstate-tree.in-memory=1

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/configitems.py
  mercurial/dirstate.py
  rust/hg-core/src/dirstate_tree.rs
  rust/hg-core/src/dirstate_tree/dirstate_map.rs
  rust/hg-cpython/src/dirstate/dirstate_map.rs

CHANGE DETAILS




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

Patch

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
@@ -50,8 +50,12 @@ 
 py_class!(pub class DirstateMap |py| {
     @shared data inner: Box<dyn DirstateMapMethods + Send>;
 
-    def __new__(_cls, _root: PyObject) -> PyResult<Self> {
-        let inner = Box::new(RustDirstateMap::default());
+    def __new__(_cls, use_dirstate_tree: bool) -> PyResult<Self> {
+        let inner = if use_dirstate_tree {
+            Box::new(hg::dirstate_tree::dirstate_map::DirstateMap::new()) as _
+        } else {
+            Box::new(RustDirstateMap::default()) as _
+        };
         Self::create_instance(py, inner)
     }
 
diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
new file mode 100644
--- /dev/null
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -0,0 +1,216 @@ 
+use std::path::PathBuf;
+use std::time::Duration;
+
+use crate::matchers::Matcher;
+use crate::utils::hg_path::{HgPath, HgPathBuf};
+use crate::CopyMapIter;
+use crate::DirstateEntry;
+use crate::DirstateError;
+use crate::DirstateMapError;
+use crate::DirstateParents;
+use crate::DirstateStatus;
+use crate::EntryState;
+use crate::FastHashMap;
+use crate::HgPathCow;
+use crate::PatternFileWarning;
+use crate::StateMapIter;
+use crate::StatusError;
+use crate::StatusOptions;
+
+pub struct DirstateMap {
+    // TODO
+}
+
+impl DirstateMap {
+    pub fn new() -> Self {
+        todo!()
+    }
+}
+
+impl super::dispatch::DirstateMapMethods for DirstateMap {
+    fn clear(&mut self) {
+        todo!()
+    }
+
+    fn add_file(
+        &mut self,
+        _filename: &HgPath,
+        _old_state: EntryState,
+        _entry: DirstateEntry,
+    ) -> Result<(), DirstateMapError> {
+        todo!()
+    }
+
+    fn remove_file(
+        &mut self,
+        _filename: &HgPath,
+        _old_state: EntryState,
+        _size: i32,
+    ) -> Result<(), DirstateMapError> {
+        todo!()
+    }
+
+    fn drop_file(
+        &mut self,
+        _filename: &HgPath,
+        _old_state: EntryState,
+    ) -> Result<bool, DirstateMapError> {
+        todo!()
+    }
+
+    fn clear_ambiguous_times(
+        &mut self,
+        _filenames: Vec<HgPathBuf>,
+        _now: i32,
+    ) {
+        todo!()
+    }
+
+    fn non_normal_entries_contains(&mut self, _key: &HgPath) -> bool {
+        todo!()
+    }
+
+    fn non_normal_entries_remove(&mut self, _key: &HgPath) -> bool {
+        todo!()
+    }
+
+    fn non_normal_or_other_parent_paths(
+        &mut self,
+    ) -> Box<dyn Iterator<Item = &HgPathBuf> + '_> {
+        todo!()
+    }
+
+    fn set_non_normal_other_parent_entries(&mut self, _force: bool) {
+        todo!()
+    }
+
+    fn iter_non_normal_paths(
+        &mut self,
+    ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_> {
+        todo!()
+    }
+
+    fn iter_non_normal_paths_panic(
+        &self,
+    ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_> {
+        todo!()
+    }
+
+    fn iter_other_parent_paths(
+        &mut self,
+    ) -> Box<dyn Iterator<Item = &HgPathBuf> + Send + '_> {
+        todo!()
+    }
+
+    fn has_tracked_dir(
+        &mut self,
+        _directory: &HgPath,
+    ) -> Result<bool, DirstateMapError> {
+        todo!()
+    }
+
+    fn has_dir(
+        &mut self,
+        _directory: &HgPath,
+    ) -> Result<bool, DirstateMapError> {
+        todo!()
+    }
+
+    fn parents(
+        &mut self,
+        _file_contents: &[u8],
+    ) -> Result<&DirstateParents, DirstateError> {
+        todo!()
+    }
+
+    fn set_parents(&mut self, _parents: &DirstateParents) {
+        todo!()
+    }
+
+    fn read<'a>(
+        &mut self,
+        _file_contents: &'a [u8],
+    ) -> Result<Option<&'a DirstateParents>, DirstateError> {
+        todo!()
+    }
+
+    fn pack(
+        &mut self,
+        _parents: DirstateParents,
+        _now: Duration,
+    ) -> Result<Vec<u8>, DirstateError> {
+        todo!()
+    }
+
+    fn build_file_fold_map(&mut self) -> &FastHashMap<HgPathBuf, HgPathBuf> {
+        todo!()
+    }
+
+    fn set_all_dirs(&mut self) -> Result<(), DirstateMapError> {
+        todo!()
+    }
+
+    fn set_dirs(&mut self) -> Result<(), DirstateMapError> {
+        todo!()
+    }
+
+    fn status<'a>(
+        &'a self,
+        _matcher: &'a (dyn Matcher + Sync),
+        _root_dir: PathBuf,
+        _ignore_files: Vec<PathBuf>,
+        _options: StatusOptions,
+    ) -> Result<
+        (
+            (Vec<HgPathCow<'a>>, DirstateStatus<'a>),
+            Vec<PatternFileWarning>,
+        ),
+        StatusError,
+    > {
+        todo!()
+    }
+
+    fn copy_map_len(&self) -> usize {
+        todo!()
+    }
+
+    fn copy_map_iter(&self) -> CopyMapIter<'_> {
+        todo!()
+    }
+
+    fn copy_map_contains_key(&self, _key: &HgPath) -> bool {
+        todo!()
+    }
+
+    fn copy_map_get(&self, _key: &HgPath) -> Option<&HgPathBuf> {
+        todo!()
+    }
+
+    fn copy_map_remove(&mut self, _key: &HgPath) -> Option<HgPathBuf> {
+        todo!()
+    }
+
+    fn copy_map_insert(
+        &mut self,
+        _key: HgPathBuf,
+        _value: HgPathBuf,
+    ) -> Option<HgPathBuf> {
+        todo!()
+    }
+
+    fn len(&self) -> usize {
+        todo!()
+    }
+
+    fn contains_key(&self, _key: &HgPath) -> bool {
+        todo!()
+    }
+
+    fn get(&self, _key: &HgPath) -> Option<&DirstateEntry> {
+        todo!()
+    }
+
+    fn iter(&self) -> StateMapIter<'_> {
+        todo!()
+    }
+}
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 +1,2 @@ 
+pub mod dirstate_map;
 pub mod dispatch;
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -1782,7 +1782,12 @@ 
             Does not fill the Dirstatemap when called. This allows for
             optimizations where only setting/getting the parents is needed.
             """
-            self._inner_rustmap = rustmod.DirstateMap(self._root)
+            use_dirstate_tree = self._ui.configbool(
+                b"experimental",
+                b"dirstate-tree.in-memory",
+                False,
+            )
+            self._inner_rustmap = rustmod.DirstateMap(use_dirstate_tree)
             return self._inner_rustmap
 
         @property
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -954,6 +954,11 @@ 
 )
 coreconfigitem(
     b'experimental',
+    b'dirstate-tree.in-memory',
+    default=False,
+)
+coreconfigitem(
+    b'experimental',
     b'editortmpinhg',
     default=False,
 )