From 418e876e8a47ab63f7df6c4a82a8a6c93d5df745 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 14 Sep 2012 17:42:12 +0200 Subject: [PATCH] Use only the locked repository when possible for better performance --- src/Composer/Installer.php | 11 +++-- src/Composer/Package/Locker.php | 33 +++++++++++++-- .../install-missing-alias-from-lock.test | 41 +++++++++++++++++++ 3 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 tests/Composer/Test/Fixtures/installer/install-missing-alias-from-lock.test diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 373787cd9..ed405a644 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -255,11 +255,14 @@ class Installer $pool = new Pool($minimumStability, $stabilityFlags); $pool->addRepository($installedRepo, $aliases); if ($installFromLock) { - $pool->addRepository($lockedRepository); + $pool->addRepository($lockedRepository, $aliases); } - $repositories = $this->repositoryManager->getRepositories(); - foreach ($repositories as $repository) { - $pool->addRepository($repository, $aliases); + + if (!$installFromLock || $this->locker->isLegacyFormat($devMode)) { + $repositories = $this->repositoryManager->getRepositories(); + foreach ($repositories as $repository) { + $pool->addRepository($repository, $aliases); + } } // creating requirements request diff --git a/src/Composer/Package/Locker.php b/src/Composer/Package/Locker.php index ac00a14bc..3036f904c 100644 --- a/src/Composer/Package/Locker.php +++ b/src/Composer/Package/Locker.php @@ -87,6 +87,24 @@ class Locker return $this->hash === $lock['hash']; } + /** + * Checks whether the lock file is in the legacy format + * + * @param bool $dev true to check in dev mode + * @return bool + */ + public function isLegacyFormat($dev) + { + $lockData = $this->getLockData(); + $lockedPackages = $dev ? $lockData['packages-dev'] : $lockData['packages']; + + if (empty($lockedPackages) || isset($lockedPackages[0]['name'])) { + return false; + } + + return true; + } + /** * Searches and returns an array of locked packages, retrieved from registered repositories. * @@ -129,9 +147,8 @@ class Locker if (!$package && !empty($info['alias-version'])) { $package = $this->repositoryManager->findPackage($info['package'], $info['version']); if ($package) { - $alias = new AliasPackage($package, $info['alias-version'], $info['alias-pretty-version']); - $package->getRepository()->addPackage($alias); - $package = $alias; + $package->setAlias($info['alias-version']); + $package->setPrettyAlias($info['alias-pretty-version']); } } @@ -142,7 +159,15 @@ class Locker )); } - $packages->addPackage(clone $package); + $package = clone $package; + if (!empty($info['time'])) { + $package->setReleaseDate($info['time']); + } + if (!empty($info['source-reference'])) { + $package->setSourceReference($info['source-reference']); + } + + $packages->addPackage($package); } return $packages; diff --git a/tests/Composer/Test/Fixtures/installer/install-missing-alias-from-lock.test b/tests/Composer/Test/Fixtures/installer/install-missing-alias-from-lock.test new file mode 100644 index 000000000..e5ddacf20 --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/install-missing-alias-from-lock.test @@ -0,0 +1,41 @@ +--TEST-- +Installing an old alias that doesn't exist anymore from a lock is possible +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { + "name": "a/a", "version": "dev-master", + "extra": { "branch-alias": { "dev-master": "2.2.x-dev" } }, + "source": { "reference": "master", "type": "git", "url": "" } + } + ] + } + ], + "require": { + "a/a": "2.1.*" + }, + "minimum-stability": "dev" +} +--LOCK-- +{ + "packages": [ + { + "name": "a/a", "version": "dev-master", "version_normalized": "9999999-dev", + "extra": { "branch-alias": { "dev-master": "2.1.x-dev" } }, + "source": { "reference": "oldmaster", "type": "git", "url": "" }, + "type": "library" + } + ], + "packages-dev": null, + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [] +} +--RUN-- +install +--EXPECT-- +Installing a/a (dev-master oldmaster) +Marking a/a (2.1.x-dev oldmaster) as installed, alias of a/a (dev-master oldmaster)