mercurial/windows.py
changeset 52096 19ae7730636a
parent 51859 f4733654f144
parent 52020 e760a36a6013
child 52639 9db77d46de79
--- a/mercurial/windows.py	Thu Oct 24 15:23:52 2024 +0200
+++ b/mercurial/windows.py	Sat Oct 26 00:58:01 2024 +0200
@@ -19,6 +19,7 @@
 import winreg  # pytype: disable=import-error
 
 from typing import (
+    Any,
     AnyStr,
     BinaryIO,
     Iterable,
@@ -676,13 +677,38 @@
 
 
 class cachestat:
-    stat: Optional[os.stat_result]
+    stat: os.stat_result
 
     def __init__(self, path: bytes) -> None:
-        self.stat = None
+        self.stat = os.stat(path)
 
     def cacheable(self) -> bool:
-        return False
+        return bool(self.stat.st_ino)
+
+    __hash__ = object.__hash__
+
+    def __eq__(self, other: Any) -> bool:
+        try:
+            # Only dev, ino, size, mtime and atime are likely to change. Out
+            # of these, we shouldn't compare atime but should compare the
+            # rest. However, one of the other fields changing indicates
+            # something fishy going on, so return False if anything but atime
+            # changes.
+            return (
+                self.stat.st_ino == other.stat.st_ino
+                and self.stat.st_dev == other.stat.st_dev
+                and self.stat.st_nlink == other.stat.st_nlink
+                and self.stat.st_uid == other.stat.st_uid
+                and self.stat.st_gid == other.stat.st_gid
+                and self.stat.st_size == other.stat.st_size
+                and self.stat[stat.ST_MTIME] == other.stat[stat.ST_MTIME]
+                and self.stat[stat.ST_CTIME] == other.stat[stat.ST_CTIME]
+            )
+        except AttributeError:
+            return False
+
+    def __ne__(self, other: Any) -> bool:
+        return not self == other
 
 
 def lookupreg(