1
0
Fork 0

Rename DEV_MASTER_ALIAS to DEFAULT_BRANCH_ALIAS

pull/9026/head
Jordi Boggiano 2020-06-25 08:56:14 +02:00
parent 821e575658
commit 05dacbdabb
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
11 changed files with 41 additions and 33 deletions

View File

@ -388,8 +388,8 @@ EOT
} }
} }
// avoid displaying 9999999-dev as version if dev-master was selected // avoid displaying 9999999-dev as version if default-branch was selected
if ($package instanceof AliasPackage && $package->getPrettyVersion() === VersionParser::DEV_MASTER_ALIAS) { if ($package instanceof AliasPackage && $package->getPrettyVersion() === VersionParser::DEFAULT_BRANCH_ALIAS) {
$package = $package->getAliasOf(); $package = $package->getAliasOf();
} }

View File

@ -329,14 +329,18 @@ class Problem
public static function getPackageList(array $packages, $isVerbose) public static function getPackageList(array $packages, $isVerbose)
{ {
$prepared = array(); $prepared = array();
$hasDefaultBranch = array();
foreach ($packages as $package) { foreach ($packages as $package) {
$prepared[$package->getName()]['name'] = $package->getPrettyName(); $prepared[$package->getName()]['name'] = $package->getPrettyName();
$prepared[$package->getName()]['versions'][$package->getVersion()] = $package->getPrettyVersion().($package instanceof AliasPackage ? ' (alias of '.$package->getAliasOf()->getPrettyVersion().')' : ''); $prepared[$package->getName()]['versions'][$package->getVersion()] = $package->getPrettyVersion().($package instanceof AliasPackage ? ' (alias of '.$package->getAliasOf()->getPrettyVersion().')' : '');
if ($package->isDefaultBranch()) {
$hasDefaultBranch[$package->getName()] = true;
}
} }
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 default branch alias to avoid cruft in the display
if (isset($package['versions'][VersionParser::DEV_MASTER_ALIAS]) && isset($package['versions']['dev-master'])) { if (isset($package['versions'][VersionParser::DEFAULT_BRANCH_ALIAS]) && isset($hasDefaultBranch[$name])) {
unset($package['versions'][VersionParser::DEV_MASTER_ALIAS]); unset($package['versions'][VersionParser::DEFAULT_BRANCH_ALIAS]);
} }
uksort($package['versions'], 'version_compare'); uksort($package['versions'], 'version_compare');

View File

@ -183,7 +183,7 @@ abstract class Rule
return 'Root composer.json requires '.$packageName.($constraint ? ' '.$constraint->getPrettyString() : '').' -> satisfiable by '.$this->formatPackagesUnique($pool, $packages, $isVerbose).'.'; return 'Root composer.json requires '.$packageName.($constraint ? ' '.$constraint->getPrettyString() : '').' -> satisfiable by '.$this->formatPackagesUnique($pool, $packages, $isVerbose).'.';
case self::RULE_FIXED: case self::RULE_FIXED:
$package = $this->deduplicateMasterAlias($this->reasonData['package']); $package = $this->deduplicateDefaultBranchAlias($this->reasonData['package']);
if ($this->reasonData['lockable']) { if ($this->reasonData['lockable']) {
return $package->getPrettyName().' is locked to version '.$package->getPrettyVersion().' and an update of this package was not requested.'; return $package->getPrettyName().' is locked to version '.$package->getPrettyVersion().' and an update of this package was not requested.';
} }
@ -191,14 +191,14 @@ abstract class Rule
return $package->getPrettyName().' is present at version '.$package->getPrettyVersion() . ' and cannot be modified by Composer'; return $package->getPrettyName().' is present at version '.$package->getPrettyVersion() . ' and cannot be modified by Composer';
case self::RULE_PACKAGE_CONFLICT: case self::RULE_PACKAGE_CONFLICT:
$package1 = $this->deduplicateMasterAlias($pool->literalToPackage($literals[0])); $package1 = $this->deduplicateDefaultBranchAlias($pool->literalToPackage($literals[0]));
$package2 = $this->deduplicateMasterAlias($pool->literalToPackage($literals[1])); $package2 = $this->deduplicateDefaultBranchAlias($pool->literalToPackage($literals[1]));
return $package2->getPrettyString().' conflicts with '.$package1->getPrettyString().'.'; return $package2->getPrettyString().' conflicts with '.$package1->getPrettyString().'.';
case self::RULE_PACKAGE_REQUIRES: case self::RULE_PACKAGE_REQUIRES:
$sourceLiteral = array_shift($literals); $sourceLiteral = array_shift($literals);
$sourcePackage = $this->deduplicateMasterAlias($pool->literalToPackage($sourceLiteral)); $sourcePackage = $this->deduplicateDefaultBranchAlias($pool->literalToPackage($sourceLiteral));
$requires = array(); $requires = array();
foreach ($literals as $literal) { foreach ($literals as $literal) {
@ -281,7 +281,7 @@ abstract class Rule
$group = $literal > 0 ? 'install' : 'don\'t install'; $group = $literal > 0 ? 'install' : 'don\'t install';
} }
$groups[$group][] = $this->deduplicateMasterAlias($package); $groups[$group][] = $this->deduplicateDefaultBranchAlias($package);
} }
$ruleTexts = array(); $ruleTexts = array();
foreach ($groups as $group => $packages) { foreach ($groups as $group => $packages) {
@ -295,10 +295,10 @@ abstract class Rule
case self::RULE_PACKAGE_ALIAS: case self::RULE_PACKAGE_ALIAS:
$aliasPackage = $pool->literalToPackage($literals[0]); $aliasPackage = $pool->literalToPackage($literals[0]);
// avoid returning content like "9999999-dev is an alias of dev-master" as it is useless // avoid returning content like "9999999-dev is an alias of dev-master" as it is useless
if ($aliasPackage->getVersion() === VersionParser::DEV_MASTER_ALIAS) { if ($aliasPackage->getVersion() === VersionParser::DEFAULT_BRANCH_ALIAS) {
return ''; return '';
} }
$package = $this->deduplicateMasterAlias($pool->literalToPackage($literals[1])); $package = $this->deduplicateDefaultBranchAlias($pool->literalToPackage($literals[1]));
return $aliasPackage->getPrettyString() .' is an alias of '.$package->getPrettyString().' and thus requires it to be installed too.'; return $aliasPackage->getPrettyString() .' is an alias of '.$package->getPrettyString().' and thus requires it to be installed too.';
default: default:
@ -342,9 +342,9 @@ abstract class Rule
return $names; return $names;
} }
private function deduplicateMasterAlias(PackageInterface $package) private function deduplicateDefaultBranchAlias(PackageInterface $package)
{ {
if ($package instanceof AliasPackage && $package->getPrettyVersion() === VersionParser::DEV_MASTER_ALIAS) { if ($package instanceof AliasPackage && $package->getPrettyVersion() === VersionParser::DEFAULT_BRANCH_ALIAS) {
$package = $package->getAliasOf(); $package = $package->getAliasOf();
} }

View File

@ -176,7 +176,7 @@ class AliasPackage extends BasePackage implements CompletePackageInterface
{ {
// for self.version requirements, we use the original package's branch name instead, to avoid leaking the magic dev-master-alias 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 === VersionParser::DEV_MASTER_ALIAS) { if ($prettyVersion === VersionParser::DEFAULT_BRANCH_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 VersionParser::DEV_MASTER_ALIAS, we renormalize it // handling of existing repos which need to remain composer v1 compatible, in case the version_normalized contained VersionParser::DEFAULT_BRANCH_ALIAS, we renormalize it
if ($version === VersionParser::DEV_MASTER_ALIAS) { if ($version === VersionParser::DEFAULT_BRANCH_ALIAS) {
$version = $this->versionParser->normalize($config['version']); $version = $this->versionParser->normalize($config['version']);
} }
} else { } else {
@ -369,7 +369,7 @@ class ArrayLoader implements LoaderInterface
} }
if (isset($config['default-branch']) && $config['default-branch'] === true) { if (isset($config['default-branch']) && $config['default-branch'] === true) {
return VersionParser::DEV_MASTER_ALIAS; return VersionParser::DEFAULT_BRANCH_ALIAS;
} }
} }
} }

