mercurial/dirstate.py
changeset 35081 a947cf872799
parent 35080 19b75779b7c3
child 35082 e6c64744781f
equal deleted inserted replaced
35080:19b75779b7c3 35081:a947cf872799
   385 
   385 
   386     def copies(self):
   386     def copies(self):
   387         return self._map.copymap
   387         return self._map.copymap
   388 
   388 
   389     def _droppath(self, f):
   389     def _droppath(self, f):
   390         if self[f] not in "?r" and "dirs" in self._map.__dict__:
       
   391             self._map.dirs.delpath(f)
       
   392 
       
   393         if "filefoldmap" in self._map.__dict__:
   390         if "filefoldmap" in self._map.__dict__:
   394             normed = util.normcase(f)
   391             normed = util.normcase(f)
   395             if normed in self._map.filefoldmap:
   392             if normed in self._map.filefoldmap:
   396                 del self._map.filefoldmap[normed]
   393                 del self._map.filefoldmap[normed]
   397 
   394 
   409                     break
   406                     break
   410                 entry = self._map.get(d)
   407                 entry = self._map.get(d)
   411                 if entry is not None and entry[0] != 'r':
   408                 if entry is not None and entry[0] != 'r':
   412                     raise error.Abort(
   409                     raise error.Abort(
   413                         _('file %r in dirstate clashes with %r') % (d, f))
   410                         _('file %r in dirstate clashes with %r') % (d, f))
   414         if oldstate in "?r" and "dirs" in self._map.__dict__:
       
   415             self._map.dirs.addpath(f)
       
   416         self._dirty = True
   411         self._dirty = True
   417         self._updatedfiles.add(f)
   412         self._updatedfiles.add(f)
   418         self._map.addfile(f, state, mode, size, mtime)
   413         self._map.addfile(f, oldstate, state, mode, size, mtime)
   419 
   414 
   420     def normal(self, f):
   415     def normal(self, f):
   421         '''Mark a file normal and clean.'''
   416         '''Mark a file normal and clean.'''
   422         s = os.lstat(self._join(f))
   417         s = os.lstat(self._join(f))
   423         mtime = s.st_mtime
   418         mtime = s.st_mtime
   474 
   469 
   475     def remove(self, f):
   470     def remove(self, f):
   476         '''Mark a file removed.'''
   471         '''Mark a file removed.'''
   477         self._dirty = True
   472         self._dirty = True
   478         self._droppath(f)
   473         self._droppath(f)
       
   474         oldstate = self[f]
   479         size = 0
   475         size = 0
   480         if self._pl[1] != nullid:
   476         if self._pl[1] != nullid:
   481             entry = self._map.get(f)
   477             entry = self._map.get(f)
   482             if entry is not None:
   478             if entry is not None:
   483                 # backup the previous state
   479                 # backup the previous state
   484                 if entry[0] == 'm': # merge
   480                 if entry[0] == 'm': # merge
   485                     size = -1
   481                     size = -1
   486                 elif entry[0] == 'n' and entry[2] == -2: # other parent
   482                 elif entry[0] == 'n' and entry[2] == -2: # other parent
   487                     size = -2
   483                     size = -2
   488                     self._map.otherparentset.add(f)
   484                     self._map.otherparentset.add(f)
   489         self._map.removefile(f, size)
   485         self._map.removefile(f, oldstate, size)
   490         if size == 0:
   486         if size == 0:
   491             self._map.copymap.pop(f, None)
   487             self._map.copymap.pop(f, None)
   492 
   488 
   493     def merge(self, f):
   489     def merge(self, f):
   494         '''Mark a file merged.'''
   490         '''Mark a file merged.'''
   496             return self.normallookup(f)
   492             return self.normallookup(f)
   497         return self.otherparent(f)
   493         return self.otherparent(f)
   498 
   494 
   499     def drop(self, f):
   495     def drop(self, f):
   500         '''Drop a file from the dirstate'''
   496         '''Drop a file from the dirstate'''
   501         if self._map.dropfile(f):
   497         oldstate = self[f]
       
   498         if self._map.dropfile(f, oldstate):
   502             self._dirty = True
   499             self._dirty = True
   503             self._droppath(f)
   500             self._droppath(f)
   504             self._map.copymap.pop(f, None)
   501             self._map.copymap.pop(f, None)
   505 
   502 
   506     def _discoverpath(self, path, normed, ignoremissing, exists, storemap):
   503     def _discoverpath(self, path, normed, ignoremissing, exists, storemap):
  1215       form that they appear as in the dirstate.
  1212       form that they appear as in the dirstate.
  1216 
  1213 
  1217     - `dirfoldmap` is a dict mapping normalized directory names to the
  1214     - `dirfoldmap` is a dict mapping normalized directory names to the
  1218       denormalized form that they appear as in the dirstate.
  1215       denormalized form that they appear as in the dirstate.
  1219 
  1216 
  1220     Once instantiated, the dirs, filefoldmap and dirfoldmap views must be
  1217     Once instantiated, the filefoldmap and dirfoldmap views must be maintained
  1221     maintained by the caller.
  1218     by the caller.
  1222     """
  1219     """
  1223 
  1220 
  1224     def __init__(self, ui, opener, root):
  1221     def __init__(self, ui, opener, root):
  1225         self._ui = ui
  1222         self._ui = ui
  1226         self._opener = opener
  1223         self._opener = opener
  1278 
  1275 
  1279     def preload(self):
  1276     def preload(self):
  1280         """Loads the underlying data, if it's not already loaded"""
  1277         """Loads the underlying data, if it's not already loaded"""
  1281         self._map
  1278         self._map
  1282 
  1279 
  1283     def addfile(self, f, state, mode, size, mtime):
  1280     def addfile(self, f, oldstate, state, mode, size, mtime):
  1284         """Add a tracked file to the dirstate."""
  1281         """Add a tracked file to the dirstate."""
       
  1282         if oldstate in "?r" and "dirs" in self.__dict__:
       
  1283             self.dirs.addpath(f)
  1285         self._map[f] = dirstatetuple(state, mode, size, mtime)
  1284         self._map[f] = dirstatetuple(state, mode, size, mtime)
  1286         if state != 'n' or mtime == -1:
  1285         if state != 'n' or mtime == -1:
  1287             self.nonnormalset.add(f)
  1286             self.nonnormalset.add(f)
  1288         if size == -2:
  1287         if size == -2:
  1289             self.otherparentset.add(f)
  1288             self.otherparentset.add(f)
  1290 
  1289 
  1291     def removefile(self, f, size):
  1290     def removefile(self, f, oldstate, size):
  1292         """
  1291         """
  1293         Mark a file as removed in the dirstate.
  1292         Mark a file as removed in the dirstate.
  1294 
  1293 
  1295         The `size` parameter is used to store sentinel values that indicate
  1294         The `size` parameter is used to store sentinel values that indicate
  1296         the file's previous state.  In the future, we should refactor this
  1295         the file's previous state.  In the future, we should refactor this
  1297         to be more explicit about what that state is.
  1296         to be more explicit about what that state is.
  1298         """
  1297         """
       
  1298         if oldstate not in "?r" and "dirs" in self.__dict__:
       
  1299             self.dirs.delpath(f)
  1299         self._map[f] = dirstatetuple('r', 0, size, 0)
  1300         self._map[f] = dirstatetuple('r', 0, size, 0)
  1300         self.nonnormalset.add(f)
  1301         self.nonnormalset.add(f)
  1301 
  1302 
  1302     def dropfile(self, f):
  1303     def dropfile(self, f, oldstate):
  1303         """
  1304         """
  1304         Remove a file from the dirstate.  Returns True if the file was
  1305         Remove a file from the dirstate.  Returns True if the file was
  1305         previously recorded.
  1306         previously recorded.
  1306         """
  1307         """
  1307         exists = self._map.pop(f, None) is not None
  1308         exists = self._map.pop(f, None) is not None
       
  1309         if exists:
       
  1310             if oldstate != "r" and "dirs" in self.__dict__:
       
  1311                 self.dirs.delpath(f)
  1308         self.nonnormalset.discard(f)
  1312         self.nonnormalset.discard(f)
  1309         return exists
  1313         return exists
  1310 
  1314 
  1311     def clearambiguoustimes(self, files, now):
  1315     def clearambiguoustimes(self, files, now):
  1312         for f in files:
  1316         for f in files: