comparison mercurial/dirstate.py @ 17094:c2016bae3b97

dirstate: factor common update code into _addpath Factor update code common to all callers of _addpath into _addpath. By centralizing the update code here, it provides one place to put updates to new data structures - in a future patch. It also removes a few lines of duplicate code.
author Joshua Redstone <joshua.redstone@fb.com>
date Mon, 18 Jun 2012 08:06:42 -0700
parents 92e1c64ba0d4
children 2abe975ffb94
comparison
equal deleted inserted replaced
17093:cd8e109b673b 17094:c2016bae3b97
310 310
311 def _droppath(self, f): 311 def _droppath(self, f):
312 if self[f] not in "?r" and "_dirs" in self.__dict__: 312 if self[f] not in "?r" and "_dirs" in self.__dict__:
313 _decdirs(self._dirs, f) 313 _decdirs(self._dirs, f)
314 314
315 def _addpath(self, f, check=False): 315 def _addpath(self, f, state, mode, size, mtime, check=False):
316 assert state not in "?r"
316 oldstate = self[f] 317 oldstate = self[f]
317 if check or oldstate == "r": 318 if check or oldstate == "r":
318 scmutil.checkfilename(f) 319 scmutil.checkfilename(f)
319 if f in self._dirs: 320 if f in self._dirs:
320 raise util.Abort(_('directory %r already in dirstate') % f) 321 raise util.Abort(_('directory %r already in dirstate') % f)
325 if d in self._map and self[d] != 'r': 326 if d in self._map and self[d] != 'r':
326 raise util.Abort( 327 raise util.Abort(
327 _('file %r in dirstate clashes with %r') % (d, f)) 328 _('file %r in dirstate clashes with %r') % (d, f))
328 if oldstate in "?r" and "_dirs" in self.__dict__: 329 if oldstate in "?r" and "_dirs" in self.__dict__:
329 _incdirs(self._dirs, f) 330 _incdirs(self._dirs, f)
331 self._dirty = True
332 self._map[f] = (state, mode, size, mtime)
330 333
331 def normal(self, f): 334 def normal(self, f):
332 '''Mark a file normal and clean.''' 335 '''Mark a file normal and clean.'''
333 self._dirty = True
334 self._addpath(f)
335 s = os.lstat(self._join(f)) 336 s = os.lstat(self._join(f))
336 mtime = int(s.st_mtime) 337 mtime = int(s.st_mtime)
337 self._map[f] = ('n', s.st_mode, s.st_size, mtime) 338 self._addpath(f, 'n', s.st_mode, s.st_size, mtime)
338 if f in self._copymap: 339 if f in self._copymap:
339 del self._copymap[f] 340 del self._copymap[f]
340 if mtime > self._lastnormaltime: 341 if mtime > self._lastnormaltime:
341 # Remember the most recent modification timeslot for status(), 342 # Remember the most recent modification timeslot for status(),
342 # to make sure we won't miss future size-preserving file content 343 # to make sure we won't miss future size-preserving file content
359 if source: 360 if source:
360 self.copy(source, f) 361 self.copy(source, f)
361 return 362 return
362 if entry[0] == 'm' or entry[0] == 'n' and entry[2] == -2: 363 if entry[0] == 'm' or entry[0] == 'n' and entry[2] == -2:
363 return 364 return
364 self._dirty = True 365 self._addpath(f, 'n', 0, -1, -1)
365 self._addpath(f)
366 self._map[f] = ('n', 0, -1, -1)
367 if f in self._copymap: 366 if f in self._copymap:
368 del self._copymap[f] 367 del self._copymap[f]
369 368
370 def otherparent(self, f): 369 def otherparent(self, f):
371 '''Mark as coming from the other parent, always dirty.''' 370 '''Mark as coming from the other parent, always dirty.'''
372 if self._pl[1] == nullid: 371 if self._pl[1] == nullid:
373 raise util.Abort(_("setting %r to other parent " 372 raise util.Abort(_("setting %r to other parent "
374 "only allowed in merges") % f) 373 "only allowed in merges") % f)
375 self._dirty = True 374 self._addpath(f, 'n', 0, -2, -1)
376 self._addpath(f)
377 self._map[f] = ('n', 0, -2, -1)
378 if f in self._copymap: 375 if f in self._copymap:
379 del self._copymap[f] 376 del self._copymap[f]
380 377
381 def add(self, f): 378 def add(self, f):
382 '''Mark a file added.''' 379 '''Mark a file added.'''
383 self._dirty = True 380 self._addpath(f, 'a', 0, -1, -1, True)
384 self._addpath(f, True)
385 self._map[f] = ('a', 0, -1, -1)
386 if f in self._copymap: 381 if f in self._copymap:
387 del self._copymap[f] 382 del self._copymap[f]
388 383
389 def remove(self, f): 384 def remove(self, f):
390 '''Mark a file removed.''' 385 '''Mark a file removed.'''
404 399
405 def merge(self, f): 400 def merge(self, f):
406 '''Mark a file merged.''' 401 '''Mark a file merged.'''
407 if self._pl[1] == nullid: 402 if self._pl[1] == nullid:
408 return self.normallookup(f) 403 return self.normallookup(f)
409 self._dirty = True
410 s = os.lstat(self._join(f)) 404 s = os.lstat(self._join(f))
411 self._addpath(f) 405 self._addpath(f, 'm', s.st_mode, s.st_size, int(s.st_mtime))
412 self._map[f] = ('m', s.st_mode, s.st_size, int(s.st_mtime))
413 if f in self._copymap: 406 if f in self._copymap:
414 del self._copymap[f] 407 del self._copymap[f]
415 408
416 def drop(self, f): 409 def drop(self, f):
417 '''Drop a file from the dirstate''' 410 '''Drop a file from the dirstate'''