Patchwork D11581: dirstatemap: align the Rust wrapper implementation of `setparent`

login
register
mail settings
Submitter phabricator
Date Oct. 2, 2021, 3:06 p.m.
Message ID <differential-rev-PHID-DREV-4xkmxia4ehcnmulb3aea-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49905/
State Superseded
Headers show

Comments

phabricator - Oct. 2, 2021, 3:06 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We move to using `drop_merge_data` as intended.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/dirstatemap.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -638,33 +638,17 @@ 
                 # TODO: move this the whole loop to Rust where `iter_mut`
                 # enables in-place mutation of elements of a collection while
                 # iterating it, without mutating the collection itself.
-                candidatefiles = [
-                    (f, s)
-                    for f, s in self._map.items()
-                    if s.merged or s.from_p2
+                files_with_p2_info = [
+                    f for f, s in self._map.items() if s.merged or s.from_p2
                 ]
-                for f, s in candidatefiles:
-                    # Discard "merged" markers when moving away from a merge state
-                    if s.merged:
-                        source = self.copymap.get(f)
-                        if source:
-                            copies[f] = source
-                        self.reset_state(
-                            f,
-                            wc_tracked=True,
-                            p1_tracked=True,
-                            possibly_dirty=True,
-                        )
-                    # Also fix up otherparent markers
-                    elif s.from_p2:
-                        source = self.copymap.get(f)
-                        if source:
-                            copies[f] = source
-                        self.reset_state(
-                            f,
-                            p1_tracked=False,
-                            wc_tracked=True,
-                        )
+                rust_map = self._map
+                for f in files_with_p2_info:
+                    e = rust_map.get(f)
+                    source = self.copymap.pop(f, None)
+                    if source:
+                        copies[f] = source
+                    e.drop_merge_data()
+                    rust_map.set_dirstate_item(f, e)
             return copies
 
         def parents(self):