1
0
Fork 0

extracted `VersionParser::DEV_MASTER_ALIAS` (#8742)

pull/8746/head
Markus Staab 2020-04-07 15:49:07 +02:00 committed by GitHub
parent b166ef4b58
commit c30925e68d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 26 additions and 20 deletions

View File

@ -17,6 +17,7 @@ use Composer\Package\AliasPackage;
use Composer\Repository\RepositorySet; use Composer\Repository\RepositorySet;
use Composer\Repository\LockArrayRepository; use Composer\Repository\LockArrayRepository;
use Composer\Semver\Constraint\Constraint; use Composer\Semver\Constraint\Constraint;
use Composer\Package\Version\VersionParser;
/** /**
* Represents a problem detected while solving dependencies * Represents a problem detected while solving dependencies
@ -295,8 +296,8 @@ class Problem
} }
foreach ($prepared as $name => $package) { foreach ($prepared as $name => $package) {
// remove the implicit dev-master alias to avoid cruft in the display // remove the implicit dev-master alias to avoid cruft in the display
if (isset($package['versions']['9999999-dev']) && isset($package['versions']['dev-master'])) { if (isset($package['versions'][VersionParser::DEV_MASTER_ALIAS]) && isset($package['versions']['dev-master'])) {
unset($package['versions']['9999999-dev']); unset($package['versions'][VersionParser::DEV_MASTER_ALIAS]);
} }
$prepared[$name] = $package['name'].'['.implode(', ', $package['versions']).']'; $prepared[$name] = $package['name'].'['.implode(', ', $package['versions']).']';
} }

View File

@ -17,6 +17,7 @@ use Composer\Package\Link;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Package\AliasPackage; use Composer\Package\AliasPackage;
use Composer\Repository\RepositorySet; use Composer\Repository\RepositorySet;
use Composer\Package\Version\VersionParser;
/** /**
* @author Nils Adermann <naderman@naderman.de> * @author Nils Adermann <naderman@naderman.de>
@ -283,7 +284,7 @@ abstract class Rule
private function deduplicateMasterAlias(PackageInterface $package) private function deduplicateMasterAlias(PackageInterface $package)
{ {
if ($package instanceof AliasPackage && $package->getPrettyVersion() === '9999999-dev') { if ($package instanceof AliasPackage && $package->getPrettyVersion() === VersionParser::DEV_MASTER_ALIAS) {
$package = $package->getAliasOf(); $package = $package->getAliasOf();
} }

View File

@ -173,9 +173,9 @@ class AliasPackage extends BasePackage implements CompletePackageInterface
*/ */
protected function replaceSelfVersionDependencies(array $links, $linkType) protected function replaceSelfVersionDependencies(array $links, $linkType)
{ {
// for self.version requirements, we use the original package's branch name instead of 9999999-dev, to avoid leaking 9999999-dev to users // for self.version requirements, we use the original package's branch name instead, to avoid leaking the magic dev-master-alias to users
$prettyVersion = $this->prettyVersion; $prettyVersion = $this->prettyVersion;
if ($prettyVersion === '9999999-dev') { if ($prettyVersion === VersionParser::DEV_MASTER_ALIAS) {
$prettyVersion = $this->aliasOf->getPrettyVersion(); $prettyVersion = $this->aliasOf->getPrettyVersion();
} }

View File

@ -90,8 +90,8 @@ class ArrayLoader implements LoaderInterface
if (isset($config['version_normalized'])) { if (isset($config['version_normalized'])) {
$version = $config['version_normalized']; $version = $config['version_normalized'];
// handling of existing repos which need to remain composer v1 compatible, in case the version_normalized contained 9999999-dev, we renormalize it // handling of existing repos which need to remain composer v1 compatible, in case the version_normalized contained VersionParser::DEV_MASTER_ALIAS, we renormalize it
if ($version === '9999999-dev') { if ($version === VersionParser::DEV_MASTER_ALIAS) {
$version = $this->versionParser->normalize($config['version']); $version = $this->versionParser->normalize($config['version']);
} }
} else { } else {
@ -362,7 +362,7 @@ class ArrayLoader implements LoaderInterface
} }
if (in_array($config['version'], array('dev-master', 'dev-default', 'dev-trunk'), true)) { if (in_array($config['version'], array('dev-master', 'dev-default', 'dev-trunk'), true)) {
return '9999999-dev'; return VersionParser::DEV_MASTER_ALIAS;
} }
} }
} }

View File

