comparison 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
comparison
equal deleted inserted replaced
47904:822c67420c77 47905:c0d6a59a7704
117 self._mtime = parentfiledata[2] 117 self._mtime = parentfiledata[2]
118 else: 118 else:
119 assert False, 'unreachable' 119 assert False, 'unreachable'
120 120
121 @classmethod 121 @classmethod
122 def new_added(cls):
123 """constructor to help legacy API to build a new "added" item
124
125 Should eventually be removed
126 """
127 instance = cls()
128 instance._state = b'a'
129 instance._mode = 0
130 instance._size = NONNORMAL
131 instance._mtime = AMBIGUOUS_TIME
132 return instance
133
134 @classmethod
135 def new_merged(cls):
136 """constructor to help legacy API to build a new "merged" item
137
138 Should eventually be removed
139 """
140 instance = cls()
141 instance._state = b'm'
142 instance._mode = 0
143 instance._size = FROM_P2
144 instance._mtime = AMBIGUOUS_TIME
145 return instance
146
147 @classmethod
148 def new_from_p2(cls):
149 """constructor to help legacy API to build a new "from_p2" item
150
151 Should eventually be removed
152 """
153 instance = cls()
154 instance._state = b'n'
155 instance._mode = 0
156 instance._size = FROM_P2
157 instance._mtime = AMBIGUOUS_TIME
158 return instance
159
160 @classmethod
161 def new_possibly_dirty(cls):
162 """constructor to help legacy API to build a new "possibly_dirty" item
163
164 Should eventually be removed
165 """
166 instance = cls()
167 instance._state = b'n'
168 instance._mode = 0
169 instance._size = NONNORMAL
170 instance._mtime = AMBIGUOUS_TIME
171 return instance
172
173 @classmethod
174 def new_normal(cls, mode, size, mtime):
175 """constructor to help legacy API to build a new "normal" item
176
177 Should eventually be removed
178 """
179 assert size != FROM_P2
180 assert size != NONNORMAL
181 instance = cls()
182 instance._state = b'n'
183 instance._mode = mode
184 instance._size = size
185 instance._mtime = mtime
186 return instance
187
188 @classmethod
122 def from_v1_data(cls, state, mode, size, mtime): 189 def from_v1_data(cls, state, mode, size, mtime):
123 """Build a new DirstateItem object from V1 data 190 """Build a new DirstateItem object from V1 data
124 191
125 Since the dirstate-v1 format is frozen, the signature of this function 192 Since the dirstate-v1 format is frozen, the signature of this function
126 is not expected to change, unlike the __init__ one. 193 is not expected to change, unlike the __init__ one.