diff mercurial/dirstatemap.py @ 47521:abed645b8e96

dirstate: move the handling of special case within the dirstatemap The dirstatemap is as well, if not better, suited to decided how to encode the various case. So we move the associated code in the dirstatemap `addfile` method. This means the dirstate no longer need to know about the various magic value used in the dirstate V1 format. The pain of the messy API start to be quite palpable in Rust, we should clean this up once the current large refactoring is dealt with. Differential Revision: https://phab.mercurial-scm.org/D10963
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 04 Jul 2021 20:23:19 +0200
parents 559aee84b889
children 69a463a4f193
line wrap: on
line diff
--- a/mercurial/dirstatemap.py	Sun Jul 04 20:41:27 2021 +0200
+++ b/mercurial/dirstatemap.py	Sun Jul 04 20:23:19 2021 +0200
@@ -35,6 +35,8 @@
 # a special value used internally for `time` if the time is ambigeous
 AMBIGUOUS_TIME = -1
 
+rangemask = 0x7FFFFFFF
+
 
 class dirstatemap(object):
     """Map encapsulating the dirstate's contents.
@@ -142,8 +144,37 @@
         """Loads the underlying data, if it's not already loaded"""
         self._map
 
-    def addfile(self, f, oldstate, state, mode, size, mtime):
+    def addfile(
+        self,
+        f,
+        oldstate,
+        state,
+        mode,
+        size=None,
+        mtime=None,
+        from_p2=False,
+        possibly_dirty=False,
+    ):
         """Add a tracked file to the dirstate."""
+        if state == b'a':
+            assert not possibly_dirty
+            assert not from_p2
+            size = NONNORMAL
+            mtime = AMBIGUOUS_TIME
+        elif from_p2:
+            assert not possibly_dirty
+            size = FROM_P2
+            mtime = AMBIGUOUS_TIME
+        elif possibly_dirty:
+            size = NONNORMAL
+            mtime = AMBIGUOUS_TIME
+        else:
+            assert size != FROM_P2
+            assert size != NONNORMAL
+            size = size & rangemask
+            mtime = mtime & rangemask
+        assert size is not None
+        assert mtime is not None
         if oldstate in b"?r" and "_dirs" in self.__dict__:
             self._dirs.addpath(f)
         if oldstate == b"?" and "_alldirs" in self.__dict__:
@@ -425,8 +456,27 @@
                 False,
             )
 
-        def addfile(self, *args, **kwargs):
-            return self._rustmap.addfile(*args, **kwargs)
+        def addfile(
+            self,
+            f,
+            oldstate,
+            state,
+            mode,
+            size=None,
+            mtime=None,
+            from_p2=False,
+            possibly_dirty=False,
+        ):
+            return self._rustmap.addfile(
+                f,
+                oldstate,
+                state,
+                mode,
+                size,
+                mtime,
+                from_p2,
+                possibly_dirty,
+            )
 
         def removefile(self, *args, **kwargs):
             return self._rustmap.removefile(*args, **kwargs)