Mercurial > hg
diff mercurial/pathutil.py @ 49912:bc83ebe07bf0
pathauditor: make _checkfs_exists a static method
This fixes the bug detected by pytype where the auditor
used in vfs.py may be a no-op auditor (vfs.py, line 398),
which doesn't have the _checkfs_exists method.
author | Arseniy Alekseyev <aalekseyev@janestreet.com> |
---|---|
date | Thu, 12 Jan 2023 16:15:51 +0000 |
parents | 789e152a6bdb |
children | d718eddf01d9 |
line wrap: on
line diff
--- a/mercurial/pathutil.py Thu Jan 12 13:14:00 2023 +0000 +++ b/mercurial/pathutil.py Thu Jan 12 16:15:51 2023 +0000 @@ -116,7 +116,9 @@ if prefix in self.auditeddir: res = self.auditeddir[prefix] else: - res = self._checkfs_exists(prefix, path) + res = pathauditor._checkfs_exists( + self.root, prefix, path, self.callback + ) if self._cached: self.auditeddir[prefix] = res if not res: @@ -125,11 +127,17 @@ if self._cached: self.audited.add(path) - def _checkfs_exists(self, prefix: bytes, path: bytes) -> bool: + @staticmethod + def _checkfs_exists( + root, + prefix: bytes, + path: bytes, + callback: Optional[Callable[[bytes], bool]] = None, + ): """raise exception if a file system backed check fails. Return a bool that indicates that the directory (or file) exists.""" - curpath = os.path.join(self.root, prefix) + curpath = os.path.join(root, prefix) try: st = os.lstat(curpath) except OSError as err: @@ -149,7 +157,7 @@ elif stat.S_ISDIR(st.st_mode) and os.path.isdir( os.path.join(curpath, b'.hg') ): - if not self.callback or not self.callback(curpath): + if not callback or not callback(curpath): msg = _(b"path '%s' is inside nested repo %r") raise error.Abort(msg % (path, pycompat.bytestr(prefix))) return True