diff mercurial/dirstatemap.py @ 50128:2f60cd6442fd

dirstate: only reload the dirstate when it may have changed This reinstall the equivalent of what the `filecache` was doing. However it does it at the dirstate level. There is a double motivation for this: - This avoid duplicating logic with the dirstate "identity" logic. - This increase the lifetime of the `dirstate` object, helping to implement change scoping.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 22 Feb 2023 01:08:25 +0100
parents 85746485a4dd
children a6b8b1ab9116
line wrap: on
line diff
--- a/mercurial/dirstatemap.py	Wed Feb 22 01:04:55 2023 +0100
+++ b/mercurial/dirstatemap.py	Wed Feb 22 01:08:25 2023 +0100
@@ -67,6 +67,25 @@
         except FileNotFoundError:
             return None
 
+    def may_need_refresh(self):
+        if 'identity' not in vars(self):
+            # no existing identity, we need a refresh
+            return True
+        if self.identity is None:
+            return True
+        if not self.identity.cacheable():
+            # We cannot trust the entry
+            # XXX this is a problem on windows, NFS, or other inode less system
+            return True
+        current_identity = self._get_current_identity()
+        if current_identity is None:
+            return True
+        if not current_identity.cacheable():
+            # We cannot trust the entry
+            # XXX this is a problem on windows, NFS, or other inode less system
+            return True
+        return current_identity != self.identity
+
     def preload(self):
         """Loads the underlying data, if it's not already loaded"""
         self._map