dirstate: factor the identity setting code in the dirstate map stable
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 21 Feb 2023 15:10:12 +0100
branchstable
changeset 50241 342c3c4640b7
parent 50240 3ddff85fa2c8
child 50242 379a78001d8e
dirstate: factor the identity setting code in the dirstate map We need it in more locations, so let us start factoring thing out first to make sure the same code is called everywhere. This bears some similarity with 85746485a4dd on default, but at a smaller scope and for a different purpose.
mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py	Wed Mar 01 00:07:26 2023 +0100
+++ b/mercurial/dirstatemap.py	Tue Feb 21 15:10:12 2023 +0100
@@ -76,6 +76,11 @@
         # for consistent view between _pl() and _read() invocations
         self._pendingmode = None
 
+    def _set_identity(self):
+        # ignore HG_PENDING because identity is used only for writing
+        file_path = self._opener.join(self._filename)
+        self.identity = util.filestat.frompath(file_path)
+
     def preload(self):
         """Loads the underlying data, if it's not already loaded"""
         self._map
@@ -295,9 +300,7 @@
 
     def read(self):
         # ignore HG_PENDING because identity is used only for writing
-        self.identity = util.filestat.frompath(
-            self._opener.join(self._filename)
-        )
+        self._set_identity()
 
         testing.wait_on_cfg(self._ui, b'dirstate.pre-read-file')
         if self._use_dirstate_v2:
@@ -563,9 +566,7 @@
             Fills the Dirstatemap when called.
             """
             # ignore HG_PENDING because identity is used only for writing
-            self.identity = util.filestat.frompath(
-                self._opener.join(self._filename)
-            )
+            self._set_identity()
 
             testing.wait_on_cfg(self._ui, b'dirstate.pre-read-file')
             if self._use_dirstate_v2: