Mercurial > hg-stable
changeset 46213:30310886d423
upgrade: introduce post upgrade and downgrade message for improvements
For certain imporvements, we will like to show a message after the operation
completed. This patch introduces that functionality.
Right now it's only used by share-safe feature.
Differential Revision: https://phab.mercurial-scm.org/D9619
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Wed, 16 Dec 2020 14:00:41 +0530 |
parents | c97d8e0406a6 |
children | 5dfa837d933e |
files | mercurial/upgrade.py mercurial/upgrade_utils/actions.py |
diffstat | 2 files changed, 45 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/upgrade.py Wed Dec 16 15:04:17 2020 +0530 +++ b/mercurial/upgrade.py Wed Dec 16 14:00:41 2020 +0530 @@ -87,6 +87,7 @@ up_actions = upgrade_actions.determine_upgrade_actions( repo, format_upgrades, optimizations, repo.requirements, newreqs ) + removed_actions = upgrade_actions.find_format_downgrades(repo) removedreqs = repo.requirements - newreqs addedreqs = newreqs - repo.requirements @@ -108,6 +109,7 @@ newreqs, repo.requirements, up_actions, + removed_actions, revlogs, ) @@ -226,20 +228,4 @@ ) ) - if upgrade_actions.sharesafe.name in addedreqs: - ui.warn( - _( - b'repository upgraded to share safe mode, existing' - b' shares will still work in old non-safe mode. ' - b'Re-share existing shares to use them in safe mode' - b' New shares will be created in safe mode.\n' - ) - ) - if upgrade_actions.sharesafe.name in removedreqs: - ui.warn( - _( - b'repository downgraded to not use share safe mode, ' - b'existing shares will not work and needs to' - b' be reshared.\n' - ) - ) + upgrade_op.print_post_op_messages()
--- a/mercurial/upgrade_utils/actions.py Wed Dec 16 15:04:17 2020 +0530 +++ b/mercurial/upgrade_utils/actions.py Wed Dec 16 14:00:41 2020 +0530 @@ -57,6 +57,14 @@ upgrademessage Message intended for humans explaining what an upgrade addressing this issue will do. Should be worded in the future tense. + + postupgrademessage + Message intended for humans which will be shown post an upgrade + operation when the improvement will be added + + postdowngrademessage + Message intended for humans which will be shown post an upgrade + operation in which this improvement was removed """ def __init__(self, name, type, description, upgrademessage): @@ -64,6 +72,8 @@ self.type = type self.description = description self.upgrademessage = upgrademessage + self.postupgrademessage = None + self.postdowngrademessage = None def __eq__(self, other): if not isinstance(other, improvement): @@ -109,6 +119,14 @@ # value of current Mercurial default for new repository default = None + # Message intended for humans which will be shown post an upgrade + # operation when the improvement will be added + postupgrademessage = None + + # Message intended for humans which will be shown post an upgrade + # operation in which this improvement was removed + postdowngrademessage = None + def __init__(self): raise NotImplementedError() @@ -235,6 +253,19 @@ b'shares of this repository share its requirements and configs.' ) + postdowngrademessage = _( + b'repository downgraded to not use share safe mode, ' + b'existing shares will not work and needs to' + b' be reshared.' + ) + + postupgrademessage = _( + b'repository upgraded to share safe mode, existing' + b' shares will still work in old non-safe mode. ' + b'Re-share existing shares to use them in safe mode' + b' New shares will be created in safe mode.' + ) + @registerformatvariant class sparserevlog(requirementformatvariant): @@ -585,6 +616,7 @@ new_requirements, current_requirements, upgrade_actions, + removed_actions, revlogs_to_process, ): self.ui = ui @@ -593,6 +625,7 @@ # list of upgrade actions the operation will perform self.upgrade_actions = upgrade_actions self._upgrade_actions_names = set([a.name for a in upgrade_actions]) + self.removed_actions = removed_actions self.revlogs_to_process = revlogs_to_process # requirements which will be added by the operation self._added_requirements = ( @@ -679,6 +712,15 @@ """ Check whether the upgrade operation will perform this action """ return name in self._upgrade_actions_names + def print_post_op_messages(self): + """ print post upgrade operation warning messages """ + for a in self.upgrade_actions: + if a.postupgrademessage is not None: + self.ui.warn(b'%s\n' % a.postupgrademessage) + for a in self.removed_actions: + if a.postdowngrademessage is not None: + self.ui.warn(b'%s\n' % a.postdowngrademessage) + ### Code checking if a repository can got through the upgrade process at all. #