changeset 47204:47ccab19bf9f

dirstate-tree: Remove newly-empty nodes after removing a `DirstateEntry` This is actually necessary to make `DirstateMap::has_dir` correct, since it assumes that a node without a `DirstateEntry` has at least one descedant node with a `DirstateEntry`. This bug would become apparent when a later changeset persists tree nodes on disk in the "dirstate-v2" format. Differential Revision: https://phab.mercurial-scm.org/D10706
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 10 May 2021 21:59:13 +0200
parents 1249eb9cc332
children acd84c434896
files rust/hg-core/src/dirstate_tree/dirstate_map.rs tests/test-status.t
diffstat 2 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Mon May 10 21:31:05 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Mon May 10 21:59:13 2021 +0200
@@ -379,9 +379,14 @@
                     had_entry: node.entry.take().is_some(),
                     had_copy_source: node.copy_source.take().is_some(),
                 };
-                // TODO: this leaves in the tree a "non-file" node. Should we
-                // remove the node instead, together with ancestor nodes for
-                // directories that become empty?
+            }
+            // After recursion, for both leaf (rest_of_path is None) nodes and
+            // parent nodes, remove a node if it just became empty.
+            if node.entry.is_none()
+                && node.copy_source.is_none()
+                && node.children.is_empty()
+            {
+                nodes.remove(first_path_component);
             }
             Some(dropped)
         }
--- a/tests/test-status.t	Mon May 10 21:31:05 2021 +0200
+++ b/tests/test-status.t	Mon May 10 21:59:13 2021 +0200
@@ -711,6 +711,9 @@
   $ hg rm b
   $ hg status a
   R a
+  $ hg commit -qm '#1'
+  $ hg status a
+  a: $ENOENT$
 
 Check using include flag with pattern when status does not need to traverse
 the working directory (issue6483)