extracted `VersionParser::DEV_MASTER_ALIAS` (#8742)

main
Markus Staab 4 years ago committed by GitHub
parent b166ef4b58
commit c30925e68d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

@ -17,6 +17,7 @@ use Composer\Package\Link;
use Composer\Package\PackageInterface;
use Composer\Package\AliasPackage;
use Composer\Repository\RepositorySet;
use Composer\Package\Version\VersionParser;
/**
* @author Nils Adermann <naderman@naderman.de>
@ -283,7 +284,7 @@ abstract class Rule
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();
}

@ -173,9 +173,9 @@ class AliasPackage extends BasePackage implements CompletePackageInterface
*/
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;
if ($prettyVersion === '9999999-dev') {
if ($prettyVersion === VersionParser::DEV_MASTER_ALIAS) {
$prettyVersion = $this->aliasOf->getPrettyVersion();
}

@ -90,8 +90,8 @@ class ArrayLoader implements LoaderInterface
if (isset($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
if ($version === '9999999-dev') {
// 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 === VersionParser::DEV_MASTER_ALIAS) {
$version = $this->versionParser->normalize($config['version']);
}
} else {
@ -362,7 +362,7 @@ class ArrayLoader implements LoaderInterface
}
if (in_array($config['version'], array('dev-master', 'dev-default', 'dev-trunk'), true)) {
return '9999999-dev';
return VersionParser::DEV_MASTER_ALIAS;
}
}
}

@ -20,6 +20,8 @@ use Composer\Util\Git as GitUtil;
use Composer\Util\HttpDownloader;
use Composer\Util\ProcessExecutor;
use Composer\Util\Svn as SvnUtil;
use Composer\Package\Version\VersionParser;
/**
* Try to guess the current version number based on different VCS configuration.
@ -206,7 +208,7 @@ class VersionGuesser
$version = $this->versionParser->normalizeBranch($branch);
$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);
}

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

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

@ -279,7 +279,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
if ($branch === 'trunk' && isset($branches['master'])) {
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;
}
@ -292,7 +292,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
}
// 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;
} else {
$prefix = substr($branch, 0, 1) === 'v' ? 'v' : '';

@ -49,9 +49,9 @@ class VersionParserTest extends TestCase
return array(
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', '9999999-dev', true),
array('9999999-dev', '9999999-dev', true),
array('9999999-dev', '1.0.0.0', false),
array('1.0.0.0', VersionParser::DEV_MASTER_ALIAS, true),
array(VersionParser::DEV_MASTER_ALIAS, VersionParser::DEV_MASTER_ALIAS, true),
array(VersionParser::DEV_MASTER_ALIAS, '1.0.0.0', false),
array('1.0.0.0', 'dev-foo', true),
array('dev-foo', 'dev-foo', true),
array('dev-foo', '1.0.0.0', true),

Loading…
Cancel
Save