@ -20,6 +20,8 @@ use Composer\Util\Git as GitUtil;
use Composer\Util\HttpDownloader; use Composer\Util\HttpDownloader;
use Composer\Util\ProcessExecutor; use Composer\Util\ProcessExecutor;
use Composer\Util\Svn as SvnUtil; use Composer\Util\Svn as SvnUtil;
use Composer\Package\Version\VersionParser;
/** /**
* Try to guess the current version number based on different VCS configuration. * Try to guess the current version number based on different VCS configuration.
@ -206,7 +208,7 @@ class VersionGuesser
$version = $this->versionParser->normalizeBranch($branch); $version = $this->versionParser->normalizeBranch($branch);
$isFeatureBranch = 0 === strpos($version, 'dev-'); $isFeatureBranch = 0 === strpos($version, 'dev-');
if ('9999999-dev' === $version) { if (VersionParser::DEV_MASTER_ALIAS === $version) {
return array('version' => $version, 'commit' => null, 'pretty_version' => 'dev-'.$branch); return array('version' => $version, 'commit' => null, 'pretty_version' => 'dev-'.$branch);
} }

View File

@ -18,6 +18,8 @@ use Composer\Semver\Semver;
class VersionParser extends SemverVersionParser class VersionParser extends SemverVersionParser
{ {
const DEV_MASTER_ALIAS = '9999999-dev';
private static $constraints = array(); private static $constraints = array();
/** /**
@ -70,8 +72,8 @@ class VersionParser extends SemverVersionParser
*/ */
public static function isUpgrade($normalizedFrom, $normalizedTo) public static function isUpgrade($normalizedFrom, $normalizedTo)
{ {
$normalizedFrom = str_replace(array('dev-master', 'dev-trunk', 'dev-default'), '9999999-dev', $normalizedFrom); $normalizedFrom = str_replace(array('dev-master', 'dev-trunk', 'dev-default'), VersionParser::DEV_MASTER_ALIAS, $normalizedFrom);
$normalizedTo = str_replace(array('dev-master', 'dev-trunk', 'dev-default'), '9999999-dev', $normalizedTo); $normalizedTo = str_replace(array('dev-master', 'dev-trunk', 'dev-default'), VersionParser::DEV_MASTER_ALIAS, $normalizedTo);
if (substr($normalizedFrom, 0, 4) === 'dev-' || substr($normalizedTo, 0, 4) === 'dev-') { if (substr($normalizedFrom, 0, 4) === 'dev-' || substr($normalizedTo, 0, 4) === 'dev-') {
return true; return true;

View File

@ -586,8 +586,8 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
if (!isset($versionsToLoad[$version['uid']])) { if (!isset($versionsToLoad[$version['uid']])) {
if (!isset($version['version_normalized'])) { if (!isset($version['version_normalized'])) {
$version['version_normalized'] = $this->versionParser->normalize($version['version']); $version['version_normalized'] = $this->versionParser->normalize($version['version']);
} elseif ($version['version_normalized'] === '9999999-dev') { } elseif ($version['version_normalized'] === VersionParser::DEV_MASTER_ALIAS) {
// handling of existing repos which need to remain composer v1 compatible, in case the version_normalized contained 9999999-dev, we renormalize it // handling of existing repos which need to remain composer v1 compatible, in case the version_normalized contained VersionParser::DEV_MASTER_ALIAS, we renormalize it
$version['version_normalized'] = $this->versionParser->normalize($version['version']); $version['version_normalized'] = $this->versionParser->normalize($version['version']);
} }
@ -707,8 +707,8 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
foreach ($versions as $version) { foreach ($versions as $version) {
if (!isset($version['version_normalized'])) { if (!isset($version['version_normalized'])) {
$version['version_normalized'] = $repo->versionParser->normalize($version['version']); $version['version_normalized'] = $repo->versionParser->normalize($version['version']);
} elseif ($version['version_normalized'] === '9999999-dev') { } elseif ($version['version_normalized'] === VersionParser::DEV_MASTER_ALIAS) {
// handling of existing repos which need to remain composer v1 compatible, in case the version_normalized contained 9999999-dev, we renormalize it // handling of existing repos which need to remain composer v1 compatible, in case the version_normalized contained VersionParser::DEV_MASTER_ALIAS, we renormalize it
$version['version_normalized'] = $repo->versionParser->normalize($version['version']); $version['version_normalized'] = $repo->versionParser->normalize($version['version']);
} }

View File

@ -279,7 +279,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
if ($branch === 'trunk' && isset($branches['master'])) { if ($branch === 'trunk' && isset($branches['master'])) {
if ($isVeryVerbose) { if ($isVeryVerbose) {
$this->io->writeError('<warning>Skipped branch '.$branch.', can not parse both master and trunk branches as they both resolve to 9999999-dev internally</warning>'); $this->io->writeError('<warning>Skipped branch '.$branch.', can not parse both master and trunk branches as they both resolve to '.VersionParser::DEV_MASTER_ALIAS.' internally</warning>');
} }
continue; continue;
} }
@ -292,7 +292,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
} }
// make sure branch packages have a dev flag // make sure branch packages have a dev flag
if ('dev-' === substr($parsedBranch, 0, 4) || '9999999-dev' === $parsedBranch) { if ('dev-' === substr($parsedBranch, 0, 4) || VersionParser::DEV_MASTER_ALIAS === $parsedBranch) {
$version = 'dev-' . $branch; $version = 'dev-' . $branch;
} else { } else {
$prefix = substr($branch, 0, 1) === 'v' ? 'v' : ''; $prefix = substr($branch, 0, 1) === 'v' ? 'v' : '';

View File

@ -49,9 +49,9 @@ class VersionParserTest extends TestCase
return array( return array(
array('0.9.0.0', '1.0.0.0', true), array('0.9.0.0', '1.0.0.0', true),
array('1.0.0.0', '0.9.0.0', false), array('1.0.0.0', '0.9.0.0', false),
array('1.0.0.0', '9999999-dev', true), array('1.0.0.0', VersionParser::DEV_MASTER_ALIAS, true),
array('9999999-dev', '9999999-dev', true), array(VersionParser::DEV_MASTER_ALIAS, VersionParser::DEV_MASTER_ALIAS, true),
array('9999999-dev', '1.0.0.0', false), array(VersionParser::DEV_MASTER_ALIAS, '1.0.0.0', false),
array('1.0.0.0', 'dev-foo', true), array('1.0.0.0', 'dev-foo', true),
array('dev-foo', 'dev-foo', true), array('dev-foo', 'dev-foo', true),
array('dev-foo', '1.0.0.0', true), array('dev-foo', '1.0.0.0', true),