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.
marmoute | |
mharbison72 |
hg-reviewers |
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.
Automatic diff as part of commit; lint not applicable. |
Automatic diff as part of commit; unit tests not applicable. |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/upgrade.py (20 lines) | |||
M | mercurial/upgrade_utils/actions.py (42 lines) |
Status | Author | Revision | |
---|---|---|---|
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Changes Planned | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit | ||
Closed | pulkit |
% b', '.join(sorted(optimize)), | % b', '.join(sorted(optimize)), | ||||
hint=_(b'run without arguments to see valid optimizations'), | hint=_(b'run without arguments to see valid optimizations'), | ||||
) | ) | ||||
format_upgrades = upgrade_actions.find_format_upgrades(repo) | format_upgrades = upgrade_actions.find_format_upgrades(repo) | ||||
up_actions = upgrade_actions.determine_upgrade_actions( | up_actions = upgrade_actions.determine_upgrade_actions( | ||||
repo, format_upgrades, optimizations, repo.requirements, newreqs | repo, format_upgrades, optimizations, repo.requirements, newreqs | ||||
) | ) | ||||
removed_actions = upgrade_actions.find_format_downgrades(repo) | |||||
removedreqs = repo.requirements - newreqs | removedreqs = repo.requirements - newreqs | ||||
addedreqs = newreqs - repo.requirements | addedreqs = newreqs - repo.requirements | ||||
if revlogs != upgrade_engine.UPGRADE_ALL_REVLOGS: | if revlogs != upgrade_engine.UPGRADE_ALL_REVLOGS: | ||||
incompatible = upgrade_actions.RECLONES_REQUIREMENTS & ( | incompatible = upgrade_actions.RECLONES_REQUIREMENTS & ( | ||||
removedreqs | addedreqs | removedreqs | addedreqs | ||||
) | ) | ||||
if incompatible: | if incompatible: | ||||
msg = _( | msg = _( | ||||
b'ignoring revlogs selection flags, format requirements ' | b'ignoring revlogs selection flags, format requirements ' | ||||
b'change: %s\n' | b'change: %s\n' | ||||
) | ) | ||||
ui.warn(msg % b', '.join(sorted(incompatible))) | ui.warn(msg % b', '.join(sorted(incompatible))) | ||||
revlogs = upgrade_engine.UPGRADE_ALL_REVLOGS | revlogs = upgrade_engine.UPGRADE_ALL_REVLOGS | ||||
upgrade_op = upgrade_actions.UpgradeOperation( | upgrade_op = upgrade_actions.UpgradeOperation( | ||||
ui, | ui, | ||||
newreqs, | newreqs, | ||||
repo.requirements, | repo.requirements, | ||||
up_actions, | up_actions, | ||||
removed_actions, | |||||
revlogs, | revlogs, | ||||
) | ) | ||||
if not run: | if not run: | ||||
fromconfig = [] | fromconfig = [] | ||||
onlydefault = [] | onlydefault = [] | ||||
for d in format_upgrades: | for d in format_upgrades: | ||||
ui.warn( | ui.warn( | ||||
_( | _( | ||||
b'the old repository will not be deleted; remove ' | b'the old repository will not be deleted; remove ' | ||||
b'it to free up disk space once the upgraded ' | b'it to free up disk space once the upgraded ' | ||||
b'repository is verified\n' | b'repository is verified\n' | ||||
) | ) | ||||
) | ) | ||||
if upgrade_actions.sharesafe.name in addedreqs: | upgrade_op.print_post_op_messages() | ||||
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' | |||||
) | |||||
) |
Message intended for humans explaining the improvement in more detail, | Message intended for humans explaining the improvement in more detail, | ||||
including the implications of it. For ``FORMAT_VARIANT`` types, should be | including the implications of it. For ``FORMAT_VARIANT`` types, should be | ||||
worded in the present tense. For ``OPTIMISATION`` types, should be | worded in the present tense. For ``OPTIMISATION`` types, should be | ||||
worded in the future tense. | worded in the future tense. | ||||
upgrademessage | upgrademessage | ||||
Message intended for humans explaining what an upgrade addressing this | Message intended for humans explaining what an upgrade addressing this | ||||
issue will do. Should be worded in the future tense. | 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): | def __init__(self, name, type, description, upgrademessage): | ||||
self.name = name | self.name = name | ||||
self.type = type | self.type = type | ||||
self.description = description | self.description = description | ||||
self.upgrademessage = upgrademessage | self.upgrademessage = upgrademessage | ||||
self.postupgrademessage = None | |||||
self.postdowngrademessage = None | |||||
def __eq__(self, other): | def __eq__(self, other): | ||||
if not isinstance(other, improvement): | if not isinstance(other, improvement): | ||||
# This is what python tell use to do | # This is what python tell use to do | ||||
return NotImplemented | return NotImplemented | ||||
return self.name == other.name | return self.name == other.name | ||||
def __ne__(self, other): | def __ne__(self, other): | ||||
# message intended for humans explaining what an upgrade addressing this | # message intended for humans explaining what an upgrade addressing this | ||||
# issue will do. should be worded in the future tense. | # issue will do. should be worded in the future tense. | ||||
upgrademessage = None | upgrademessage = None | ||||
# value of current Mercurial default for new repository | # value of current Mercurial default for new repository | ||||
default = None | 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): | def __init__(self): | ||||
raise NotImplementedError() | raise NotImplementedError() | ||||
@staticmethod | @staticmethod | ||||
def fromrepo(repo): | def fromrepo(repo): | ||||
"""current value of the variant in the repository""" | """current value of the variant in the repository""" | ||||
raise NotImplementedError() | raise NotImplementedError() | ||||
b'extensions are enabled.' | b'extensions are enabled.' | ||||
) | ) | ||||
upgrademessage = _( | upgrademessage = _( | ||||
b'Upgrades a repository to share-safe format so that future ' | b'Upgrades a repository to share-safe format so that future ' | ||||
b'shares of this repository share its requirements and configs.' | 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 | @registerformatvariant | ||||
class sparserevlog(requirementformatvariant): | class sparserevlog(requirementformatvariant): | ||||
name = b'sparserevlog' | name = b'sparserevlog' | ||||
_requirement = requirements.SPARSEREVLOG_REQUIREMENT | _requirement = requirements.SPARSEREVLOG_REQUIREMENT | ||||
default = True | default = True | ||||
"""represent the work to be done during an upgrade""" | """represent the work to be done during an upgrade""" | ||||
def __init__( | def __init__( | ||||
self, | self, | ||||
ui, | ui, | ||||
new_requirements, | new_requirements, | ||||
current_requirements, | current_requirements, | ||||
upgrade_actions, | upgrade_actions, | ||||
removed_actions, | |||||
revlogs_to_process, | revlogs_to_process, | ||||
): | ): | ||||
self.ui = ui | self.ui = ui | ||||
self.new_requirements = new_requirements | self.new_requirements = new_requirements | ||||
self.current_requirements = current_requirements | self.current_requirements = current_requirements | ||||
# list of upgrade actions the operation will perform | # list of upgrade actions the operation will perform | ||||
self.upgrade_actions = upgrade_actions | self.upgrade_actions = upgrade_actions | ||||
self._upgrade_actions_names = set([a.name for a in 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 | self.revlogs_to_process = revlogs_to_process | ||||
# requirements which will be added by the operation | # requirements which will be added by the operation | ||||
self._added_requirements = ( | self._added_requirements = ( | ||||
self.new_requirements - self.current_requirements | self.new_requirements - self.current_requirements | ||||
) | ) | ||||
# requirements which will be removed by the operation | # requirements which will be removed by the operation | ||||
self._removed_requirements = ( | self._removed_requirements = ( | ||||
self.current_requirements - self.new_requirements | self.current_requirements - self.new_requirements | ||||
def print_unused_optimizations(self): | def print_unused_optimizations(self): | ||||
for i in self.unused_optimizations: | for i in self.unused_optimizations: | ||||
self.ui.status(_(b'%s\n %s\n\n') % (i.name, i.description)) | self.ui.status(_(b'%s\n %s\n\n') % (i.name, i.description)) | ||||
def has_upgrade_action(self, name): | def has_upgrade_action(self, name): | ||||
""" Check whether the upgrade operation will perform this action """ | """ Check whether the upgrade operation will perform this action """ | ||||
return name in self._upgrade_actions_names | 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. # | ### Code checking if a repository can got through the upgrade process at all. # | ||||
def requiredsourcerequirements(repo): | def requiredsourcerequirements(repo): | ||||
"""Obtain requirements required to be present to upgrade a repo. | """Obtain requirements required to be present to upgrade a repo. | ||||
An upgrade will not be allowed if the repository doesn't have the | An upgrade will not be allowed if the repository doesn't have the |