mercurial/pathutil.py
changeset 44865 233ee525dcef
parent 44626 11f284c8c5e4
child 45942 89a2afe31e82
--- a/mercurial/pathutil.py	Mon May 25 17:32:25 2020 -0400
+++ b/mercurial/pathutil.py	Mon May 25 17:39:23 2020 -0400
@@ -1,5 +1,6 @@
 from __future__ import absolute_import
 
+import contextlib
 import errno
 import os
 import posixpath
@@ -148,6 +149,19 @@
         except (OSError, error.Abort):
             return False
 
+    @contextlib.contextmanager
+    def cached(self):
+        if self._cached:
+            yield
+        else:
+            try:
+                self._cached = True
+                yield
+            finally:
+                self.audited.clear()
+                self.auditeddir.clear()
+                self._cached = False
+
 
 def canonpath(root, cwd, myname, auditor=None):
     '''return the canonical path of myname, given cwd and root