dirstate: factor the identity getting/setting code in the dirstate map
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 21 Feb 2023 15:10:12 +0100
changeset 50175 85746485a4dd
parent 50174 eedbf8256263
child 50176 ec769cbc1fa2
dirstate: factor the identity getting/setting code in the dirstate map We are doing the same things twice and we will add more logic in the next changesets. So lets start factoring things out now.
mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py	Wed Feb 22 00:53:51 2023 +0100
+++ b/mercurial/dirstatemap.py	Tue Feb 21 15:10:12 2023 +0100
@@ -58,6 +58,15 @@
         # for consistent view between _pl() and _read() invocations
         self._pendingmode = None
 
+    def _set_identity(self):
+        self.identity = self._get_current_identity()
+
+    def _get_current_identity(self):
+        try:
+            return util.cachestat(self._opener.join(self._filename))
+        except FileNotFoundError:
+            return None
+
     def preload(self):
         """Loads the underlying data, if it's not already loaded"""
         self._map
@@ -263,10 +272,7 @@
 
     def read(self):
         # ignore HG_PENDING because identity is used only for writing
-        try:
-            self.identity = util.cachestat(self._opener.join(self._filename))
-        except FileNotFoundError:
-            self.identity = None
+        self._set_identity()
 
         if self._use_dirstate_v2:
             if not self.docket.uuid:
@@ -529,12 +535,7 @@
             Fills the Dirstatemap when called.
             """
             # ignore HG_PENDING because identity is used only for writing
-            try:
-                self.identity = util.cachestat(
-                    self._opener.join(self._filename)
-                )
-            except FileNotFoundError:
-                self.identity = None
+            self._set_identity()
 
             if self._use_dirstate_v2:
                 if self.docket.uuid: