Remove package/repo priority concept as it is enforced by the pool builder now
parent
926afab1f4
commit
f68731e663
|
@ -69,7 +69,6 @@ class DefaultPolicy implements PolicyInterface
|
|||
}
|
||||
|
||||
foreach ($packages as &$sortedLiterals) {
|
||||
$sortedLiterals = $this->pruneToHighestPriority($pool, $sortedLiterals);
|
||||
$sortedLiterals = $this->pruneToBestVersion($pool, $sortedLiterals);
|
||||
$sortedLiterals = $this->pruneRemoteAliases($pool, $sortedLiterals);
|
||||
}
|
||||
|
@ -104,7 +103,6 @@ class DefaultPolicy implements PolicyInterface
|
|||
*/
|
||||
public function compareByPriority(Pool $pool, PackageInterface $a, PackageInterface $b, $requiredPackage = null, $ignoreReplace = false)
|
||||
{
|
||||
if ($a->getRepository() === $b->getRepository()) {
|
||||
// prefer aliases to the original package
|
||||
if ($a->getName() === $b->getName()) {
|
||||
$aAliased = $a instanceof AliasPackage;
|
||||
|
@ -148,9 +146,6 @@ class DefaultPolicy implements PolicyInterface
|
|||
return ($a->id < $b->id) ? -1 : 1;
|
||||
}
|
||||
|
||||
return ($pool->getPriority($a->id) > $pool->getPriority($b->id)) ? -1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if source replaces a package with the same name as target.
|
||||
*
|
||||
|
@ -198,32 +193,6 @@ class DefaultPolicy implements PolicyInterface
|
|||
return $bestLiterals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assumes that highest priority packages come first
|
||||
*/
|
||||
protected function pruneToHighestPriority(Pool $pool, array $literals)
|
||||
{
|
||||
$selected = array();
|
||||
|
||||
$priority = null;
|
||||
|
||||
foreach ($literals as $literal) {
|
||||
$package = $pool->literalToPackage($literal);
|
||||
|
||||
if (null === $priority) {
|
||||
$priority = $pool->getPriority($package->id);
|
||||
}
|
||||
|
||||
if ($pool->getPriority($package->id) != $priority) {
|
||||
break;
|
||||
}
|
||||
|
||||
$selected[] = $literal;
|
||||
}
|
||||
|
||||
return $selected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assumes that locally aliased (in root package requires) packages take priority over branch-alias ones
|
||||
*
|
||||
|
|
|
@ -36,7 +36,6 @@ class Pool implements \Countable
|
|||
protected $packages = array();
|
||||
protected $packageByName = array();
|
||||
protected $packageByExactName = array();
|
||||
protected $priorities = array();
|
||||
protected $versionParser;
|
||||
protected $providerCache = array();
|
||||
|
||||
|
@ -45,13 +44,12 @@ class Pool implements \Countable
|
|||
$this->versionParser = new VersionParser;
|
||||
}
|
||||
|
||||
public function setPackages(array $packages, array $priorities = array())
|
||||
public function setPackages(array $packages)
|
||||
{
|
||||
$id = 1;
|
||||
|
||||
foreach ($packages as $i => $package) {
|
||||
$this->packages[] = $package;
|
||||
$this->priorities[] = isset($priorities[$i]) ? $priorities[$i] : 0;
|
||||
|
||||
$package->id = $id++;
|
||||
$names = $package->getNames();
|
||||
|
@ -63,11 +61,6 @@ class Pool implements \Countable
|
|||
}
|
||||
}
|
||||
|
||||
public function getPriority($id)
|
||||
{
|
||||
return $this->priorities[$id - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the package object for a given package id.
|
||||
*
|
||||
|
|
|
@ -38,7 +38,6 @@ class PoolBuilder
|
|||
private $loadedNames = array();
|
||||
|
||||
private $packages = array();
|
||||
private $priorities = array();
|
||||
|
||||
public function __construct($isPackageAcceptableCallable, array $rootRequires = array())
|
||||
{
|
||||
|
@ -134,7 +133,6 @@ class PoolBuilder
|
|||
if (!$found) {
|
||||
foreach ($aliasedPackages as $index => $packageOrAlias) {
|
||||
unset($this->packages[$index]);
|
||||
unset($this->priorities[$index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +147,7 @@ class PoolBuilder
|
|||
}
|
||||
}
|
||||
|
||||
$pool->setPackages($this->packages, $this->priorities);
|
||||
$pool->setPackages($this->packages);
|
||||
|
||||
unset($this->aliasMap);
|
||||
unset($this->loadedNames);
|
||||
|
@ -158,11 +156,10 @@ class PoolBuilder
|
|||
return $pool;
|
||||
}
|
||||
|
||||
private function loadPackage(Request $request, PackageInterface $package, $repoIndex)
|
||||
private function loadPackage(Request $request, PackageInterface $package)
|
||||
{
|
||||
$index = count($this->packages);
|
||||
$this->packages[] = $package;
|
||||
$this->priorities[] = -$repoIndex;
|
||||
|
||||
if ($package instanceof AliasPackage) {
|
||||
$this->aliasMap[spl_object_hash($package->getAliasOf())][$index] = $package;
|
||||
|
@ -192,7 +189,6 @@ class PoolBuilder
|
|||
|
||||
$package->getRepository()->addPackage($aliasPackage); // TODO do we need this?
|
||||
$this->packages[] = $aliasPackage;
|
||||
$this->priorities[] = -$repoIndex;
|
||||
$this->aliasMap[spl_object_hash($aliasPackage->getAliasOf())][$index+1] = $aliasPackage;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,9 @@ class RepositorySet
|
|||
/**
|
||||
* Adds a repository to this repository set
|
||||
*
|
||||
* The first repos added have a higher priority. As soon as a package is found in any
|
||||
* repository the search for that package ends, and following repos will not be consulted.
|
||||
*
|
||||
* @param RepositoryInterface $repo A package repository
|
||||
*/
|
||||
public function addRepository(RepositoryInterface $repo)
|
||||
|
@ -134,17 +137,6 @@ class RepositorySet
|
|||
return $candidates;
|
||||
}
|
||||
|
||||
public function getPriority(RepositoryInterface $repo)
|
||||
{
|
||||
$priority = array_search($repo, $this->repositories, true);
|
||||
|
||||
if (false === $priority) {
|
||||
throw new \RuntimeException("Could not determine repository priority. The repository was not registered in the pool.");
|
||||
}
|
||||
|
||||
return -$priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a pool for dependency resolution from the packages in this repository set.
|
||||
*
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
namespace Composer\Test\DependencyResolver;
|
||||
|
||||
use Composer\Repository\ArrayRepository;
|
||||
use Composer\Repository\LockArrayRepository;
|
||||
use Composer\Repository\RepositoryInterface;
|
||||
use Composer\DependencyResolver\DefaultPolicy;
|
||||
use Composer\DependencyResolver\Pool;
|
||||
|
@ -28,7 +29,7 @@ class DefaultPolicyTest extends TestCase
|
|||
protected $repositorySet;
|
||||
/** @var ArrayRepository */
|
||||
protected $repo;
|
||||
/** @var ArrayRepository */
|
||||
/** @var LockArrayRepository */
|
||||
protected $repoLocked;
|
||||
/** @var DefaultPolicy */
|
||||
protected $policy;
|
||||
|
@ -37,7 +38,7 @@ class DefaultPolicyTest extends TestCase
|
|||
{
|
||||
$this->repositorySet = new RepositorySet(array(), array(), 'dev');
|
||||
$this->repo = new ArrayRepository;
|
||||
$this->repoLocked = new ArrayRepository;
|
||||
$this->repoLocked = new LockArrayRepository;
|
||||
|
||||
$this->policy = new DefaultPolicy;
|
||||
}
|
||||
|
@ -122,44 +123,6 @@ class DefaultPolicyTest extends TestCase
|
|||
$this->assertSame($expected, $selected);
|
||||
}
|
||||
|
||||
public function testSelectNewestOverLocked()
|
||||
{
|
||||
$this->repo->addPackage($packageA = $this->getPackage('A', '2.0'));
|
||||
$this->repoLocked->addPackage($packageAInstalled = $this->getPackage('A', '1.0'));
|
||||
$this->repositorySet->addRepository($this->repo);
|
||||
$this->repositorySet->addRepository($this->repoLocked);
|
||||
|
||||
$pool = $this->repositorySet->createPoolForPackage('A');
|
||||
|
||||
$literals = array($packageA->getId(), $packageAInstalled->getId());
|
||||
$expected = array($packageA->getId());
|
||||
|
||||
$selected = $this->policy->selectPreferredPackages($pool, $literals);
|
||||
|
||||
$this->assertSame($expected, $selected);
|
||||
}
|
||||
|
||||
public function testSelectFirstRepo()
|
||||
{
|
||||
$otherRepository = new ArrayRepository;
|
||||
|
||||
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
|
||||
$otherRepository->addPackage($packageAImportant = $this->getPackage('A', '1.0'));
|
||||
|
||||
$this->repositorySet->addRepository($otherRepository);
|
||||
$this->repositorySet->addRepository($this->repo);
|
||||
$this->repositorySet->addRepository($this->repoLocked);
|
||||
|
||||
$pool = $this->repositorySet->createPoolForPackage('A');
|
||||
|
||||
$literals = array($packageA->getId(), $packageAImportant->getId());
|
||||
$expected = array($packageAImportant->getId());
|
||||
|
||||
$selected = $this->policy->selectPreferredPackages($pool, $literals);
|
||||
|
||||
$this->assertSame($expected, $selected);
|
||||
}
|
||||
|
||||
public function testRepositoryOrderingAffectsPriority()
|
||||
{
|
||||
$repo1 = new ArrayRepository;
|
||||
|
|
Loading…
Reference in New Issue