From 6473dd91850460b9825fa8300b71e7712618bafe Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 27 Feb 2019 15:03:25 +0100 Subject: [PATCH] Minor improvements to VersionCacheInterface --- src/Composer/Repository/VcsRepository.php | 28 +++++++++++++++++++ .../Repository/VersionCacheInterface.php | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Composer/Repository/VcsRepository.php b/src/Composer/Repository/VcsRepository.php index d6fb1bbee..9a9ba5833 100644 --- a/src/Composer/Repository/VcsRepository.php +++ b/src/Composer/Repository/VcsRepository.php @@ -43,6 +43,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt private $driver; /** @var VersionCacheInterface */ private $versionCache; + private $emptyReferences = array(); public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $dispatcher = null, array $drivers = null, VersionCacheInterface $versionCache = null) { @@ -117,6 +118,11 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt return $this->branchErrorOccurred; } + public function getEmptyReferences() + { + return $this->emptyReferences; + } + protected function initialize() { parent::initialize(); @@ -159,6 +165,10 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt if ($cachedPackage) { $this->addPackage($cachedPackage); + continue; + } elseif ($cachedPackage === false) { + $this->emptyReferences[] = $identifier; + continue; } @@ -174,6 +184,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt if ($verbose) { $this->io->writeError('Skipped tag '.$tag.', no composer file'); } + $this->emptyReferences[] = $identifier; continue; } @@ -212,6 +223,9 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt $this->addPackage($this->loader->load($this->preProcess($driver, $data, $identifier))); } catch (\Exception $e) { + if ($e instanceof TransportException) { + $this->emptyReferences[] = $identifier; + } if ($verbose) { $this->io->writeError('Skipped tag '.$tag.', '.($e instanceof TransportException ? 'no composer file was found' : $e->getMessage()).''); } @@ -258,6 +272,10 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt if ($cachedPackage) { $this->addPackage($cachedPackage); + continue; + } elseif ($cachedPackage === false) { + $this->emptyReferences[] = $identifier; + continue; } @@ -266,6 +284,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt if ($verbose) { $this->io->writeError('Skipped branch '.$branch.', no composer file'); } + $this->emptyReferences[] = $identifier; continue; } @@ -284,6 +303,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt } $this->addPackage($package); } catch (TransportException $e) { + $this->emptyReferences[] = $identifier; if ($verbose) { $this->io->writeError('Skipped branch '.$branch.', no composer file was found'); } @@ -352,6 +372,14 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt } $cachedPackage = $this->versionCache->getVersionPackage($version, $identifier); + if ($cachedPackage === false) { + if ($verbose) { + $this->io->writeError('Skipped '.$version.', no composer file (cached from ref '.$identifier.')'); + } + + return false; + } + if ($cachedPackage) { $msg = 'Found cached composer.json of ' . ($this->packageName ?: $this->url) . ' (' . $version . ')'; if ($verbose) { diff --git a/src/Composer/Repository/VersionCacheInterface.php b/src/Composer/Repository/VersionCacheInterface.php index db5934b59..41d485c64 100644 --- a/src/Composer/Repository/VersionCacheInterface.php +++ b/src/Composer/Repository/VersionCacheInterface.php @@ -17,7 +17,7 @@ interface VersionCacheInterface /** * @param string $version * @param string $identifier - * @return array Package version data + * @return array|null|false Package version data if found, false to indicate the identifier is known but has no package, null for an unknown identifier */ public function getVersionPackage($version, $identifier); }