diff mercurial/pure/parsers.py @ 47905:c0d6a59a7704

dirstate-item: add dedicated "legacy" constructor for `addfile` case This way the internal details of how a DirstateItem is encoded is encapsulated within the DirstateItem. This will finally give use some latitude to change the data we store in a DirstateItem. The addfile logic will likely be rewritten eventually and these dedicated constructor can be removed at that time. In the mean-time this should help with hiding internal details of DirstateItem and to migrate it to new internal storage and logic. Differential Revision: https://phab.mercurial-scm.org/D11330
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 16 Jul 2021 18:12:27 +0200
parents 22c39f8acf78
children ba9491be5e0c
line wrap: on
line diff
--- a/mercurial/pure/parsers.py	Fri Jul 16 17:32:40 2021 +0200
+++ b/mercurial/pure/parsers.py	Fri Jul 16 18:12:27 2021 +0200
@@ -119,6 +119,73 @@
             assert False, 'unreachable'
 
     @classmethod
+    def new_added(cls):
+        """constructor to help legacy API to build a new "added" item
+
+        Should eventually be removed
+        """
+        instance = cls()
+        instance._state = b'a'
+        instance._mode = 0
+        instance._size = NONNORMAL
+        instance._mtime = AMBIGUOUS_TIME
+        return instance
+
+    @classmethod
+    def new_merged(cls):
+        """constructor to help legacy API to build a new "merged" item
+
+        Should eventually be removed
+        """
+        instance = cls()
+        instance._state = b'm'
+        instance._mode = 0
+        instance._size = FROM_P2
+        instance._mtime = AMBIGUOUS_TIME
+        return instance
+
+    @classmethod
+    def new_from_p2(cls):
+        """constructor to help legacy API to build a new "from_p2" item
+
+        Should eventually be removed
+        """
+        instance = cls()
+        instance._state = b'n'
+        instance._mode = 0
+        instance._size = FROM_P2
+        instance._mtime = AMBIGUOUS_TIME
+        return instance
+
+    @classmethod
+    def new_possibly_dirty(cls):
+        """constructor to help legacy API to build a new "possibly_dirty" item
+
+        Should eventually be removed
+        """
+        instance = cls()
+        instance._state = b'n'
+        instance._mode = 0
+        instance._size = NONNORMAL
+        instance._mtime = AMBIGUOUS_TIME
+        return instance
+
+    @classmethod
+    def new_normal(cls, mode, size, mtime):
+        """constructor to help legacy API to build a new "normal" item
+
+        Should eventually be removed
+        """
+        assert size != FROM_P2
+        assert size != NONNORMAL
+        instance = cls()
+        instance._state = b'n'
+        instance._mode = mode
+        instance._size = size
+        instance._mtime = mtime
+        return instance
+
+    @classmethod
     def from_v1_data(cls, state, mode, size, mtime):
         """Build a new DirstateItem object from V1 data