comparison mercurial/dirstate.py @ 50116:4f758b51bf9b

dirstate: enforce the use of `changing_files` context to change tracking Now that everything is using the new context, we can start enforcing its usage.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 26 Jan 2023 17:46:54 +0100
parents 3550e4a88ccd
children 8d02dfac072e
comparison
equal deleted inserted replaced
50115:3236643066c4 50116:4f758b51bf9b
72 msg = 'calling `%s` outside of a changing_parents context' 72 msg = 'calling `%s` outside of a changing_parents context'
73 msg %= func.__name__ 73 msg %= func.__name__
74 raise error.ProgrammingError(msg) 74 raise error.ProgrammingError(msg)
75 if self._invalidated_context: 75 if self._invalidated_context:
76 msg = 'calling `%s` after the dirstate was invalidated' 76 msg = 'calling `%s` after the dirstate was invalidated'
77 raise error.ProgrammingError(msg)
78 return func(self, *args, **kwargs)
79
80 return wrap
81
82
83 def requires_changing_files(func):
84 def wrap(self, *args, **kwargs):
85 if not self.is_changing_files:
86 msg = 'calling `%s` outside of a `changing_files`'
87 msg %= func.__name__
77 raise error.ProgrammingError(msg) 88 raise error.ProgrammingError(msg)
78 return func(self, *args, **kwargs) 89 return func(self, *args, **kwargs)
79 90
80 return wrap 91 return wrap
81 92
537 548
538 def copies(self): 549 def copies(self):
539 return self._map.copymap 550 return self._map.copymap
540 551
541 @requires_not_changing_parents 552 @requires_not_changing_parents
553 @requires_changing_files
542 def set_tracked(self, filename, reset_copy=False): 554 def set_tracked(self, filename, reset_copy=False):
543 """a "public" method for generic code to mark a file as tracked 555 """a "public" method for generic code to mark a file as tracked
544 556
545 This function is to be called outside of "update/merge" case. For 557 This function is to be called outside of "update/merge" case. For
546 example by a command like `hg add X`. 558 example by a command like `hg add X`.
559 if pre_tracked: 571 if pre_tracked:
560 self._dirty_tracked_set = True 572 self._dirty_tracked_set = True
561 return pre_tracked 573 return pre_tracked
562 574
563 @requires_not_changing_parents 575 @requires_not_changing_parents
576 @requires_changing_files
564 def set_untracked(self, filename): 577 def set_untracked(self, filename):
565 """a "public" method for generic code to mark a file as untracked 578 """a "public" method for generic code to mark a file as untracked
566 579
567 This function is to be called outside of "update/merge" case. For 580 This function is to be called outside of "update/merge" case. For
568 example by a command like `hg remove X`. 581 example by a command like `hg remove X`.