dirstate: generalize the dirstate's invalidation on transaction abort
authorPierre-Yves David <pierre-yves.david@octobus.net>
Thu, 16 Feb 2023 02:34:54 +0100
changeset 50076 63c4e9639753
parent 50075 8eb460e0a202
child 50077 605f0ccffb43
dirstate: generalize the dirstate's invalidation on transaction abort The previous code was too specific, we should add the invalidation at next to the `addfilegenerator` in the `write` call.
mercurial/dirstate.py
--- a/mercurial/dirstate.py	Thu Feb 16 02:22:13 2023 +0100
+++ b/mercurial/dirstate.py	Thu Feb 16 02:34:54 2023 +0100
@@ -217,9 +217,6 @@
                         # calling) might have been called by a nested context
                         # instead of the top level one.
                         tr = repo.currenttransaction()
-                        if tr is not None:
-                            abort_cb = lambda tr: self.invalidate()
-                            tr.addabort(b'dirstate', abort_cb)
                         self.write(tr)
 
     @contextlib.contextmanager
@@ -917,6 +914,12 @@
 
         write_key = self._use_tracked_hint and self._dirty_tracked_set
         if tr:
+            # make sure we invalidate the current change on abort
+            if tr is not None:
+                tr.addabort(
+                    b'dirstate-invalidate',
+                    lambda tr: self.invalidate(),
+                )
             # delay writing in-memory changes out
             tr.addfilegenerator(
                 b'dirstate-1-main',