View File

@ -210,7 +210,7 @@ class VersionGuesser
$version = $this->versionParser->normalizeBranch($branch); $version = $this->versionParser->normalizeBranch($branch);
$isFeatureBranch = 0 === strpos($version, 'dev-'); $isFeatureBranch = 0 === strpos($version, 'dev-');
if (VersionParser::DEV_MASTER_ALIAS === $version) { if (VersionParser::DEFAULT_BRANCH_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,7 +18,7 @@ use Composer\Semver\Semver;
class VersionParser extends SemverVersionParser class VersionParser extends SemverVersionParser
{ {
const DEV_MASTER_ALIAS = '9999999-dev'; const DEFAULT_BRANCH_ALIAS = '9999999-dev';
private static $constraints = array(); private static $constraints = array();
@ -72,8 +72,12 @@ 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'), VersionParser::DEV_MASTER_ALIAS, $normalizedFrom); if ($normalizedFrom === $normalizedTo) {
$normalizedTo = str_replace(array('dev-master', 'dev-trunk', 'dev-default'), VersionParser::DEV_MASTER_ALIAS, $normalizedTo); return true;
}
$normalizedFrom = str_replace(array('dev-master', 'dev-trunk', 'dev-default'), VersionParser::DEFAULT_BRANCH_ALIAS, $normalizedFrom);
$normalizedTo = str_replace(array('dev-master', 'dev-trunk', 'dev-default'), VersionParser::DEFAULT_BRANCH_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

@ -596,8 +596,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'] === VersionParser::DEV_MASTER_ALIAS) { } elseif ($version['version_normalized'] === VersionParser::DEFAULT_BRANCH_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 // handling of existing repos which need to remain composer v1 compatible, in case the version_normalized contained VersionParser::DEFAULT_BRANCH_ALIAS, we renormalize it
$version['version_normalized'] = $this->versionParser->normalize($version['version']); $version['version_normalized'] = $this->versionParser->normalize($version['version']);
} }
@ -717,8 +717,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'] === VersionParser::DEV_MASTER_ALIAS) { } elseif ($version['version_normalized'] === VersionParser::DEFAULT_BRANCH_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 // handling of existing repos which need to remain composer v1 compatible, in case the version_normalized contained VersionParser::DEFAULT_BRANCH_ALIAS, we renormalize it
$version['version_normalized'] = $repo->versionParser->normalize($version['version']); $version['version_normalized'] = $repo->versionParser->normalize($version['version']);
} }

