comparison mercurial/dirstatemap.py @ 47511:eaae39894312

dirstate: move most of the `remove` logic with dirstatemap `removefile` This code deal with special logic to preserving "merged" and "from_p2" information when removing a file. These are implementation details that are more suitable for the dirstatemap layer. Since the dirstatemap layer alreaday have most of the information necessary to do so, the move is easy. This move helps us to encapsulate more implementation details within the dirstatemap and its entry. Easing the use of a different storage for dirstate v2. Differential Revision: https://phab.mercurial-scm.org/D10953
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 03 Jul 2021 19:52:00 +0200
parents 8b7e47802deb
children 10e740292dff
comparison
equal deleted inserted replaced
47510:94c58f3aab56 47511:eaae39894312
152 if state != b'n' or mtime == AMBIGUOUS_TIME: 152 if state != b'n' or mtime == AMBIGUOUS_TIME:
153 self.nonnormalset.add(f) 153 self.nonnormalset.add(f)
154 if size == FROM_P2: 154 if size == FROM_P2:
155 self.otherparentset.add(f) 155 self.otherparentset.add(f)
156 156
157 def removefile(self, f, oldstate, size): 157 def removefile(self, f, in_merge=False):
158 """ 158 """
159 Mark a file as removed in the dirstate. 159 Mark a file as removed in the dirstate.
160 160
161 The `size` parameter is used to store sentinel values that indicate 161 The `size` parameter is used to store sentinel values that indicate
162 the file's previous state. In the future, we should refactor this 162 the file's previous state. In the future, we should refactor this
163 to be more explicit about what that state is. 163 to be more explicit about what that state is.
164 """ 164 """
165 if oldstate not in b"?r" and "_dirs" in self.__dict__: 165 entry = self.get(f)
166 size = 0
167 if in_merge:
168 # XXX we should not be able to have 'm' state and 'FROM_P2' if not
169 # during a merge. So I (marmoute) am not sure we need the
170 # conditionnal at all. Adding double checking this with assert
171 # would be nice.
172 if entry is not None:
173 # backup the previous state
174 if entry[0] == b'm': # merge
175 size = NONNORMAL
176 elif entry[0] == b'n' and entry[2] == FROM_P2: # other parent
177 size = FROM_P2
178 self.otherparentset.add(f)
179 if size == 0:
180 self.copymap.pop(f, None)
181
182 if entry is not None and entry[0] != b'r' and "_dirs" in self.__dict__:
166 self._dirs.delpath(f) 183 self._dirs.delpath(f)
167 if oldstate == b"?" and "_alldirs" in self.__dict__: 184 if entry is None and "_alldirs" in self.__dict__:
168 self._alldirs.addpath(f) 185 self._alldirs.addpath(f)
169 if "filefoldmap" in self.__dict__: 186 if "filefoldmap" in self.__dict__:
170 normed = util.normcase(f) 187 normed = util.normcase(f)
171 self.filefoldmap.pop(normed, None) 188 self.filefoldmap.pop(normed, None)
172 self._map[f] = dirstatetuple(b'r', 0, size, 0) 189 self._map[f] = dirstatetuple(b'r', 0, size, 0)