D10921: dirstate: Removed unused instances of `DirsMultiset`

SimonSapin phabricator at mercurial-scm.org
Fri Jul 2 12:37:44 UTC 2021


SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  … in Rust-backed dirstatemap.
  
  The Python class `dirstatemap` had cached properties `_dirs` and `_alldirs`
  that were not used for `hastrackeddir` and `hasdir` since they were redundant
  with corresponding fields for the Rust `DirstateMap` struct.
  
  `dirfoldmap` is modified to reuse instead the directory iterator introduced
  in 3b9914b28133c0918186b6e8b9e4f1916e21338d <https://phab.mercurial-scm.org/rHG3b9914b28133c0918186b6e8b9e4f1916e21338d>.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/dirstate/dispatch.rs b/rust/hg-cpython/src/dirstate/dispatch.rs
--- a/rust/hg-cpython/src/dirstate/dispatch.rs
+++ b/rust/hg-cpython/src/dirstate/dispatch.rs
@@ -128,14 +128,6 @@
         self.get_mut().pack_v2(parents, now)
     }
 
-    fn set_all_dirs(&mut self) -> Result<(), DirstateError> {
-        self.get_mut().set_all_dirs()
-    }
-
-    fn set_dirs(&mut self) -> Result<(), DirstateError> {
-        self.get_mut().set_dirs()
-    }
-
     fn status<'a>(
         &'a mut self,
         matcher: &'a (dyn Matcher + Sync),
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
@@ -19,11 +19,11 @@
 
 use crate::{
     dirstate::copymap::{CopyMap, CopyMapItemsIterator, CopyMapKeysIterator},
+    dirstate::make_dirstate_tuple,
     dirstate::non_normal_entries::{
         NonNormalEntries, NonNormalEntriesIterator,
     },
     dirstate::owning::OwningDirstateMap,
-    dirstate::{dirs_multiset::Dirs, make_dirstate_tuple},
     parsers::dirstate_parents_to_pytuple,
 };
 use hg::{
@@ -34,8 +34,8 @@
     revlog::Node,
     utils::files::normalize_case,
     utils::hg_path::{HgPath, HgPathBuf},
-    DirsMultiset, DirstateEntry, DirstateError,
-    DirstateMap as RustDirstateMap, DirstateParents, EntryState, StateMapIter,
+    DirstateEntry, DirstateError, DirstateMap as RustDirstateMap,
+    DirstateParents, EntryState, StateMapIter,
 };
 
 // TODO
@@ -391,40 +391,6 @@
         )
     }
 
-    def getdirs(&self) -> PyResult<Dirs> {
-        // TODO don't copy, share the reference
-        self.inner(py).borrow_mut().set_dirs()
-            .map_err(|e| {
-                PyErr::new::<exc::ValueError, _>(py, e.to_string())
-            })?;
-        Dirs::from_inner(
-            py,
-            DirsMultiset::from_dirstate(
-                self.inner(py).borrow().iter(),
-                Some(EntryState::Removed),
-            )
-            .map_err(|e| {
-                PyErr::new::<exc::ValueError, _>(py, e.to_string())
-            })?,
-        )
-    }
-    def getalldirs(&self) -> PyResult<Dirs> {
-        // TODO don't copy, share the reference
-        self.inner(py).borrow_mut().set_all_dirs()
-            .map_err(|e| {
-                PyErr::new::<exc::ValueError, _>(py, e.to_string())
-            })?;
-        Dirs::from_inner(
-            py,
-            DirsMultiset::from_dirstate(
-                self.inner(py).borrow().iter(),
-                None,
-            ).map_err(|e| {
-                PyErr::new::<exc::ValueError, _>(py, e.to_string())
-            })?,
-        )
-    }
-
     // TODO all copymap* methods, see docstring above
     def copymapcopy(&self) -> PyResult<PyDict> {
         let dict = PyDict::new(py);
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
@@ -95,10 +95,6 @@
         now: Timestamp,
     ) -> Result<Vec<u8>, DirstateError>;
 
-    fn set_all_dirs(&mut self) -> Result<(), DirstateError>;
-
-    fn set_dirs(&mut self) -> Result<(), DirstateError>;
-
     fn status<'a>(
         &'a mut self,
         matcher: &'a (dyn Matcher + Sync),
@@ -281,14 +277,6 @@
         )
     }
 
-    fn set_all_dirs(&mut self) -> Result<(), DirstateError> {
-        self.set_all_dirs()
-    }
-
-    fn set_dirs(&mut self) -> Result<(), DirstateError> {
-        self.set_dirs()
-    }
-
     fn status<'a>(
         &'a mut self,
         matcher: &'a (dyn Matcher + Sync),
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
@@ -977,18 +977,6 @@
         on_disk::write(self, parents)
     }
 
-    fn set_all_dirs(&mut self) -> Result<(), DirstateError> {
-        // Do nothing, this `DirstateMap` does not a separate `all_dirs` that
-        // needs to be recomputed
-        Ok(())
-    }
-
-    fn set_dirs(&mut self) -> Result<(), DirstateError> {
-        // Do nothing, this `DirstateMap` does not a separate `dirs` that needs
-        // to be recomputed
-        Ok(())
-    }
-
     fn status<'a>(
         &'a mut self,
         matcher: &'a (dyn Matcher + Sync),
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -1951,22 +1951,12 @@
             return self._rustmap.filefoldmapasdict()
 
         def hastrackeddir(self, d):
-            self._dirs  # Trigger Python's propertycache
             return self._rustmap.hastrackeddir(d)
 
         def hasdir(self, d):
-            self._dirs  # Trigger Python's propertycache
             return self._rustmap.hasdir(d)
 
         @propertycache
-        def _dirs(self):
-            return self._rustmap.getdirs()
-
-        @propertycache
-        def _alldirs(self):
-            return self._rustmap.getalldirs()
-
-        @propertycache
         def identity(self):
             self._rustmap
             return self.identity
@@ -1988,6 +1978,6 @@
         def dirfoldmap(self):
             f = {}
             normcase = util.normcase
-            for name in self._dirs:
+            for name, _pseudo_entry in self.directories():
                 f[normcase(name)] = name
             return f
diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -1147,7 +1147,10 @@
 
     def d():
         dirstate.hasdir(b'a')
-        del dirstate._map._dirs
+        try:
+            del dirstate._map._dirs
+        except AttributeError:
+            pass
 
     timer(d)
     fm.end()
@@ -1225,7 +1228,10 @@
     repo.dirstate.hasdir(b"a")
 
     def setup():
-        del repo.dirstate._map._dirs
+        try:
+            del repo.dirstate._map._dirs
+        except AttributeError:
+            pass
 
     def d():
         repo.dirstate.hasdir(b"a")
@@ -1268,7 +1274,10 @@
 
     def setup():
         del dirstate._map.dirfoldmap
-        del dirstate._map._dirs
+        try:
+            del dirstate._map._dirs
+        except AttributeError:
+            pass
 
     def d():
         dirstate._map.dirfoldmap.get(b'a')



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


More information about the Mercurial-devel mailing list