dirstatemap: stop setting identity after reading the data stable
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 18 Feb 2025 21:23:13 +0100
branchstable
changeset 52962 e16065bb7f42
parent 52961 51a9148f8349
child 52963 42f78c859dd1
child 52966 7aec18bded6d
dirstatemap: stop setting identity after reading the data The code was calling `_set_identity` in too many places, resulting in fetching cache information after reading the on disk data. This could result in old data labelled with the identity of new, never loaded data. Fixing it solve the issue spotted in the previous changesets. Further cleanup are warranted but it seems more reasonable to do them on stable.
mercurial/dirstatemap.py
tests/test-dirstate-read-race.t
--- a/mercurial/dirstatemap.py	Tue Feb 18 03:28:20 2025 +0100
+++ b/mercurial/dirstatemap.py	Tue Feb 18 21:23:13 2025 +0100
@@ -674,7 +674,6 @@
             Fills the Dirstatemap when called.
             """
             # ignore HG_PENDING because identity is used only for writing
-            self._set_identity()
 
             testing.wait_on_cfg(self._ui, b'dirstate.pre-read-file')
             if self._use_dirstate_v2:
@@ -714,7 +713,6 @@
             return self._map
 
         def _get_rust_identity(self):
-            self._set_identity()
             identity = None
             if self.identity is not None and self.identity.stat is not None:
                 stat_info = self.identity.stat
@@ -734,8 +732,9 @@
             return identity
 
         def _v1_map(self, from_v2_exception=None):
-            identity = self._get_rust_identity()
             try:
+                self._set_identity()
+                identity = self._get_rust_identity()
                 self._map, parents = rustmod.DirstateMap.new_v1(
                     self._readdirstatefile(), identity
                 )
--- a/tests/test-dirstate-read-race.t	Tue Feb 18 03:28:20 2025 +0100
+++ b/tests/test-dirstate-read-race.t	Tue Feb 18 21:23:13 2025 +0100
@@ -284,27 +284,6 @@
   $ touch $TESTTMP/status-race-lock
   $ wait
 (the working copy should have been updated)
-#if rust no-rhg known-bad-output dirstate-v2-append pre-some-read known-bad-output
-  $ hg log -T '{node|short}\n' --rev "."
-  9a86dcbfb938
-  $ hg log -GT '{node|short} {desc}\n'
-  @  9a86dcbfb938 more files to have two commit
-  |
-  o  4f23db756b09 recreate a bunch of files to facilitate dirstate-v2 append
-  
-  $ hg status
-  A dir/o
-  R dir/nested/m
-  ! dir/i
-  ! dir/j
-  ! dir/nested/h
-  ! dir2/k
-  ! dir2/l
-  ! g
-  ? dir/n
-  ? p
-  ? q
-#else
   $ hg log -T '{node|short}\n' --rev "."
   4f23db756b09
   $ hg log -GT '{node|short} {desc}\n'
@@ -317,7 +296,6 @@
   ? dir/n
   ? p
   ? q
-#endif
 
 The status process should return a consistent result and not crash.