marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This logic is fairly independant, lets move it out of the main function.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9485

AFFECTED FILES
  mercurial/upgrade.py
  mercurial/upgrade_utils/actions.py

CHANGE DETAILS

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
@@ -664,3 +664,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)
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -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)



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to