Patchwork D11574: dirstatemap: use a common implement for set_tracked

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

Comments

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

REVISION SUMMARY
  Same logic as for `set_untracked` this make sure both implementation use the
  same logic for this.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -109,6 +109,37 @@ 
 
     ### method to manipulate the entries
 
+    def set_tracked(self, filename):
+        new = False
+        entry = self.get(filename)
+        if entry is None:
+            self._dirs_incr(filename)
+            entry = DirstateItem(
+                p1_tracked=False,
+                p2_tracked=False,
+                wc_tracked=True,
+                merged=False,
+                clean_p1=False,
+                clean_p2=False,
+                possibly_dirty=False,
+                parentfiledata=None,
+            )
+
+            self._insert_entry(filename, entry)
+            new = True
+        elif not entry.tracked:
+            self._dirs_incr(filename, entry)
+            entry.set_tracked()
+            self._refresh_entry(filename, entry)
+            new = True
+        else:
+            # XXX This is probably overkill for more case, but we need this to
+            # fully replace the `normallookup` call with `set_tracked` one.
+            # Consider smoothing this in the future.
+            entry.set_possibly_dirty()
+            self._refresh_entry(filename, entry)
+        return new
+
     def set_untracked(self, f):
         """Mark a file as no longer tracked in the dirstate map"""
         entry = self.get(f)
@@ -492,34 +523,6 @@ 
         )
         self._map[filename] = entry
 
-    def set_tracked(self, filename):
-        new = False
-        entry = self.get(filename)
-        if entry is None:
-            self._dirs_incr(filename)
-            entry = DirstateItem(
-                p1_tracked=False,
-                p2_tracked=False,
-                wc_tracked=True,
-                merged=False,
-                clean_p1=False,
-                clean_p2=False,
-                possibly_dirty=False,
-                parentfiledata=None,
-            )
-            self._map[filename] = entry
-            new = True
-        elif not entry.tracked:
-            self._dirs_incr(filename, entry)
-            entry.set_tracked()
-            new = True
-        else:
-            # XXX This is probably overkill for more case, but we need this to
-            # fully replace the `normallookup` call with `set_tracked` one.
-            # Consider smoothing this in the future.
-            self.set_possibly_dirty(filename)
-        return new
-
 
 if rustmod is not None:
 
@@ -894,23 +897,6 @@ 
             else:
                 assert False, 'unreachable'
 
-        def set_tracked(self, filename):
-            new = False
-            entry = self.get(filename)
-            if entry is None:
-                self.addfile(filename, added=True)
-                new = True
-            elif not entry.tracked:
-                entry.set_tracked()
-                self._map.set_dirstate_item(filename, entry)
-                new = True
-            else:
-                # XXX This is probably overkill for more case, but we need this to
-                # fully replace the `normallookup` call with `set_tracked` one.
-                # Consider smoothing this in the future.
-                self.set_possibly_dirty(filename)
-            return new
-
         ### Legacy method we need to get rid of
 
         def addfile(