dirstate: add a `require_changing_any` decorator
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 20 Feb 2023 11:54:10 +0100
changeset 50108 f7981f202b7a
parent 50107 cad3a68c0e0c
child 50109 bec7182cc406
dirstate: add a `require_changing_any` decorator We will need it for a couple of usecase (e.g `dirstate.copy`).
mercurial/dirstate.py
--- a/mercurial/dirstate.py	Mon Feb 20 12:06:03 2023 +0100
+++ b/mercurial/dirstate.py	Mon Feb 20 11:54:10 2023 +0100
@@ -90,6 +90,20 @@
     return wrap
 
 
+def requires_changing_any(func):
+    def wrap(self, *args, **kwargs):
+        if not self.is_changing_any:
+            msg = 'calling `%s` outside of a changing context'
+            msg %= func.__name__
+            raise error.ProgrammingError(msg)
+        if self._invalidated_context:
+            msg = 'calling `%s` after the dirstate was invalidated'
+            raise error.ProgrammingError(msg)
+        return func(self, *args, **kwargs)
+
+    return wrap
+
+
 def requires_not_changing_parents(func):
     def wrap(self, *args, **kwargs):
         if self.is_changing_parents: