From 956b54e5167c6dd9244072c59406fb1d4ba23f62 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 22 Feb 2012 09:40:05 +0100 Subject: [PATCH] Use policy rule instead of stacking up another repo to prioritize aliased packages --- src/Composer/Command/InstallCommand.php | 4 +--- src/Composer/DependencyResolver/DefaultPolicy.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index 89dc3aa87..426c1fb9e 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -106,7 +106,6 @@ EOT } // prepare aliased packages - $aliasRepo = new ArrayRepository; if (!$update && $composer->getLocker()->isLocked()) { $aliases = $composer->getLocker()->getAliases(); } else { @@ -114,14 +113,13 @@ EOT } foreach ($aliases as $alias) { foreach ($repoManager->findPackages($alias['package'], $alias['version']) as $package) { - $aliasRepo->addPackage(new AliasPackage($package, $alias['alias'])); + $package->getRepository()->addPackage(new AliasPackage($package, $alias['alias'])); } foreach ($repoManager->getLocalRepository()->findPackages($alias['package'], $alias['version']) as $package) { $repoManager->getLocalRepository()->addPackage(new AliasPackage($package, $alias['alias'])); $repoManager->getLocalRepository()->removePackage($package); } } - $repoManager->addRepository($aliasRepo); // creating repository pool $pool = new Pool; diff --git a/src/Composer/DependencyResolver/DefaultPolicy.php b/src/Composer/DependencyResolver/DefaultPolicy.php index 63699d883..277188238 100644 --- a/src/Composer/DependencyResolver/DefaultPolicy.php +++ b/src/Composer/DependencyResolver/DefaultPolicy.php @@ -14,6 +14,7 @@ namespace Composer\DependencyResolver; use Composer\Repository\RepositoryInterface; use Composer\Package\PackageInterface; +use Composer\Package\AliasPackage; use Composer\Package\LinkConstraint\VersionConstraint; /** @@ -103,6 +104,16 @@ class DefaultPolicy implements PolicyInterface public function compareByPriorityPreferInstalled(Pool $pool, array $installedMap, PackageInterface $a, PackageInterface $b, $ignoreReplace = false) { if ($a->getRepository() === $b->getRepository()) { + if ($a->getName() === $b->getName()) { + $aAliased = $a instanceof AliasPackage; + $bAliased = $b instanceof AliasPackage; + if ($aAliased && !$bAliased) { + return -1; // use a + } + if (!$aAliased && $bAliased) { + return 1; // use b + } + } if (!$ignoreReplace) { // return original, not replaced