cachestat: avoid creating cachestat for http path
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sat, 26 Oct 2024 01:38:20 +0200
changeset 52102 82e2c99c84f3
parent 52101 720d9849dcf9
child 52103 97840154eee3
cachestat: avoid creating cachestat for http path The statichttprepo repo attemp to create cachestat for content we access through http. We modify the couple of place create cachestat object to detect this situation and avoids it. This is not marvelous, but there is few of them and the freeze is looming. This helps on Windows where calling cachestat on http path might create issues.
mercurial/dirstatemap.py
mercurial/scmutil.py
mercurial/typelib.py
mercurial/util.py
--- a/mercurial/dirstatemap.py	Sat Oct 26 02:03:54 2024 +0200
+++ b/mercurial/dirstatemap.py	Sat Oct 26 01:38:20 2024 +0200
@@ -113,8 +113,12 @@
         self.identity = self._get_current_identity()
 
     def _get_current_identity(self) -> Optional[typelib.CacheStat]:
+        # TODO have a cleaner approach on httpstaticrepo side
+        path = self._opener.join(self._filename)
+        if path.startswith(b'https://') or path.startswith(b'http://'):
+            return util.uncacheable_cachestat()
         try:
-            return util.cachestat(self._opener.join(self._filename))
+            return util.cachestat(path)
         except FileNotFoundError:
             return None
 
--- a/mercurial/scmutil.py	Sat Oct 26 02:03:54 2024 +0200
+++ b/mercurial/scmutil.py	Sat Oct 26 01:38:20 2024 +0200
@@ -1764,10 +1764,13 @@
 
     @staticmethod
     def stat(path: bytes) -> Optional[typelib.CacheStat]:
+        # TODO have a cleaner approach on httpstaticrepo side
+        if path.startswith(b'https://') or path.startswith(b'http://'):
+            return util.uncacheable_cachestat()
         try:
             return util.cachestat(path)
         except FileNotFoundError:
-            pass
+            return None
 
 
 class filecacheentry:
--- a/mercurial/typelib.py	Sat Oct 26 02:03:54 2024 +0200
+++ b/mercurial/typelib.py	Sat Oct 26 01:38:20 2024 +0200
@@ -33,11 +33,16 @@
     from . import (
         node,
         posix,
+        util,
         windows,
     )
 
     BinaryIO_Proxy = BinaryIO
-    CacheStat = Union[posix.cachestat, windows.cachestat]
+    CacheStat = Union[
+        posix.cachestat,
+        windows.cachestat,
+        util.uncacheable_cachestat,
+    ]
     NodeConstants = node.sha1nodeconstants
 else:
     from typing import Any
--- a/mercurial/util.py	Sat Oct 26 02:03:54 2024 +0200
+++ b/mercurial/util.py	Sat Oct 26 01:38:20 2024 +0200
@@ -514,6 +514,16 @@
         raise
 
 
+class uncacheable_cachestat:
+    stat: Optional[os.stat_result]
+
+    def __init__(self) -> None:
+        self.stat = None
+
+    def cacheable(self) -> bool:
+        return False
+
+
 class fileobjectproxy:
     """A proxy around file objects that tells a watcher when events occur.