From 05dacbdabb64083fea7ba4880bf0ea23b0a0c837 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 25 Jun 2020 08:56:14 +0200 Subject: [PATCH] Rename DEV_MASTER_ALIAS to DEFAULT_BRANCH_ALIAS --- src/Composer/Command/CreateProjectCommand.php | 4 ++-- src/Composer/DependencyResolver/Problem.php | 10 +++++++--- src/Composer/DependencyResolver/Rule.php | 18 +++++++++--------- src/Composer/Package/AliasPackage.php | 2 +- src/Composer/Package/Loader/ArrayLoader.php | 6 +++--- .../Package/Version/VersionGuesser.php | 2 +- src/Composer/Package/Version/VersionParser.php | 12 ++++++++---- src/Composer/Repository/ComposerRepository.php | 8 ++++---- src/Composer/Repository/VcsRepository.php | 2 +- .../installer/update-mirrors-changes-url.test | 4 ++-- .../Test/Package/Version/VersionParserTest.php | 6 +++--- 11 files changed, 41 insertions(+), 33 deletions(-) diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 27d9919d7..c0470e096 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -388,8 +388,8 @@ EOT } } - // avoid displaying 9999999-dev as version if dev-master was selected - if ($package instanceof AliasPackage && $package->getPrettyVersion() === VersionParser::DEV_MASTER_ALIAS) { + // avoid displaying 9999999-dev as version if default-branch was selected + if ($package instanceof AliasPackage && $package->getPrettyVersion() === VersionParser::DEFAULT_BRANCH_ALIAS) { $package = $package->getAliasOf(); } diff --git a/src/Composer/DependencyResolver/Problem.php b/src/Composer/DependencyResolver/Problem.php index eed4c5043..6d94b068b 100644 --- a/src/Composer/DependencyResolver/Problem.php +++ b/src/Composer/DependencyResolver/Problem.php @@ -329,14 +329,18 @@ class Problem public static function getPackageList(array $packages, $isVerbose) { $prepared = array(); + $hasDefaultBranch = array(); foreach ($packages as $package) { $prepared[$package->getName()]['name'] = $package->getPrettyName(); $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) { - // remove the implicit dev-master alias to avoid cruft in the display - if (isset($package['versions'][VersionParser::DEV_MASTER_ALIAS]) && isset($package['versions']['dev-master'])) { - unset($package['versions'][VersionParser::DEV_MASTER_ALIAS]); + // remove the implicit default branch alias to avoid cruft in the display + if (isset($package['versions'][VersionParser::DEFAULT_BRANCH_ALIAS]) && isset($hasDefaultBranch[$name])) { + unset($package['versions'][VersionParser::DEFAULT_BRANCH_ALIAS]); } uksort($package['versions'], 'version_compare'); diff --git a/src/Composer/DependencyResolver/Rule.php b/src/Composer/DependencyResolver/Rule.php index 4cb36258c..ee71929e5 100644 --- a/src/Composer/DependencyResolver/Rule.php +++ b/src/Composer/DependencyResolver/Rule.php @@ -183,7 +183,7 @@ abstract class Rule return 'Root composer.json requires '.$packageName.($constraint ? ' '.$constraint->getPrettyString() : '').' -> satisfiable by '.$this->formatPackagesUnique($pool, $packages, $isVerbose).'.'; case self::RULE_FIXED: - $package = $this->deduplicateMasterAlias($this->reasonData['package']); + $package = $this->deduplicateDefaultBranchAlias($this->reasonData['package']); if ($this->reasonData['lockable']) { 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'; case self::RULE_PACKAGE_CONFLICT: - $package1 = $this->deduplicateMasterAlias($pool->literalToPackage($literals[0])); - $package2 = $this->deduplicateMasterAlias($pool->literalToPackage($literals[1])); + $package1 = $this->deduplicateDefaultBranchAlias($pool->literalToPackage($literals[0])); + $package2 = $this->deduplicateDefaultBranchAlias($pool->literalToPackage($literals[1])); return $package2->getPrettyString().' conflicts with '.$package1->getPrettyString().'.'; case self::RULE_PACKAGE_REQUIRES: $sourceLiteral = array_shift($literals); - $sourcePackage = $this->deduplicateMasterAlias($pool->literalToPackage($sourceLiteral)); + $sourcePackage = $this->deduplicateDefaultBranchAlias($pool->literalToPackage($sourceLiteral)); $requires = array(); foreach ($literals as $literal) { @@ -281,7 +281,7 @@ abstract class Rule $group = $literal > 0 ? 'install' : 'don\'t install'; } - $groups[$group][] = $this->deduplicateMasterAlias($package); + $groups[$group][] = $this->deduplicateDefaultBranchAlias($package); } $ruleTexts = array(); foreach ($groups as $group => $packages) { @@ -295,10 +295,10 @@ abstract class Rule case self::RULE_PACKAGE_ALIAS: $aliasPackage = $pool->literalToPackage($literals[0]); // 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 ''; } - $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.'; default: @@ -342,9 +342,9 @@ abstract class Rule 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(); } diff --git a/src/Composer/Package/AliasPackage.php b/src/Composer/Package/AliasPackage.php index 7d843c6ba..a3bc117f0 100644 --- a/src/Composer/Package/AliasPackage.php +++ b/src/Composer/Package/AliasPackage.php @@ -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 $prettyVersion = $this->prettyVersion; - if ($prettyVersion === VersionParser::DEV_MASTER_ALIAS) { + if ($prettyVersion === VersionParser::DEFAULT_BRANCH_ALIAS) { $prettyVersion = $this->aliasOf->getPrettyVersion(); } diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index b2330e6e2..3d7b3b614 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -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 VersionParser::DEV_MASTER_ALIAS, we renormalize it - if ($version === VersionParser::DEV_MASTER_ALIAS) { + // 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::DEFAULT_BRANCH_ALIAS) { $version = $this->versionParser->normalize($config['version']); } } else { @@ -369,7 +369,7 @@ class ArrayLoader implements LoaderInterface } if (isset($config['default-branch']) && $config['default-branch'] === true) { - return VersionParser::DEV_MASTER_ALIAS; + return VersionParser::DEFAULT_BRANCH_ALIAS; } } } diff --git a/src/Composer/Package/Version/VersionGuesser.php b/src/Composer/Package/Version/VersionGuesser.php index 6cf185685..1c2f99247 100644 --- a/src/Composer/Package/Version/VersionGuesser.php +++ b/src/Composer/Package/Version/VersionGuesser.php @@ -210,7 +210,7 @@ class VersionGuesser $version = $this->versionParser->normalizeBranch($branch); $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); } diff --git a/src/Composer/Package/Version/VersionParser.php b/src/Composer/Package/Version/VersionParser.php index 29bdab37b..ab75126c3 100644 --- a/src/Composer/Package/Version/VersionParser.php +++ b/src/Composer/Package/Version/VersionParser.php @@ -18,8 +18,8 @@ use Composer\Semver\Semver; class VersionParser extends SemverVersionParser { - const DEV_MASTER_ALIAS = '9999999-dev'; - + const DEFAULT_BRANCH_ALIAS = '9999999-dev'; + private static $constraints = array(); /** @@ -72,8 +72,12 @@ class VersionParser extends SemverVersionParser */ public static function isUpgrade($normalizedFrom, $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 ($normalizedFrom === $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-') { return true; diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index f7462c89f..74ce15e8a 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -596,8 +596,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'] === 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 + } 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::DEFAULT_BRANCH_ALIAS, we renormalize it $version['version_normalized'] = $this->versionParser->normalize($version['version']); } @@ -717,8 +717,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'] === 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 + } 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::DEFAULT_BRANCH_ALIAS, we renormalize it $version['version_normalized'] = $repo->versionParser->normalize($version['version']); } diff --git a/src/Composer/Repository/VcsRepository.php b/src/Composer/Repository/VcsRepository.php index f3d7fe56b..5c6c09557 100644 --- a/src/Composer/Repository/VcsRepository.php +++ b/src/Composer/Repository/VcsRepository.php @@ -306,7 +306,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt } // 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; } else { $prefix = substr($branch, 0, 1) === 'v' ? 'v' : ''; diff --git a/tests/Composer/Test/Fixtures/installer/update-mirrors-changes-url.test b/tests/Composer/Test/Fixtures/installer/update-mirrors-changes-url.test index 9bfca4c85..554783fc0 100644 --- a/tests/Composer/Test/Fixtures/installer/update-mirrors-changes-url.test +++ b/tests/Composer/Test/Fixtures/installer/update-mirrors-changes-url.test @@ -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 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 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 --COMPOSER-- { diff --git a/tests/Composer/Test/Package/Version/VersionParserTest.php b/tests/Composer/Test/Package/Version/VersionParserTest.php index 6e4ab7cc3..e4c15245e 100644 --- a/tests/Composer/Test/Package/Version/VersionParserTest.php +++ b/tests/Composer/Test/Package/Version/VersionParserTest.php @@ -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', 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', VersionParser::DEFAULT_BRANCH_ALIAS, true), + array(VersionParser::DEFAULT_BRANCH_ALIAS, VersionParser::DEFAULT_BRANCH_ALIAS, true), + array(VersionParser::DEFAULT_BRANCH_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),