diff mercurial/vfs.py @ 49909:b7cf91ef03ba

merge: skip syntactic path checks in [_checkunknownfile] We don't need to check the paths syntactically, since they are coming from diffing the revisions, so hopefully already checked on the way in. We still need to check what's on the filesystem, to avoid traversing the symlinks or subdirs, which we can't know about statically. Also, we use the directory audit to elide [isfileorlink], this removing ~all lstat calls from hg updates from-empty.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Fri, 06 Jan 2023 18:09:19 +0000
parents 2506c3ac73f4
children bc83ebe07bf0
line wrap: on
line diff
--- a/mercurial/vfs.py	Fri Jan 06 16:42:24 2023 +0000
+++ b/mercurial/vfs.py	Fri Jan 06 18:09:19 2023 +0000
@@ -422,6 +422,25 @@
                 raise error.Abort(b"%s: %r" % (r, path))
             self.audit(path, mode=mode)
 
+    def isfileorlink_checkdir(
+        self, dircache, path: Optional[bytes] = None
+    ) -> bool:
+        """return True if the path is a regular file or a symlink and
+        the directories along the path are "normal", that is
+        not symlinks or nested hg repositories."""
+        try:
+            for prefix in pathutil.finddirs_rev_noroot(util.localpath(path)):
+                if prefix in dircache:
+                    res = dircache[prefix]
+                else:
+                    res = self.audit._checkfs_exists(prefix, path)
+                    dircache[prefix] = res
+                if not res:
+                    return False
+        except (OSError, error.Abort):
+            return False
+        return self.isfileorlink(path)
+
     def __call__(
         self,
         path: bytes,