View File

@ -306,7 +306,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) || VersionParser::DEV_MASTER_ALIAS === $parsedBranch) { if ('dev-' === substr($parsedBranch, 0, 4) || VersionParser::DEFAULT_BRANCH_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

@ -3,10 +3,10 @@ Update mirrors updates URLs for all packages if they have changed without updati
a/a is dev and gets everything updated as it updates to a new ref a/a is dev and gets everything updated as it updates to a new ref
b/b is a tag and gets everything updated by updating the package URL directly b/b is a tag and gets everything updated by updating the package URL directly
c/c is a tag and not whitelisted and gets the new URL but keeps its old ref c/c is a tag and not allowlisted for update and gets the new URL but keeps its old ref
d/d is dev but with a #ref so it should get URL updated but not the reference d/d is dev but with a #ref so it should get URL updated but not the reference
e/e is dev and newly installed with a #ref so it should get the correct URL but with the #111 ref e/e is dev and newly installed with a #ref so it should get the correct URL but with the #111 ref
e/e is dev but not whitelisted and gets the new URL but keeps its old ref e/e is dev but not allowlisted for update and gets the new URL but keeps its old ref
g/g is dev and installed in a different ref than the #ref, so it gets updated and gets the new URL but not the new ref g/g is dev and installed in a different ref than the #ref, so it gets updated and gets the new URL but not the new ref
--COMPOSER-- --COMPOSER--
{ {

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', VersionParser::DEV_MASTER_ALIAS, true), array('1.0.0.0', VersionParser::DEFAULT_BRANCH_ALIAS, true),
array(VersionParser::DEV_MASTER_ALIAS, VersionParser::DEV_MASTER_ALIAS, true), array(VersionParser::DEFAULT_BRANCH_ALIAS, VersionParser::DEFAULT_BRANCH_ALIAS, true),
array(VersionParser::DEV_MASTER_ALIAS, '1.0.0.0', false), array(VersionParser::DEFAULT_BRANCH_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),