1
0
Fork 0

Store default branch info inside metadata

pull/8995/head
Jordi Boggiano 2020-06-17 16:09:38 +02:00
parent 04381c70fe
commit ce368f8269
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
6 changed files with 55 additions and 2 deletions

View File

@ -414,6 +414,11 @@ class AliasPackage extends BasePackage implements CompletePackageInterface
return $this->aliasOf->getArchiveExcludes(); return $this->aliasOf->getArchiveExcludes();
} }
public function isDefaultBranch()
{
return $this->aliasOf->isDefaultBranch();
}
public function isAbandoned() public function isAbandoned()
{ {
return $this->aliasOf->isAbandoned(); return $this->aliasOf->isAbandoned();

View File

@ -95,6 +95,10 @@ class ArrayDumper
$data['time'] = $package->getReleaseDate()->format(DATE_RFC3339); $data['time'] = $package->getReleaseDate()->format(DATE_RFC3339);
} }
if ($package->isDefaultBranch()) {
$data['default_branch'] = true;
}
$data = $this->dumpValues($package, $keys, $data); $data = $this->dumpValues($package, $keys, $data);
if ($package instanceof CompletePackageInterface) { if ($package instanceof CompletePackageInterface) {

View File

@ -124,6 +124,10 @@ class ArrayLoader implements LoaderInterface
$package->setInstallationSource($config['installation-source']); $package->setInstallationSource($config['installation-source']);
} }
if (isset($config['default_branch']) && $config['default_branch'] === true) {
$package->setIsDefaultBranch(true);
}
if (isset($config['source'])) { if (isset($config['source'])) {
if (!isset($config['source']['type']) || !isset($config['source']['url']) || !isset($config['source']['reference'])) { if (!isset($config['source']['type']) || !isset($config['source']['url']) || !isset($config['source']['reference'])) {
throw new \UnexpectedValueException(sprintf( throw new \UnexpectedValueException(sprintf(
@ -364,7 +368,7 @@ class ArrayLoader implements LoaderInterface
} }
} }
if (\in_array($config['version'], array('dev-master', 'dev-default', 'dev-trunk'), true)) { if (isset($config['default_branch']) && $config['default_branch'] === true) {
return VersionParser::DEV_MASTER_ALIAS; return VersionParser::DEV_MASTER_ALIAS;
} }
} }

View File

@ -59,6 +59,7 @@ class Package extends BasePackage
protected $includePaths = array(); protected $includePaths = array();
protected $archiveName; protected $archiveName;
protected $archiveExcludes = array(); protected $archiveExcludes = array();
protected $isDefaultBranch = false;
/** /**
* Creates a new in memory package. * Creates a new in memory package.
@ -588,6 +589,22 @@ class Package extends BasePackage
return $this->archiveExcludes; return $this->archiveExcludes;
} }
/**
* @param bool $defaultBranch
*/
public function setIsDefaultBranch($defaultBranch)
{
$this->isDefaultBranch = $defaultBranch;
}
/**
* {@inheritDoc}
*/
public function isDefaultBranch()
{
return $this->isDefaultBranch;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View File

@ -371,6 +371,11 @@ interface PackageInterface
*/ */
public function getArchiveExcludes(); public function getArchiveExcludes();
/**
* @return bool
*/
public function isDefaultBranch();
/** /**
* Returns a list of options to download package dist files * Returns a list of options to download package dist files
* *

View File

@ -167,8 +167,10 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
$this->loader = new ArrayLoader($this->versionParser); $this->loader = new ArrayLoader($this->versionParser);
} }
$hasRootIdentifierComposerJson = false;
try { try {
if ($driver->hasComposerFile($driver->getRootIdentifier())) { $hasRootIdentifierComposerJson = $driver->hasComposerFile($driver->getRootIdentifier());
if ($hasRootIdentifierComposerJson) {
$data = $driver->getComposerInformation($driver->getRootIdentifier()); $data = $driver->getComposerInformation($driver->getRootIdentifier());
$this->packageName = !empty($data['name']) ? $data['name'] : null; $this->packageName = !empty($data['name']) ? $data['name'] : null;
} }
@ -229,6 +231,9 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
$data['version'] = preg_replace('{[.-]?dev$}i', '', $data['version']); $data['version'] = preg_replace('{[.-]?dev$}i', '', $data['version']);
$data['version_normalized'] = preg_replace('{(^dev-|[.-]?dev$)}i', '', $data['version_normalized']); $data['version_normalized'] = preg_replace('{(^dev-|[.-]?dev$)}i', '', $data['version_normalized']);
// make sure tag do not contain the default_branch marker
unset($data['default_branch']);
// broken package, version doesn't match tag // broken package, version doesn't match tag
if ($data['version_normalized'] !== $parsedTag) { if ($data['version_normalized'] !== $parsedTag) {
if ($isVeryVerbose) { if ($isVeryVerbose) {
@ -273,6 +278,11 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
} }
$branches = $driver->getBranches(); $branches = $driver->getBranches();
// make sure the root identifier branch gets loaded first
if ($hasRootIdentifierComposerJson && isset($branches[$driver->getRootIdentifier()])) {
$branches = array($driver->getRootIdentifier() => $branches[$driver->getRootIdentifier()]) + $branches;
}
foreach ($branches as $branch => $identifier) { foreach ($branches as $branch => $identifier) {
$msg = 'Reading composer.json of <info>' . ($this->packageName ?: $this->url) . '</info> (<comment>' . $branch . '</comment>)'; $msg = 'Reading composer.json of <info>' . ($this->packageName ?: $this->url) . '</info> (<comment>' . $branch . '</comment>)';
if ($isVeryVerbose) { if ($isVeryVerbose) {
@ -302,6 +312,9 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
$prefix = substr($branch, 0, 1) === 'v' ? 'v' : ''; $prefix = substr($branch, 0, 1) === 'v' ? 'v' : '';
$version = $prefix . preg_replace('{(\.9{7})+}', '.x', $parsedBranch); $version = $prefix . preg_replace('{(\.9{7})+}', '.x', $parsedBranch);
} }
if ($driver->getRootIdentifier() === $branch) {
$parsedBranch = '9999999-dev';
}
$cachedPackage = $this->getCachedPackageVersion($version, $identifier, $isVerbose, $isVeryVerbose); $cachedPackage = $this->getCachedPackageVersion($version, $identifier, $isVerbose, $isVeryVerbose);
if ($cachedPackage) { if ($cachedPackage) {
@ -327,6 +340,11 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
$data['version'] = $version; $data['version'] = $version;
$data['version_normalized'] = $parsedBranch; $data['version_normalized'] = $parsedBranch;
unset($data['default_branch']);
if ($driver->getRootIdentifier() === $branch) {
$data['default_branch'] = true;
}
if ($isVeryVerbose) { if ($isVeryVerbose) {
$this->io->writeError('Importing branch '.$branch.' ('.$data['version'].')'); $this->io->writeError('Importing branch '.$branch.' ('.$data['version'].')');
} }