1
0
Fork 0

Added references for dev versions, fixes #599

dev-<branch> and <n.m>.x-dev versions can now have a #<reference> appended
to them. This reference being a git/hg commit hash, or svn revision.
pull/702/head
Jordi Boggiano 2012-05-16 17:14:25 +02:00
parent 799a478f2a
commit ba29b4bf94
6 changed files with 139 additions and 34 deletions

View File

@ -1,5 +1,6 @@
* 1.0.0-alpha4 * 1.0.0-alpha4
* Schema: Added references for dev versions, requiring 'dev-master#abcdef' for example will force the abcdef commit
* Added caching of GitHub metadata (faster startup time with custom GitHub VCS repos) * Added caching of GitHub metadata (faster startup time with custom GitHub VCS repos)
* 1.0.0-alpha3 (2012-05-13) * 1.0.0-alpha3 (2012-05-13)

View File

@ -294,7 +294,6 @@ class Installer
} }
// force dev packages to be updated if we update or install from a (potentially new) lock // force dev packages to be updated if we update or install from a (potentially new) lock
if ($this->update || $installFromLock) {
foreach ($localRepo->getPackages() as $package) { foreach ($localRepo->getPackages() as $package) {
// skip non-dev packages // skip non-dev packages
if (!$package->isDev()) { if (!$package->isDev()) {
@ -310,14 +309,8 @@ class Installer
} }
} }
// force update to latest on update
if ($this->update) {
$newPackage = $this->repositoryManager->findPackage($package->getName(), $package->getVersion());
if ($newPackage && $newPackage->getSourceReference() !== $package->getSourceReference()) {
$operations[] = new UpdateOperation($package, $newPackage);
}
} elseif ($installFromLock) {
// force update to locked version if it does not match the installed version // force update to locked version if it does not match the installed version
if ($installFromLock) {
$lockData = $this->locker->getLockData(); $lockData = $this->locker->getLockData();
unset($lockedReference); unset($lockedReference);
foreach ($lockData['packages'] as $lockedPackage) { foreach ($lockData['packages'] as $lockedPackage) {
@ -328,8 +321,23 @@ class Installer
} }
if (isset($lockedReference) && $lockedReference !== $package->getSourceReference()) { if (isset($lockedReference) && $lockedReference !== $package->getSourceReference()) {
// changing the source ref to update to will be handled in the operations loop below // changing the source ref to update to will be handled in the operations loop below
$operations[] = new UpdateOperation($package, $package); $operations[] = new UpdateOperation($package, clone $package);
} }
} else {
// force update to latest on update
if ($this->update) {
$newPackage = $this->repositoryManager->findPackage($package->getName(), $package->getVersion());
if ($newPackage && $newPackage->getSourceReference() !== $package->getSourceReference()) {
$operations[] = new UpdateOperation($package, $newPackage);
}
}
// force installed package to update to referenced version if it does not match the installed version
$references = $this->package->getReferences();
if (isset($references[$package->getName()]) && $references[$package->getName()] !== $package->getSourceReference()) {
// changing the source ref to update to will be handled in the operations loop below
$operations[] = new UpdateOperation($package, clone $package);
} }
} }
} }
@ -378,7 +386,22 @@ class Installer
} }
} }
} }
} else {
// not installing from lock, force dev packages' references if they're in root package refs
$package = null;
if ('update' === $operation->getJobType()) {
$package = $operation->getTargetPackage();
} elseif ('install' === $operation->getJobType()) {
$package = $operation->getPackage();
} }
if ($package && $package->isDev()) {
$references = $this->package->getReferences();
if (isset($references[$package->getName()])) {
$package->setSourceReference($references[$package->getName()]);
}
}
}
$this->installationManager->execute($localRepo, $operation); $this->installationManager->execute($localRepo, $operation);
$event = 'Composer\Script\ScriptEvents::POST_PACKAGE_'.strtoupper($operation->getJobType()); $event = 'Composer\Script\ScriptEvents::POST_PACKAGE_'.strtoupper($operation->getJobType());

