comparison mercurial/util.py @ 13928:155d2e17884e

path_auditor: eliminate local function 'check' in __call__
author Adrian Buehlmann <adrian@cadifra.com>
date Mon, 11 Apr 2011 10:06:57 +0200
parents 61ba09d8d118
children 545091b12724
comparison
equal deleted inserted replaced
13927:518344d02761 13928:155d2e17884e
553 self.auditeddir = set() 553 self.auditeddir = set()
554 self.root = root 554 self.root = root
555 self.callback = callback 555 self.callback = callback
556 556
557 def __call__(self, path): 557 def __call__(self, path):
558 '''Check the relative path.
559 path may contain a pattern (e.g. foodir/**.txt)'''
560
558 if path in self.audited: 561 if path in self.audited:
559 return 562 return
560 # AIX ignores "/" at end of path, others raise EISDIR. 563 # AIX ignores "/" at end of path, others raise EISDIR.
561 if endswithsep(path): 564 if endswithsep(path):
562 raise Abort(_("path ends in directory separator: %s") % path) 565 raise Abort(_("path ends in directory separator: %s") % path)
572 if p in lparts[1:]: 575 if p in lparts[1:]:
573 pos = lparts.index(p) 576 pos = lparts.index(p)
574 base = os.path.join(*parts[:pos]) 577 base = os.path.join(*parts[:pos])
575 raise Abort(_('path %r is inside nested repo %r') 578 raise Abort(_('path %r is inside nested repo %r')
576 % (path, base)) 579 % (path, base))
577 def check(prefix): 580
581 parts.pop()
582 prefixes = []
583 while parts:
584 prefix = os.sep.join(parts)
585 if prefix in self.auditeddir:
586 break
578 curpath = os.path.join(self.root, prefix) 587 curpath = os.path.join(self.root, prefix)
579 try: 588 try:
580 st = os.lstat(curpath) 589 st = os.lstat(curpath)
581 except OSError, err: 590 except OSError, err:
582 # EINVAL can be raised as invalid path syntax under win32. 591 # EINVAL can be raised as invalid path syntax under win32.
590 elif (stat.S_ISDIR(st.st_mode) and 599 elif (stat.S_ISDIR(st.st_mode) and
591 os.path.isdir(os.path.join(curpath, '.hg'))): 600 os.path.isdir(os.path.join(curpath, '.hg'))):
592 if not self.callback or not self.callback(curpath): 601 if not self.callback or not self.callback(curpath):
593 raise Abort(_('path %r is inside nested repo %r') % 602 raise Abort(_('path %r is inside nested repo %r') %
594 (path, prefix)) 603 (path, prefix))
595 parts.pop()
596 prefixes = []
597 while parts:
598 prefix = os.sep.join(parts)
599 if prefix in self.auditeddir:
600 break
601 check(prefix)
602 prefixes.append(prefix) 604 prefixes.append(prefix)
603 parts.pop() 605 parts.pop()
604 606
605 self.audited.add(path) 607 self.audited.add(path)
606 # only add prefixes to the cache after checking everything: we don't 608 # only add prefixes to the cache after checking everything: we don't