mercurial/upgrade.py
changeset 31899 cccd8e1538b0
parent 31898 9db45228da52
child 31900 0f0d7005b9ad
--- a/mercurial/upgrade.py	Fri Apr 07 18:46:27 2017 +0200
+++ b/mercurial/upgrade.py	Tue Apr 11 23:46:16 2017 +0200
@@ -261,8 +261,7 @@
 
     return optimizations
 
-def determineactions(repo, improvements, sourcereqs, destreqs,
-                            optimize):
+def determineactions(repo, improvements, sourcereqs, destreqs):
     """Determine upgrade actions that will be performed.
 
     Given a list of improvements as returned by ``finddeficiencies`` and
@@ -290,8 +289,6 @@
         if i.type == deficiency:
             newactions.append(name)
 
-    newactions.extend(o for o in sorted(optimize) if o not in newactions)
-
     # FUTURE consider adding some optimizations here for certain transitions.
     # e.g. adding generaldelta could schedule parent redeltas.
 
@@ -621,20 +618,27 @@
                           _(', ').join(sorted(unsupportedreqs)))
 
     # Find and validate all improvements that can be made.
-    alloptimizations = optimizations = findoptimizations(repo)
+    alloptimizations = findoptimizations(repo)
 
-    # Validate arguments.
-    unknownoptimize = optimize - set(i.name for i in optimizations)
-    if unknownoptimize:
+    # Apply and Validate arguments.
+    optimizations = []
+    for o in alloptimizations:
+        if o.name in optimize:
+            optimizations.append(o)
+            optimize.discard(o.name)
+
+    if optimize: # anything left is unknown
         raise error.Abort(_('unknown optimization action requested: %s') %
-                          ', '.join(sorted(unknownoptimize)),
+                          ', '.join(sorted(optimize)),
                           hint=_('run without arguments to see valid '
                                  'optimizations'))
 
     deficiencies = finddeficiencies(repo)
     improvements = deficiencies + optimizations
-    actions = determineactions(repo, improvements, repo.requirements,
-                                      newreqs, optimize)
+    actions = determineactions(repo, deficiencies, repo.requirements, newreqs)
+    actions.extend(o.name for o in sorted(optimizations)
+                   # determineactions could have added optimisation
+                   if o.name not in actions)
 
     def printrequirements():
         ui.write(_('requirements\n'))