diff --git a/src/Composer/Repository/Vcs/GitBitbucketDriver.php b/src/Composer/Repository/Vcs/GitBitbucketDriver.php index 6a4e242a9..8424ba61a 100644 --- a/src/Composer/Repository/Vcs/GitBitbucketDriver.php +++ b/src/Composer/Repository/Vcs/GitBitbucketDriver.php @@ -293,7 +293,7 @@ class GitBitbucketDriver extends VcsDriver } if (null === $this->tags) { - $this->tags = array(); + $tags = array(); $resource = sprintf( '%s?%s', $this->tagsUrl, @@ -311,7 +311,7 @@ class GitBitbucketDriver extends VcsDriver while ($hasNext) { $tagsData = $this->fetchWithOAuthCredentials($resource)->decodeJson(); foreach ($tagsData['values'] as $data) { - $this->tags[$data['name']] = $data['target']['hash']; + $tags[$data['name']] = $data['target']['hash']; } if (empty($tagsData['next'])) { $hasNext = false; @@ -319,6 +319,8 @@ class GitBitbucketDriver extends VcsDriver $resource = $tagsData['next']; } } + + $this->tags = $tags; } return $this->tags; @@ -334,7 +336,7 @@ class GitBitbucketDriver extends VcsDriver } if (null === $this->branches) { - $this->branches = array(); + $branches = array(); $resource = sprintf( '%s?%s', $this->branchesUrl, @@ -352,7 +354,7 @@ class GitBitbucketDriver extends VcsDriver while ($hasNext) { $branchData = $this->fetchWithOAuthCredentials($resource)->decodeJson(); foreach ($branchData['values'] as $data) { - $this->branches[$data['name']] = $data['target']['hash']; + $branches[$data['name']] = $data['target']['hash']; } if (empty($branchData['next'])) { $hasNext = false; @@ -360,6 +362,8 @@ class GitBitbucketDriver extends VcsDriver $resource = $branchData['next']; } } + + $this->branches = $branches; } return $this->branches; diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index f186bb6f5..07daab475 100644 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -322,18 +322,20 @@ class GitHubDriver extends VcsDriver return $this->gitDriver->getTags(); } if (null === $this->tags) { - $this->tags = array(); + $tags = array(); $resource = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository.'/tags?per_page=100'; do { $response = $this->getContents($resource); $tagsData = $response->decodeJson(); foreach ($tagsData as $tag) { - $this->tags[$tag['name']] = $tag['commit']['sha']; + $tags[$tag['name']] = $tag['commit']['sha']; } $resource = $this->getNextPage($response); } while ($resource); + + $this->tags = $tags; } return $this->tags; @@ -348,7 +350,7 @@ class GitHubDriver extends VcsDriver return $this->gitDriver->getBranches(); } if (null === $this->branches) { - $this->branches = array(); + $branches = array(); $resource = $this->getApiUrl() . '/repos/'.$this->owner.'/'.$this->repository.'/git/refs/heads?per_page=100'; do { @@ -357,12 +359,14 @@ class GitHubDriver extends VcsDriver foreach ($branchData as $branch) { $name = substr($branch['ref'], 11); if ($name !== 'gh-pages') { - $this->branches[$name] = $branch['object']['sha']; + $branches[$name] = $branch['object']['sha']; } } $resource = $this->getNextPage($response); } while ($resource); + + $this->branches = $branches; } return $this->branches; diff --git a/src/Composer/Repository/Vcs/SvnDriver.php b/src/Composer/Repository/Vcs/SvnDriver.php index f375c900a..6380ea387 100644 --- a/src/Composer/Repository/Vcs/SvnDriver.php +++ b/src/Composer/Repository/Vcs/SvnDriver.php @@ -222,7 +222,7 @@ class SvnDriver extends VcsDriver public function getTags() { if (null === $this->tags) { - $this->tags = array(); + $tags = array(); if ($this->tagsPath !== false) { $output = $this->execute('svn ls --verbose', $this->baseUrl . '/' . $this->tagsPath); @@ -231,7 +231,7 @@ class SvnDriver extends VcsDriver $line = trim($line); if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) { if (isset($match[1], $match[2]) && $match[2] !== './') { - $this->tags[rtrim($match[2], '/')] = $this->buildIdentifier( + $tags[rtrim($match[2], '/')] = $this->buildIdentifier( '/' . $this->tagsPath . '/' . $match[2], $match[1] ); @@ -240,6 +240,8 @@ class SvnDriver extends VcsDriver } } } + + $this->tags = $tags; } return $this->tags; @@ -251,7 +253,7 @@ class SvnDriver extends VcsDriver public function getBranches() { if (null === $this->branches) { - $this->branches = array(); + $branches = array(); if (false === $this->trunkPath) { $trunkParent = $this->baseUrl . '/'; @@ -265,11 +267,11 @@ class SvnDriver extends VcsDriver $line = trim($line); if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) { if (isset($match[1], $match[2]) && $match[2] === './') { - $this->branches['trunk'] = $this->buildIdentifier( + $branches['trunk'] = $this->buildIdentifier( '/' . $this->trunkPath, $match[1] ); - $this->rootIdentifier = $this->branches['trunk']; + $this->rootIdentifier = $branches['trunk']; break; } } @@ -284,7 +286,7 @@ class SvnDriver extends VcsDriver $line = trim($line); if ($line && preg_match('{^\s*(\S+).*?(\S+)\s*$}', $line, $match)) { if (isset($match[1], $match[2]) && $match[2] !== './') { - $this->branches[rtrim($match[2], '/')] = $this->buildIdentifier( + $branches[rtrim($match[2], '/')] = $this->buildIdentifier( '/' . $this->branchesPath . '/' . $match[2], $match[1] ); @@ -293,6 +295,8 @@ class SvnDriver extends VcsDriver } } } + + $this->branches = $branches; } return $this->branches; diff --git a/src/Composer/Repository/VcsRepository.php b/src/Composer/Repository/VcsRepository.php index b6b0f7cc2..2281f1c76 100644 --- a/src/Composer/Repository/VcsRepository.php +++ b/src/Composer/Repository/VcsRepository.php @@ -212,6 +212,10 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt $this->packageName = !empty($data['name']) ? $data['name'] : null; } } catch (\Exception $e) { + if ($e instanceof TransportException && $this->shouldRethrowTransportException($e)) { + throw $e; + } + if ($isVeryVerbose) { $this->io->writeError('Skipped parsing '.$driver->getRootIdentifier().', '.$e->getMessage().''); } @@ -303,7 +307,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt if ($e->getCode() === 404) { $this->emptyReferences[] = $identifier; } - if (in_array($e->getCode(), array(401, 403, 429), true)) { + if ($this->shouldRethrowTransportException($e)) { throw $e; } } @@ -392,7 +396,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt if ($e->getCode() === 404) { $this->emptyReferences[] = $identifier; } - if (in_array($e->getCode(), array(401, 403, 429), true)) { + if ($this->shouldRethrowTransportException($e)) { throw $e; } if ($isVeryVerbose) { @@ -531,4 +535,12 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt return null; } + + /** + * @return bool + */ + private function shouldRethrowTransportException(TransportException $e) + { + return in_array($e->getCode(), array(401, 403, 429), true) || $e->getCode() >= 500; + } }