changeset 48023:357307feaf61

debugstate: Always call dirstatemap.debug_iter() … passing it a new `all` argument for the `--all` CLI option, instead of conditionally calling `.debug_iter()` or `.items()` This prepares for the next commit. Differential Revision: https://phab.mercurial-scm.org/D11462
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 20 Sep 2021 19:59:09 +0200
parents f2a9db29cb2d
children cedfe2606adf
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
diffstat 6 files changed, 24 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/debugcommands.py	Fri Sep 17 13:33:45 2021 +0200
+++ b/mercurial/debugcommands.py	Mon Sep 20 19:59:09 2021 +0200
@@ -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:
--- a/mercurial/dirstatemap.py	Fri Sep 17 13:33:45 2021 +0200
+++ b/mercurial/dirstatemap.py	Mon Sep 20 19:59:09 2021 +0200
@@ -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
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Fri Sep 17 13:33:45 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Mon Sep 20 19:59:09 2021 +0200
@@ -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)))
         }))
     }
 }
--- a/rust/hg-core/src/dirstate_tree/dispatch.rs	Fri Sep 17 13:33:45 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/dispatch.rs	Mon Sep 20 19:59:09 2021 +0200
@@ -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()
--- a/rust/hg-core/src/dirstate_tree/owning_dispatch.rs	Fri Sep 17 13:33:45 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/owning_dispatch.rs	Mon Sep 20 19:59:09 2021 +0200
@@ -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)
     }
 }
--- a/rust/hg-cpython/src/dirstate/dirstate_map.rs	Fri Sep 17 13:33:45 2021 +0200
+++ b/rust/hg-cpython/src/dirstate/dirstate_map.rs	Mon Sep 20 19:59:09 2021 +0200
@@ -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());