dirstate: add a `require_changing_any` decorator
We will need it for a couple of usecase (e.g `dirstate.copy`).
--- 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: