mercurial/dirstate.py
changeset 4617 70352337934e
parent 4616 9b00b73a5286
child 4621 d97fd22a0ea9
equal deleted inserted replaced
4616:9b00b73a5286 4617:70352337934e
   180         for c in strutil.findall(path, '/'):
   180         for c in strutil.findall(path, '/'):
   181             pc = path[:c]
   181             pc = path[:c]
   182             self._dirs.setdefault(pc, 0)
   182             self._dirs.setdefault(pc, 0)
   183             self._dirs[pc] -= 1
   183             self._dirs[pc] -= 1
   184 
   184 
   185     def checkinterfering(self, files):
   185     def _incpathcheck(self, f):
   186         def prefixes(f):
   186         if '\r' in f or '\n' in f:
   187             for c in strutil.rfindall(f, '/'):
   187             raise util.Abort(_("'\\n' and '\\r' disallowed in filenames"))
   188                 yield f[:c]
   188         # shadows
   189         seendirs = {}
   189         if f in self._dirs:
   190         for f in files:
   190             raise util.Abort(_('directory named %r already in dirstate') % f)
   191             # shadows
   191         for c in strutil.rfindall(f, '/'):
   192             if self._dirs.get(f):
   192             d = f[:c]
   193                 raise util.Abort(_('directory named %r already in dirstate') %
   193             if d in self._dirs:
   194                                  f)
   194                 break
   195             for d in prefixes(f):
   195             if d in self._map:
   196                 if d in seendirs:
   196                 raise util.Abort(_('file named %r already in dirstate') % d)
   197                     break
   197         self._incpath(f)
   198                 if d in self._map:
       
   199                     raise util.Abort(_('file named %r already in dirstate') %
       
   200                                      d)
       
   201                 seendirs[d] = True
       
   202             # disallowed
       
   203             if '\r' in f or '\n' in f:
       
   204                 raise util.Abort(_("'\\n' and '\\r' disallowed in filenames"))
       
   205 
   198 
   206     def update(self, files, state, **kw):
   199     def update(self, files, state, **kw):
   207         ''' current states:
   200         ''' current states:
   208         n  normal
   201         n  normal
   209         m  needs merging
   202         m  needs merging
   210         r  marked for removal
   203         r  marked for removal
   211         a  marked for addition'''
   204         a  marked for addition'''
   212 
   205 
   213         if not files: return
   206         if not files: return
   214         self.markdirty()
   207         self.markdirty()
   215         if state == "a":
       
   216             self.checkinterfering(files)
       
   217         for f in files:
   208         for f in files:
       
   209             if self._copymap.has_key(f):
       
   210                 del self._copymap[f]
       
   211 
   218             if state == "r":
   212             if state == "r":
   219                 self._map[f] = ('r', 0, 0, 0)
   213                 self._map[f] = ('r', 0, 0, 0)
   220                 self._decpath(f)
   214                 self._decpath(f)
       
   215                 continue
   221             else:
   216             else:
   222                 if state == "a":
   217                 if state == "a":
   223                     self._incpath(f)
   218                     self._incpathcheck(f)
   224                 s = os.lstat(self.wjoin(f))
   219                 s = os.lstat(self.wjoin(f))
   225                 st_size = kw.get('st_size', s.st_size)
   220                 st_size = kw.get('st_size', s.st_size)
   226                 st_mtime = kw.get('st_mtime', s.st_mtime)
   221                 st_mtime = kw.get('st_mtime', s.st_mtime)
   227                 self._map[f] = (state, s.st_mode, st_size, st_mtime)
   222                 self._map[f] = (state, s.st_mode, st_size, st_mtime)
   228             if self._copymap.has_key(f):
       
   229                 del self._copymap[f]
       
   230 
   223 
   231     def forget(self, files):
   224     def forget(self, files):
   232         if not files: return
   225         if not files: return
   233         self.markdirty()
   226         self.markdirty()
   234         for f in files:
   227         for f in files: