comparison mercurial/dirstate.py @ 5487:7a64931e2d76

Fix file-changed-to-dir and dir-to-file commits (issue660). Allow adding to dirstate files that clash with previously existing but marked for removal. Protect from reintroducing clashes by revert. This change doesn't address related issues with update. Current workaround is to do "clean" update by manually removing conflicting files/dirs from working directory.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 05 Nov 2007 20:05:44 +0300
parents 5105b119edd2
children f252ba975925
comparison
equal deleted inserted replaced
5486:48c22c719f8c 5487:7a64931e2d76
48 if err.errno != errno.ENOENT: raise 48 if err.errno != errno.ENOENT: raise
49 return self._pl 49 return self._pl
50 elif name == '_dirs': 50 elif name == '_dirs':
51 self._dirs = {} 51 self._dirs = {}
52 for f in self._map: 52 for f in self._map:
53 self._incpath(f) 53 if self[f] != 'r':
54 self._incpath(f)
54 return self._dirs 55 return self._dirs
55 elif name == '_ignore': 56 elif name == '_ignore':
56 files = [self._join('.hgignore')] 57 files = [self._join('.hgignore')]
57 for name, path in self._ui.configitems("ui"): 58 for name, path in self._ui.configitems("ui"):
58 if name == 'ignore' or name.startswith('ignore.'): 59 if name == 'ignore' or name.startswith('ignore.'):
203 raise util.Abort(_('directory %r already in dirstate') % f) 204 raise util.Abort(_('directory %r already in dirstate') % f)
204 for c in strutil.rfindall(f, '/'): 205 for c in strutil.rfindall(f, '/'):
205 d = f[:c] 206 d = f[:c]
206 if d in self._dirs: 207 if d in self._dirs:
207 break 208 break
208 if d in self._map: 209 if d in self._map and self[d] != 'r':
209 raise util.Abort(_('file %r in dirstate clashes with %r') % 210 raise util.Abort(_('file %r in dirstate clashes with %r') %
210 (d, f)) 211 (d, f))
211 self._incpath(f) 212 self._incpath(f)
212 213
214 def _changepath(self, f, newstate):
215 # handle upcoming path changes
216 oldstate = self[f]
217 if oldstate not in "?r" and newstate in "?r":
218 self._decpath(f)
219 return
220 if oldstate in "?r" and newstate not in "?r":
221 self._incpathcheck(f)
222 return
223
213 def normal(self, f): 224 def normal(self, f):
214 'mark a file normal and clean' 225 'mark a file normal and clean'
215 self._dirty = True 226 self._dirty = True
227 self._changepath(f, 'n')
216 s = os.lstat(self._join(f)) 228 s = os.lstat(self._join(f))
217 self._map[f] = ('n', s.st_mode, s.st_size, s.st_mtime, 0) 229 self._map[f] = ('n', s.st_mode, s.st_size, s.st_mtime, 0)
218 if self._copymap.has_key(f): 230 if self._copymap.has_key(f):
219 del self._copymap[f] 231 del self._copymap[f]
220 232
221 def normallookup(self, f): 233 def normallookup(self, f):
222 'mark a file normal, but possibly dirty' 234 'mark a file normal, but possibly dirty'
223 self._dirty = True 235 self._dirty = True
236 self._changepath(f, 'n')
224 self._map[f] = ('n', 0, -1, -1, 0) 237 self._map[f] = ('n', 0, -1, -1, 0)
225 if f in self._copymap: 238 if f in self._copymap:
226 del self._copymap[f] 239 del self._copymap[f]
227 240
228 def normaldirty(self, f): 241 def normaldirty(self, f):
229 'mark a file normal, but dirty' 242 'mark a file normal, but dirty'
230 self._dirty = True 243 self._dirty = True
244 self._changepath(f, 'n')
231 self._map[f] = ('n', 0, -2, -1, 0) 245 self._map[f] = ('n', 0, -2, -1, 0)
232 if f in self._copymap: 246 if f in self._copymap:
233 del self._copymap[f] 247 del self._copymap[f]
234 248
235 def add(self, f): 249 def add(self, f):
236 'mark a file added' 250 'mark a file added'
237 self._dirty = True 251 self._dirty = True
238 self._incpathcheck(f) 252 self._changepath(f, 'a')
239 self._map[f] = ('a', 0, -1, -1, 0) 253 self._map[f] = ('a', 0, -1, -1, 0)
240 if f in self._copymap: 254 if f in self._copymap:
241 del self._copymap[f] 255 del self._copymap[f]
242 256
243 def remove(self, f): 257 def remove(self, f):
244 'mark a file removed' 258 'mark a file removed'
245 self._dirty = True 259 self._dirty = True
260 self._changepath(f, 'r')
246 self._map[f] = ('r', 0, 0, 0, 0) 261 self._map[f] = ('r', 0, 0, 0, 0)
247 self._decpath(f)
248 if f in self._copymap: 262 if f in self._copymap:
249 del self._copymap[f] 263 del self._copymap[f]
250 264
251 def merge(self, f): 265 def merge(self, f):
252 'mark a file merged' 266 'mark a file merged'
253 self._dirty = True 267 self._dirty = True
254 s = os.lstat(self._join(f)) 268 s = os.lstat(self._join(f))
269 self._changepath(f, 'm')
255 self._map[f] = ('m', s.st_mode, s.st_size, s.st_mtime, 0) 270 self._map[f] = ('m', s.st_mode, s.st_size, s.st_mtime, 0)
256 if f in self._copymap: 271 if f in self._copymap:
257 del self._copymap[f] 272 del self._copymap[f]
258 273
259 def forget(self, f): 274 def forget(self, f):
260 'forget a file' 275 'forget a file'
261 self._dirty = True 276 self._dirty = True
262 try: 277 try:
278 self._changepath(f, '?')
263 del self._map[f] 279 del self._map[f]
264 self._decpath(f)
265 except KeyError: 280 except KeyError:
266 self._ui.warn(_("not in dirstate: %s!\n") % f) 281 self._ui.warn(_("not in dirstate: %s!\n") % f)
267 282
268 def clear(self): 283 def clear(self):
269 self._map = {} 284 self._map = {}
285 if "_dirs" in self.__dict__:
286 delattr(self, "_dirs");
270 self._copymap = {} 287 self._copymap = {}
271 self._pl = [nullid, nullid] 288 self._pl = [nullid, nullid]
272 self._dirty = True 289 self._dirty = True
273 290
274 def rebuild(self, parent, files): 291 def rebuild(self, parent, files):
520 nonexistent = True 537 nonexistent = True
521 if not st: 538 if not st:
522 try: 539 try:
523 st = lstat(_join(fn)) 540 st = lstat(_join(fn))
524 except OSError, inst: 541 except OSError, inst:
525 if inst.errno != errno.ENOENT: 542 if inst.errno not in (errno.ENOENT, errno.ENOTDIR):
526 raise 543 raise
527 st = None 544 st = None
528 # We need to re-check that it is a valid file 545 # We need to re-check that it is a valid file
529 if st and self._supported(fn, st.st_mode): 546 if st and self._supported(fn, st.st_mode):
530 nonexistent = False 547 nonexistent = False