Mercurial > public > mercurial-scm > hg-stable
diff mercurial/upgrade_utils/actions.py @ 46055:72b7b4bf3e65
upgrade: extract the checking of target requirements change
This logic is fairly independant, lets move it out of the main function.
Differential Revision: https://phab.mercurial-scm.org/D9485
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 01 Dec 2020 20:24:38 +0100 |
parents | a2a59cde9b9f |
children | 08802795ae90 |
line wrap: on
line diff
--- a/mercurial/upgrade_utils/actions.py Tue Dec 01 15:50:12 2020 +0100 +++ b/mercurial/upgrade_utils/actions.py Tue Dec 01 20:24:38 2020 +0100 @@ -686,3 +686,34 @@ m = _(b'cannot upgrade repository; unsupported source requirement: %s') blockingreqs = b', '.join(sorted(blockingreqs)) raise error.Abort(m % blockingreqs) + + +### Verify the validity of the planned requirement changes #################### + + +def check_requirements_changes(repo, new_reqs): + old_reqs = repo.requirements + + support_removal = supportremovedrequirements(repo) + no_remove_reqs = old_reqs - new_reqs - support_removal + if no_remove_reqs: + msg = _(b'cannot upgrade repository; requirement would be removed: %s') + no_remove_reqs = b', '.join(sorted(no_remove_reqs)) + raise error.Abort(msg % no_remove_reqs) + + support_addition = allowednewrequirements(repo) + no_add_reqs = new_reqs - old_reqs - support_addition + if no_add_reqs: + m = _(b'cannot upgrade repository; do not support adding requirement: ') + no_add_reqs = b', '.join(sorted(no_add_reqs)) + raise error.Abort(m + no_add_reqs) + + supported = supporteddestrequirements(repo) + unsupported_reqs = new_reqs - supported + if unsupported_reqs: + msg = _( + b'cannot upgrade repository; do not support destination ' + b'requirement: %s' + ) + unsupported_reqs = b', '.join(sorted(unsupported_reqs)) + raise error.Abort(msg % unsupported_reqs)