Mercurial > hg
comparison mercurial/util.py @ 12079:41e56e07eef5
path_auditor: delegate checking of nested repos to a callback
author | Martin Geisler <mg@lazybytes.net> |
---|---|
date | Sun, 29 Aug 2010 23:56:19 +0200 |
parents | e03ca36ba9f3 |
children | dba2db7a7c28 |
comparison
equal
deleted
inserted
replaced
12078:e03ca36ba9f3 | 12079:41e56e07eef5 |
---|---|
490 | 490 |
491 - under top-level .hg | 491 - under top-level .hg |
492 - starts at the root of a windows drive | 492 - starts at the root of a windows drive |
493 - contains ".." | 493 - contains ".." |
494 - traverses a symlink (e.g. a/symlink_here/b) | 494 - traverses a symlink (e.g. a/symlink_here/b) |
495 - inside a nested repository''' | 495 - inside a nested repository (a callback can be used to approve |
496 | 496 some nested repositories, e.g., subrepositories) |
497 def __init__(self, root): | 497 ''' |
498 | |
499 def __init__(self, root, callback=None): | |
498 self.audited = set() | 500 self.audited = set() |
499 self.auditeddir = set() | 501 self.auditeddir = set() |
500 self.root = root | 502 self.root = root |
503 self.callback = callback | |
501 | 504 |
502 def __call__(self, path): | 505 def __call__(self, path): |
503 if path in self.audited: | 506 if path in self.audited: |
504 return | 507 return |
505 normpath = os.path.normcase(path) | 508 normpath = os.path.normcase(path) |
528 if stat.S_ISLNK(st.st_mode): | 531 if stat.S_ISLNK(st.st_mode): |
529 raise Abort(_('path %r traverses symbolic link %r') % | 532 raise Abort(_('path %r traverses symbolic link %r') % |
530 (path, prefix)) | 533 (path, prefix)) |
531 elif (stat.S_ISDIR(st.st_mode) and | 534 elif (stat.S_ISDIR(st.st_mode) and |
532 os.path.isdir(os.path.join(curpath, '.hg'))): | 535 os.path.isdir(os.path.join(curpath, '.hg'))): |
533 raise Abort(_('path %r is inside repo %r') % | 536 if not self.callback or not self.callback(curpath): |
534 (path, prefix)) | 537 raise Abort(_('path %r is inside repo %r') % |
538 (path, prefix)) | |
535 parts.pop() | 539 parts.pop() |
536 prefixes = [] | 540 prefixes = [] |
537 while parts: | 541 while parts: |
538 prefix = os.sep.join(parts) | 542 prefix = os.sep.join(parts) |
539 if prefix in self.auditeddir: | 543 if prefix in self.auditeddir: |