# HG changeset patch # User Pierre-Yves David # Date 2020-12-01 14:45:23 # Node ID f4f956342cf137d5b2ce7af1a72171a1f28ea5c7 # Parent 4b89cf08d8dcd096ba4f6bf108fd2a6023beb51d upgrade: move requirements checking in a dedicated function This is a simple an isolated check that can go next to the associated code. Differential Revision: https://phab.mercurial-scm.org/D9482 diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py --- a/mercurial/upgrade.py +++ b/mercurial/upgrade.py @@ -72,26 +72,7 @@ def upgraderepo( revlogs.discard(upgrade) # Ensure the repository can be upgraded. - missingreqs = ( - upgrade_actions.requiredsourcerequirements(repo) - repo.requirements - ) - if missingreqs: - raise error.Abort( - _(b'cannot upgrade repository; requirement missing: %s') - % _(b', ').join(sorted(missingreqs)) - ) - - blockedreqs = ( - upgrade_actions.blocksourcerequirements(repo) & repo.requirements - ) - if blockedreqs: - raise error.Abort( - _( - b'cannot upgrade repository; unsupported source ' - b'requirement: %s' - ) - % _(b', ').join(sorted(blockedreqs)) - ) + upgrade_actions.check_source_requirements(repo) # FUTURE there is potentially a need to control the wanted requirements via # command arguments or via an extension hook point. diff --git a/mercurial/upgrade_utils/actions.py b/mercurial/upgrade_utils/actions.py --- a/mercurial/upgrade_utils/actions.py +++ b/mercurial/upgrade_utils/actions.py @@ -9,6 +9,7 @@ from __future__ import absolute_import from ..i18n import _ from .. import ( + error, localrepo, requirements, util, @@ -664,3 +665,21 @@ def determineactions(repo, deficiencies, # e.g. adding generaldelta could schedule parent redeltas. return newactions + + +def check_source_requirements(repo): + """Ensure that no existing requirements prevent the repository upgrade""" + + required = requiredsourcerequirements(repo) + missingreqs = required - repo.requirements + if missingreqs: + msg = _(b'cannot upgrade repository; requirement missing: %s') + missingreqs = b', '.join(sorted(missingreqs)) + raise error.Abort(msg % missingreqs) + + blocking = blocksourcerequirements(repo) + blockingreqs = blocking & repo.requirements + if blockingreqs: + m = _(b'cannot upgrade repository; unsupported source requirement: %s') + blockingreqs = b', '.join(sorted(blockingreqs)) + raise error.Abort(m % blockingreqs)