mercurial/dirstate.py
changeset 1392 32d8068b3e36
parent 1276 25e5b1086624
child 1394 b20b683e8d95
equal deleted inserted replaced
1391:9395c2f94130 1392:32d8068b3e36
   266     #
   266     #
   267     # dc is an optional arg for the current dirstate.  dc is not modified
   267     # dc is an optional arg for the current dirstate.  dc is not modified
   268     # directly by this function, but might be modified by your statmatch call.
   268     # directly by this function, but might be modified by your statmatch call.
   269     #
   269     #
   270     def walkhelper(self, files, statmatch, dc):
   270     def walkhelper(self, files, statmatch, dc):
       
   271         def supported_type(f, st):
       
   272             if stat.S_ISREG(st.st_mode):
       
   273                 return True
       
   274             else:
       
   275                 kind = 'unknown'
       
   276                 if stat.S_ISCHR(st.st_mode): kind = 'character device'
       
   277                 elif stat.S_ISBLK(st.st_mode): kind = 'block device'
       
   278                 elif stat.S_ISFIFO(st.st_mode): kind = 'fifo'
       
   279                 elif stat.S_ISLNK(st.st_mode): kind = 'symbolic link'
       
   280                 elif stat.S_ISSOCK(st.st_mode): kind = 'socket'
       
   281                 elif stat.S_ISDIR(st.st_mode): kind = 'directory'
       
   282                 self.ui.warn('%s: unsupported file type (type is %s)\n' % (
       
   283                     util.pathto(self.getcwd(), f),
       
   284                     kind))
       
   285                 return False
       
   286 
   271         # recursion free walker, faster than os.walk.
   287         # recursion free walker, faster than os.walk.
   272         def findfiles(s):
   288         def findfiles(s):
   273             retfiles = []
   289             retfiles = []
   274             work = [s]
   290             work = [s]
   275             while work:
   291             while work:
   288                     st = os.lstat(p)
   304                     st = os.lstat(p)
   289                     if stat.S_ISDIR(st.st_mode):
   305                     if stat.S_ISDIR(st.st_mode):
   290                         ds = os.path.join(nd, f +'/')
   306                         ds = os.path.join(nd, f +'/')
   291                         if statmatch(ds, st):
   307                         if statmatch(ds, st):
   292                             work.append(p)
   308                             work.append(p)
   293                     else:
   309                     elif supported_type(np, st):
   294                         if statmatch(np, st):
   310                         if statmatch(np, st):
   295                             yield util.pconvert(np)
   311                             yield util.pconvert(np)
       
   312 
   296 
   313 
   297         known = {'.hg': 1}
   314         known = {'.hg': 1}
   298         def seen(fn):
   315         def seen(fn):
   299             if fn in known: return True
   316             if fn in known: return True
   300             known[fn] = 1
   317             known[fn] = 1
   313             if stat.S_ISDIR(st.st_mode):
   330             if stat.S_ISDIR(st.st_mode):
   314                 sorted = [ x for x in findfiles(f) ]
   331                 sorted = [ x for x in findfiles(f) ]
   315                 sorted.sort()
   332                 sorted.sort()
   316                 for fl in sorted:
   333                 for fl in sorted:
   317                     yield 'f', fl
   334                     yield 'f', fl
   318             elif stat.S_ISREG(st.st_mode):
   335             else:
   319                 ff = util.normpath(ff)
   336                 ff = util.normpath(ff)
   320                 if seen(ff):
   337                 if seen(ff):
   321                     continue
   338                     continue
   322                 found = False
   339                 found = False
   323                 self.blockignore = True
   340                 self.blockignore = True
   324                 if statmatch(ff, st):
   341                 if supported_type(ff, st) and statmatch(ff, st):
   325                     found = True
   342                     found = True
   326                 self.blockignore = False
   343                 self.blockignore = False
   327                 if found:
   344                 if found:
   328                     yield 'f', ff
   345                     yield 'f', ff
   329             else:
       
   330                 kind = 'unknown'
       
   331                 if stat.S_ISCHR(st.st_mode): kind = 'character device'
       
   332                 elif stat.S_ISBLK(st.st_mode): kind = 'block device'
       
   333                 elif stat.S_ISFIFO(st.st_mode): kind = 'fifo'
       
   334                 elif stat.S_ISLNK(st.st_mode): kind = 'symbolic link'
       
   335                 elif stat.S_ISSOCK(st.st_mode): kind = 'socket'
       
   336                 self.ui.warn('%s: unsupported file type (type is %s)\n' % (
       
   337                     util.pathto(self.getcwd(), ff),
       
   338                     kind))
       
   339 
   346 
   340         # step two run through anything left in the dc hash and yield
   347         # step two run through anything left in the dc hash and yield
   341         # if we haven't already seen it
   348         # if we haven't already seen it
   342         ks = dc.keys()
   349         ks = dc.keys()
   343         ks.sort()
   350         ks.sort()
   366 
   373 
   367             if not s or stat.S_ISDIR(s.st_mode):
   374             if not s or stat.S_ISDIR(s.st_mode):
   368                 if self.ignore(fn): return False
   375                 if self.ignore(fn): return False
   369                 return match(fn)
   376                 return match(fn)
   370 
   377 
   371             if not stat.S_ISREG(s.st_mode):
       
   372                 return False
       
   373             c = dc.pop(fn, None)
   378             c = dc.pop(fn, None)
   374             if c:
   379             if c:
   375                 type, mode, size, time = c
   380                 type, mode, size, time = c
   376                 # check the common case first
   381                 # check the common case first
   377                 if type == 'n':
   382                 if type == 'n':