diff mercurial/dirstate.py @ 49961:7a8bfc05b691

dirstate: rename parentchange to changing_parents Since the new argument breaks the API anyway, we can rename it to a better name. The previous name `parentchange` might be seen as something active, a function that would directly change the parents, however this is just a context manager to frame the operation that will change the parents and adjust the dirstate content accordingly. In addition, the future sister method that will be about changes to tracking and files would have a hard time fitting in the same naming scheme in a clear way. The new naming uses a clear prefix will make it more distinct from other dirstate methods and easier to extend with other similar contexts.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 25 Jan 2023 19:12:31 +0100
parents c166b212bdee
children 5b0beaf45491
line wrap: on
line diff
--- a/mercurial/dirstate.py	Wed Jan 25 18:46:20 2023 +0100
+++ b/mercurial/dirstate.py	Wed Jan 25 19:12:31 2023 +0100
@@ -69,7 +69,7 @@
 def requires_parents_change(func):
     def wrap(self, *args, **kwargs):
         if not self.pendingparentchange():
-            msg = 'calling `%s` outside of a parentchange context'
+            msg = 'calling `%s` outside of a changing_parents context'
             msg %= func.__name__
             raise error.ProgrammingError(msg)
         if self._invalidated_context:
@@ -83,7 +83,7 @@
 def requires_no_parents_change(func):
     def wrap(self, *args, **kwargs):
         if self.pendingparentchange():
-            msg = 'calling `%s` inside of a parentchange context'
+            msg = 'calling `%s` inside of a changing_parents context'
             msg %= func.__name__
             raise error.ProgrammingError(msg)
         return func(self, *args, **kwargs)
@@ -127,7 +127,7 @@
         self._dirty_tracked_set = False
         self._ui = ui
         self._filecache = {}
-        # nesting level of `parentchange` context
+        # nesting level of `changing_parents` context
         self._parentwriters = 0
         # True if the current dirstate changing operations have been
         # invalidated (used to make sure all nested contexts have been exited)
@@ -151,7 +151,7 @@
         self._pl
 
     @contextlib.contextmanager
-    def parentchange(self, repo):
+    def changing_parents(self, repo):
         """Context manager for handling dirstate parents.
 
         If an exception occurs in the scope of the context manager,
@@ -180,6 +180,14 @@
                     assert self._parentwriters == 0
                     self._invalidated_context = False
 
+    # here to help migration to the new code
+    def parentchange(self):
+        msg = (
+            "Mercurial 6.4 and later requires call to "
+            "`dirstate.changing_parents(repo)`"
+        )
+        raise error.ProgrammingError(msg)
+
     def pendingparentchange(self):
         """Returns true if the dirstate is in the middle of a set of changes
         that modify the dirstate parent.
@@ -399,7 +407,7 @@
         if self._parentwriters == 0:
             raise ValueError(
                 b"cannot set dirstate parent outside of "
-                b"dirstate.parentchange context manager"
+                b"dirstate.changing_parents context manager"
             )
 
         self._dirty = True
@@ -523,7 +531,7 @@
         rewriting operation.
 
         It should not be called during a merge (p2 != nullid) and only within
-        a `with dirstate.parentchange(repo):` context.
+        a `with dirstate.changing_parents(repo):` context.
         """
         if self.in_merge:
             msg = b'update_file_reference should not be called when merging'
@@ -566,7 +574,7 @@
         This is to be called when the direstates parent changes to keep track
         of what is the file situation in regards to the working copy and its parent.
 
-        This function must be called within a `dirstate.parentchange` context.
+        This function must be called within a `dirstate.changing_parents` context.
 
         note: the API is at an early stage and we might need to adjust it
         depending of what information ends up being relevant and useful to