View File

@ -63,17 +63,18 @@ class RootPackageLoader extends ArrayLoader
$aliases = array(); $aliases = array();
$stabilityFlags = array(); $stabilityFlags = array();
if (isset($config['require'])) { $references = array();
$aliases = $this->extractAliases($config['require'], $aliases); foreach (array('require', 'require-dev') as $linkType) {
$stabilityFlags = $this->extractStabilityFlags($config['require'], $stabilityFlags); if (isset($config[$linkType])) {
$aliases = $this->extractAliases($config[$linkType], $aliases);
$stabilityFlags = $this->extractStabilityFlags($config[$linkType], $stabilityFlags);
$references = $this->extractReferences($config[$linkType], $references);
} }
if (isset($config['require-dev'])) {
$aliases = $this->extractAliases($config['require-dev'], $aliases);
$stabilityFlags = $this->extractStabilityFlags($config['require-dev'], $stabilityFlags);
} }
$package->setAliases($aliases); $package->setAliases($aliases);
$package->setStabilityFlags($stabilityFlags); $package->setStabilityFlags($stabilityFlags);
$package->setReferences($references);
if (isset($config['minimum-stability'])) { if (isset($config['minimum-stability'])) {
$package->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability'])); $package->setMinimumStability(VersionParser::normalizeStability($config['minimum-stability']));
@ -145,4 +146,16 @@ class RootPackageLoader extends ArrayLoader
return $stabilityFlags; return $stabilityFlags;
} }
private function extractReferences(array $requires, array $references)
{
foreach ($requires as $reqName => $reqVersion) {
if (preg_match('{^[^,\s@]+?#([a-f0-9]+)$}', $reqVersion, $match) && 'dev' === ($stabilityName = VersionParser::parseStability($reqVersion))) {
$name = strtolower($reqName);
$references[$name] = $match[1];
}
}
return $references;
}
} }

View File

@ -51,6 +51,7 @@ class MemoryPackage extends BasePackage
// TODO BC change dev to stable end of june? // TODO BC change dev to stable end of june?
protected $minimumStability = 'dev'; protected $minimumStability = 'dev';
protected $stabilityFlags = array(); protected $stabilityFlags = array();
protected $references = array();
protected $requires = array(); protected $requires = array();
protected $conflicts = array(); protected $conflicts = array();
@ -637,6 +638,24 @@ class MemoryPackage extends BasePackage
return $this->stabilityFlags; return $this->stabilityFlags;
} }
/**
* Set the references
*
* @param array $references
*/
public function setReferences(array $references)
{
$this->references = $references;
}
/**
* {@inheritDoc}
*/
public function getReferences()
{
return $this->references;
}
/** /**
* Set the autoload mapping * Set the autoload mapping
* *

View File

@ -0,0 +1,21 @@
--TEST--
Installs a dev package forcing it's reference
--COMPOSER--
{
"repositories": [
{
"type": "package",
"package": [
{
"name": "a/a", "version": "dev-master",
"source": { "reference": "abc123", "url": "", "type": "git" }
}
]
}
],
"require": {
"a/a": "dev-master#def000"
}
}
--EXPECT--
Installing a/a (dev-master def000)

View File

@ -0,0 +1,28 @@
--TEST--
Updates a dev package forcing it's reference
--COMPOSER--
{
"repositories": [
{
"type": "package",
"package": [
{
"name": "a/a", "version": "dev-master",
"source": { "reference": "abc123", "url": "", "type": "git" }
}
]
}
],
"require": {
"a/a": "dev-master#def000"
}
}
--INSTALLED--
[
{
"name": "a/a", "version": "dev-master",
"source": { "reference": "abc123", "url": "", "type": "git" }
}
]
--EXPECT--
Updating a/a (dev-master abc123) to a/a (dev-master def000)