# HG changeset patch # User Pierre-Yves David # Date 1449174168 28800 # Node ID 6d29ce250a3d927659096c1176e2d3aec21b602b # Parent 9f8b8c4e5076e05d4ba46b37d9f8992617e2b384 pathauditor: move file system specific check in their own function This will make it easy to disable that part when not relevant (eg: auditing filename for operation in history) diff -r 9f8b8c4e5076 -r 6d29ce250a3d mercurial/pathutil.py --- a/mercurial/pathutil.py Sat Nov 07 16:31:04 2015 +0900 +++ b/mercurial/pathutil.py Thu Dec 03 12:22:48 2015 -0800 @@ -81,25 +81,7 @@ normprefix = os.sep.join(normparts) if normprefix in self.auditeddir: break - curpath = os.path.join(self.root, prefix) - try: - st = os.lstat(curpath) - except OSError as err: - # EINVAL can be raised as invalid path syntax under win32. - # They must be ignored for patterns can be checked too. - if err.errno not in (errno.ENOENT, errno.ENOTDIR, errno.EINVAL): - raise - else: - if stat.S_ISLNK(st.st_mode): - raise error.Abort( - _('path %r traverses symbolic link %r') - % (path, prefix)) - elif (stat.S_ISDIR(st.st_mode) and - os.path.isdir(os.path.join(curpath, '.hg'))): - if not self.callback or not self.callback(curpath): - raise error.Abort(_("path '%s' is inside nested " - "repo %r") - % (path, prefix)) + self._checkfs(prefix, path) prefixes.append(normprefix) parts.pop() normparts.pop() @@ -109,6 +91,27 @@ # want to add "foo/bar/baz" before checking if there's a "foo/.hg" self.auditeddir.update(prefixes) + def _checkfs(self, prefix, path): + """raise exception if a file system backed check fails""" + curpath = os.path.join(self.root, prefix) + try: + st = os.lstat(curpath) + except OSError as err: + # EINVAL can be raised as invalid path syntax under win32. + # They must be ignored for patterns can be checked too. + if err.errno not in (errno.ENOENT, errno.ENOTDIR, errno.EINVAL): + raise + else: + if stat.S_ISLNK(st.st_mode): + raise error.Abort( + _('path %r traverses symbolic link %r') + % (path, prefix)) + elif (stat.S_ISDIR(st.st_mode) and + os.path.isdir(os.path.join(curpath, '.hg'))): + if not self.callback or not self.callback(curpath): + raise error.Abort(_("path '%s' is inside nested " + "repo %r") % (path, prefix)) + def check(self, path): try: self(path)