Patchwork D12431: rust-dirstatemap: properly decrement counter for tracked descendants

login
register
mail settings
Submitter phabricator
Date April 4, 2022, 3:30 p.m.
Message ID <differential-rev-PHID-DREV-rufvuvgkhx63qs6ly3vd-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50776/
State New
Headers show

Comments

phabricator - April 4, 2022, 3:30 p.m.
Alphare created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  I found this bug when writing unit tests after the fact for the `DirstateMap`.
  We never decremented the tracked descendants counter since we were always
  resetting the node data before reading it. This also drops the use of `state`,
  in favor of the new API to get that information.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  rust/hg-core/src/dirstate_tree/dirstate_map.rs

CHANGE DETAILS




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

Patch

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
@@ -858,7 +858,9 @@ 
                     return Ok(None);
                 }
             } else {
-                let had_entry = node.data.has_entry();
+                let entry = node.data.as_entry();
+                let was_tracked = entry.map_or(false, |entry| entry.tracked());
+                let had_entry = entry.is_some();
                 if had_entry {
                     node.data = NodeData::None
                 }
@@ -867,10 +869,7 @@ 
                     node.copy_source = None
                 }
                 dropped = Dropped {
-                    was_tracked: node
-                        .data
-                        .as_entry()
-                        .map_or(false, |entry| entry.state().is_tracked()),
+                    was_tracked,
                     had_entry,
                     had_copy_source: node.copy_source.take().is_some(),
                 };