changeset 46051: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 ad9dd4d333be
children 08802795ae90
files mercurial/upgrade.py mercurial/upgrade_utils/actions.py
diffstat 2 files changed, 34 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/upgrade.py	Tue Dec 01 15:50:12 2020 +0100
+++ b/mercurial/upgrade.py	Tue Dec 01 20:24:38 2020 +0100
@@ -74,48 +74,11 @@
     # Ensure the repository can be upgraded.
     upgrade_actions.check_source_requirements(repo)
 
-    newreqs = localrepo.newreporequirements(
-        repo.ui, localrepo.defaultcreateopts(repo.ui)
-    )
+    default_options = localrepo.defaultcreateopts(repo.ui)
+    newreqs = localrepo.newreporequirements(repo.ui, default_options)
     newreqs.update(upgrade_actions.preservedrequirements(repo))
 
-    noremovereqs = (
-        repo.requirements
-        - newreqs
-        - upgrade_actions.supportremovedrequirements(repo)
-    )
-    if noremovereqs:
-        raise error.Abort(
-            _(
-                b'cannot upgrade repository; requirement would be '
-                b'removed: %s'
-            )
-            % _(b', ').join(sorted(noremovereqs))
-        )
-
-    noaddreqs = (
-        newreqs
-        - repo.requirements
-        - upgrade_actions.allowednewrequirements(repo)
-    )
-    if noaddreqs:
-        raise error.Abort(
-            _(
-                b'cannot upgrade repository; do not support adding '
-                b'requirement: %s'
-            )
-            % _(b', ').join(sorted(noaddreqs))
-        )
-
-    unsupportedreqs = newreqs - upgrade_actions.supporteddestrequirements(repo)
-    if unsupportedreqs:
-        raise error.Abort(
-            _(
-                b'cannot upgrade repository; do not support '
-                b'destination requirement: %s'
-            )
-            % _(b', ').join(sorted(unsupportedreqs))
-        )
+    upgrade_actions.check_requirements_changes(repo, newreqs)
 
     # Find and validate all improvements that can be made.
     alloptimizations = upgrade_actions.findoptimizations(repo)
--- 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)