From patchwork Tue Apr 11 22:47:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [07, of, 12] upgrade: filter optimizations outside of 'determineactions' From: Pierre-Yves David X-Patchwork-Id: 20121 Message-Id: <0ac92cae04221762209a.1491950867@nodosa.octopoid.net> To: mercurial-devel@mercurial-scm.org Date: Wed, 12 Apr 2017 00:47:47 +0200 # HG changeset patch # User Pierre-Yves David # 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. 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'))