Mercurial > hg-stable
changeset 50157:f7981f202b7a
dirstate: add a `require_changing_any` decorator
We will need it for a couple of usecase (e.g `dirstate.copy`).
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 20 Feb 2023 11:54:10 +0100 |
parents | cad3a68c0e0c |
children | bec7182cc406 |
files | mercurial/dirstate.py |
diffstat | 1 files changed, 14 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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: