[Updated] D11462: debugstate: Always call dirstatemap.debug_iter()

SimonSapin phabricator at mercurial-scm.org
Wed Sep 22 08:57:46 UTC 2021


Closed by commit rHG357307feaf61: debugstate: Always call dirstatemap.debug_iter() (authored by SimonSapin).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D11462?vs=30336&id=30374

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D11462/new/

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

AFFECTED FILES
  mercurial/debugcommands.py
  mercurial/dirstatemap.py
  rust/hg-core/src/dirstate_tree/dirstate_map.rs
  rust/hg-core/src/dirstate_tree/dispatch.rs
  rust/hg-core/src/dirstate_tree/owning_dispatch.rs
  rust/hg-cpython/src/dirstate/dirstate_map.rs

CHANGE DETAILS

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
@@ -606,9 +606,9 @@
         Ok(dirs)
     }
 
-    def debug_iter(&self) -> PyResult<PyList> {
+    def debug_iter(&self, all: bool) -> PyResult<PyList> {
         let dirs = PyList::new(py, &[]);
-        for item in self.inner(py).borrow().debug_iter() {
+        for item in self.inner(py).borrow().debug_iter(all) {
             let (path, (state, mode, size, mtime)) =
                 item.map_err(|e| v2_error(py, e))?;
             let path = PyBytes::new(py, path.as_bytes());
diff --git a/rust/hg-core/src/dirstate_tree/owning_dispatch.rs b/rust/hg-core/src/dirstate_tree/owning_dispatch.rs
--- a/rust/hg-core/src/dirstate_tree/owning_dispatch.rs
+++ b/rust/hg-core/src/dirstate_tree/owning_dispatch.rs
@@ -226,6 +226,7 @@
 
     fn debug_iter(
         &self,
+        all: bool,
     ) -> Box<
         dyn Iterator<
                 Item = Result<
@@ -235,6 +236,6 @@
             > + Send
             + '_,
     > {
-        self.get().debug_iter()
+        self.get().debug_iter(all)
     }
 }
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
@@ -290,13 +290,15 @@
     /// node stored in this dirstate map, for the purpose of the `hg
     /// debugdirstate` command.
     ///
-    /// For nodes that don’t have an entry, `state` is the ASCII space.
+    /// If `all` is true, include  nodes that don’t have an entry.
+    /// For such nodes `state` is the ASCII space.
     /// An `mtime` may still be present. It is used to optimize `status`.
     ///
     /// Because parse errors can happen during iteration, the iterated items
     /// are `Result`s.
     fn debug_iter(
         &self,
+        all: bool,
     ) -> Box<
         dyn Iterator<
                 Item = Result<
@@ -538,6 +540,7 @@
 
     fn debug_iter(
         &self,
+        all: bool,
     ) -> Box<
         dyn Iterator<
                 Item = Result<
@@ -547,6 +550,9 @@
             > + Send
             + '_,
     > {
+        // Not used for the flat (not tree-based) DirstateMap
+        let _ = all;
+
         Box::new(
             (&**self)
                 .iter()
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
@@ -1289,6 +1289,7 @@
 
     fn debug_iter(
         &self,
+        all: bool,
     ) -> Box<
         dyn Iterator<
                 Item = Result<
@@ -1298,16 +1299,17 @@
             > + Send
             + '_,
     > {
-        Box::new(self.iter_nodes().map(move |node| {
-            let node = node?;
+        Box::new(filter_map_results(self.iter_nodes(), move |node| {
             let debug_tuple = if let Some(entry) = node.entry()? {
                 entry.debug_tuple()
+            } else if !all {
+                return Ok(None);
             } else if let Some(mtime) = node.cached_directory_mtime() {
                 (b' ', 0, -1, mtime.seconds() as i32)
             } else {
                 (b' ', 0, -1, -1)
             };
-            Ok((node.full_path(self.on_disk)?, debug_tuple))
+            Ok(Some((node.full_path(self.on_disk)?, debug_tuple)))
         }))
     }
 }
diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -118,7 +118,11 @@
     # forward for python2,3 compat
     iteritems = items
 
-    debug_iter = items
+    def debug_iter(self, all):
+        """
+        `all` is unused when Rust is not enabled
+        """
+        return self.item()
 
     def __len__(self):
         return len(self._map)
@@ -700,8 +704,8 @@
         def copymap(self):
             return self._rustmap.copymap()
 
-        def debug_iter(self):
-            return self._rustmap.debug_iter()
+        def debug_iter(self, all):
+            return self._rustmap.debug_iter(all)
 
         def preload(self):
             self._rustmap
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -968,10 +968,7 @@
         )  # sort by mtime, then by filename
     else:
         keyfunc = None  # sort by filename
-    if opts['all']:
-        entries = list(repo.dirstate._map.debug_iter())
-    else:
-        entries = list(pycompat.iteritems(repo.dirstate))
+    entries = list(repo.dirstate._map.debug_iter(all=opts['all']))
     entries.sort(key=keyfunc)
     for file_, ent in entries:
         if ent.v1_mtime() == -1:



To: SimonSapin, #hg-reviewers, Alphare
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20210922/0446582a/attachment-0002.html>


More information about the Mercurial-patches mailing list