Patchwork [07,of,12] upgrade: filter optimizations outside of 'determineactions'

login
register
mail settings
Submitter Pierre-Yves David
Date April 11, 2017, 10:47 p.m.
Message ID <0ac92cae04221762209a.1491950867@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/20121/
State Accepted
Headers show

Comments

Pierre-Yves David - April 11, 2017, 10:47 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1491947176 -7200
#      Tue Apr 11 23:46:16 2017 +0200
# Node ID 0ac92cae04221762209a3e58ef95ef7c0092c764
# Parent  3c80a99ee76292613a6cbaaa5a69d353f7dfa9a7
# EXP-Topic upgraderepo
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 0ac92cae0422
upgrade: filter optimizations outside of 'determineactions'

This sounds like higher level logic to process arguments.

Moving it out of 'determineactions' will allow passing only deficiencies to the
function. Then, in a future changeset, we will remove  dispatch on "improvement
type" within the function. See next changeset for details.

Patch

diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -261,8 +261,7 @@  def findoptimizations(repo):
 
     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 @@  def determineactions(repo, improvements,
         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 @@  def upgraderepo(ui, repo, run=False, opt
                           _(', ').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'))