comparison mercurial/dirstate.py @ 50108: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 cdbd5f990596
children bec7182cc406
comparison
equal deleted inserted replaced
50107:cad3a68c0e0c 50108:f7981f202b7a
82 def requires_changing_files(func): 82 def requires_changing_files(func):
83 def wrap(self, *args, **kwargs): 83 def wrap(self, *args, **kwargs):
84 if not self.is_changing_files: 84 if not self.is_changing_files:
85 msg = 'calling `%s` outside of a `changing_files`' 85 msg = 'calling `%s` outside of a `changing_files`'
86 msg %= func.__name__ 86 msg %= func.__name__
87 raise error.ProgrammingError(msg)
88 return func(self, *args, **kwargs)
89
90 return wrap
91
92
93 def requires_changing_any(func):
94 def wrap(self, *args, **kwargs):
95 if not self.is_changing_any:
96 msg = 'calling `%s` outside of a changing context'
97 msg %= func.__name__
98 raise error.ProgrammingError(msg)
99 if self._invalidated_context:
100 msg = 'calling `%s` after the dirstate was invalidated'
87 raise error.ProgrammingError(msg) 101 raise error.ProgrammingError(msg)
88 return func(self, *args, **kwargs) 102 return func(self, *args, **kwargs)
89 103
90 return wrap 104 return wrap
91 105