From 70e306f05514cfa07d2ca8ef1065be56d46ce3fe Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 15 May 2012 20:19:38 +0200 Subject: [PATCH] Process all jobs in one method and remove lock jobs which are not used --- src/Composer/DependencyResolver/Rule.php | 4 - src/Composer/DependencyResolver/Solver.php | 116 +++++++++------------ 2 files changed, 48 insertions(+), 72 deletions(-) diff --git a/src/Composer/DependencyResolver/Rule.php b/src/Composer/DependencyResolver/Rule.php index 4370d38c6..a7248f65a 100644 --- a/src/Composer/DependencyResolver/Rule.php +++ b/src/Composer/DependencyResolver/Rule.php @@ -20,7 +20,6 @@ class Rule const RULE_INTERNAL_ALLOW_UPDATE = 1; const RULE_JOB_INSTALL = 2; const RULE_JOB_REMOVE = 3; - const RULE_JOB_LOCK = 4; const RULE_PACKAGE_CONFLICT = 6; const RULE_PACKAGE_REQUIRES = 7; const RULE_PACKAGE_OBSOLETES = 8; @@ -196,9 +195,6 @@ class Rule case self::RULE_JOB_REMOVE: return "Remove command rule ($ruleText)"; - case self::RULE_JOB_LOCK: - return "Lock command rule ($ruleText)"; - case self::RULE_PACKAGE_CONFLICT: $package1 = $this->literals[0]->getPackage(); $package2 = $this->literals[1]->getPackage(); diff --git a/src/Composer/DependencyResolver/Solver.php b/src/Composer/DependencyResolver/Solver.php index 6cd3c55a3..a447479e9 100644 --- a/src/Composer/DependencyResolver/Solver.php +++ b/src/Composer/DependencyResolver/Solver.php @@ -481,6 +481,53 @@ class Solver } } + protected function addRulesForJobs() + { + foreach ($this->jobs as $job) { + switch ($job['cmd']) { + case 'update': + foreach ($job['packages'] as $package) { + if (isset($this->installedMap[$package->getId()])) { + $this->updateMap[$package->getId()] = true; + } + } + break; + + case 'update-all': + foreach ($this->installedMap as $package) { + $this->updateMap[$package->getId()] = true; + } + break; + case 'install': + if (empty($job['packages'])) { + $problem = new Problem(); + $problem->addJobRule($job); + $this->problems[] = $problem; + } else { + foreach ($job['packages'] as $package) { + if (!isset($this->installedMap[$package->getId()])) { + $this->addRulesForPackage($package); + } + } + + $rule = $this->createInstallOneOfRule($job['packages'], Rule::RULE_JOB_INSTALL, $job['packageName']); + $this->addRule(RuleSet::TYPE_JOB, $rule); + $this->ruleToJob[$rule->getId()] = $job; + } + break; + case 'remove': + // remove all packages with this name including uninstalled + // ones to make sure none of them are picked as replacements + foreach ($job['packages'] as $package) { + $rule = $this->createRemoveRule($package, Rule::RULE_JOB_REMOVE); + $this->addRule(RuleSet::TYPE_JOB, $rule); + $this->ruleToJob[$rule->getId()] = $job; + } + break; + } + } + } + public function solve(Request $request) { $this->jobs = $request->getJobs(); @@ -493,79 +540,12 @@ class Solver $this->decisionMap = array_fill(0, $this->pool->getMaxId() + 1, 0); } - foreach ($this->jobs as $job) { - foreach ($job['packages'] as $package) { - switch ($job['cmd']) { - case 'update': - if (isset($this->installedMap[$package->getId()])) { - $this->updateMap[$package->getId()] = true; - } - break; - } - } - - switch ($job['cmd']) { - case 'update-all': - foreach ($this->installedMap as $package) { - $this->updateMap[$package->getId()] = true; - } - break; - } - } - foreach ($this->installedMap as $package) { $this->addRulesForPackage($package); $this->addRulesForUpdatePackages($package); } - foreach ($this->jobs as $job) { - foreach ($job['packages'] as $package) { - switch ($job['cmd']) { - case 'install': - $this->installCandidateMap[$package->getId()] = true; - $this->addRulesForPackage($package); - break; - } - } - } - - foreach ($this->jobs as $job) { - switch ($job['cmd']) { - case 'install': - if (empty($job['packages'])) { - $problem = new Problem(); - $problem->addJobRule($job); - $this->problems[] = $problem; - } else { - $rule = $this->createInstallOneOfRule($job['packages'], Rule::RULE_JOB_INSTALL, $job['packageName']); - $this->addRule(RuleSet::TYPE_JOB, $rule); - $this->ruleToJob[$rule->getId()] = $job; - } - break; - case 'remove': - // remove all packages with this name including uninstalled - // ones to make sure none of them are picked as replacements - - // todo: cleandeps - foreach ($job['packages'] as $package) { - $rule = $this->createRemoveRule($package, Rule::RULE_JOB_REMOVE); - $this->addRule(RuleSet::TYPE_JOB, $rule); - $this->ruleToJob[$rule->getId()] = $job; - } - break; - case 'lock': - foreach ($job['packages'] as $package) { - if (isset($this->installedMap[$package->getId()])) { - $rule = $this->createInstallRule($package, Rule::RULE_JOB_LOCK); - } else { - $rule = $this->createRemoveRule($package, Rule::RULE_JOB_LOCK); - } - $this->addRule(RuleSet::TYPE_JOB, $rule); - $this->ruleToJob[$rule->getId()] = $job; - } - break; - } - } + $this->addRulesForJobs(); foreach ($this->rules as $rule) { $this->addWatchesToRule($rule);