1
0
Fork 0

Undo changes to providers, only unlock replacers when unlocking a given name

pull/10280/head
Jordi Boggiano 2021-11-23 16:02:34 +01:00
parent 3242de2438
commit bbc442b0ad
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
3 changed files with 31 additions and 41 deletions

View File

@ -156,10 +156,10 @@ class PoolBuilder
foreach ($request->getLockedRepository()->getPackages() as $lockedPackage) { foreach ($request->getLockedRepository()->getPackages() as $lockedPackage) {
if (!$this->isUpdateAllowed($lockedPackage)) { if (!$this->isUpdateAllowed($lockedPackage)) {
$request->lockPackage($lockedPackage); $request->lockPackage($lockedPackage);
$lockedName = $lockedPackage->getName(); $this->skippedLoad[$lockedPackage->getName()][] = $lockedPackage;
// remember which packages we skipped loading remote content for in this partial update // remember which packages we skipped loading remote content for in this partial update
foreach ($lockedPackage->getNames() as $name) { foreach ($lockedPackage->getReplaces() as $link) {
$this->skippedLoad[$name][] = $lockedPackage; $this->skippedLoad[$link->getTarget()][] = $lockedPackage;
} }
} }
} }
@ -493,33 +493,25 @@ class PoolBuilder
if (isset($rootRequires[$name])) { if (isset($rootRequires[$name])) {
return array_map(function (PackageInterface $package) use ($name) { return array_map(function (PackageInterface $package) use ($name) {
if ($name !== $package->getName()) { if ($name !== $package->getName()) {
foreach ($package->getReplaces() as $link) {
if ($link->getTarget() === $name) {
return $package->getName() .' (via replace of '.$name.')'; return $package->getName() .' (via replace of '.$name.')';
} }
}
return $package->getName() .' (via provide of '.$name.')';
}
return $package->getName(); return $package->getName();
}, $this->skippedLoad[$name]); }, $this->skippedLoad[$name]);
} }
foreach ($this->skippedLoad[$name] as $providedBy) { foreach ($this->skippedLoad[$name] as $packageOrReplacer) {
foreach ($providedBy->getNames() as $providedName) { if (isset($rootRequires[$packageOrReplacer->getName()])) {
if (isset($rootRequires[$providedName])) { $matches[] = $packageOrReplacer->getName();
if ($name !== $providedBy->getName()) {
foreach ($providedBy->getReplaces() as $link) {
if ($link->getTarget() === $name) {
$matches[] = $providedBy->getName() .' (via replace of '.$name.')';
continue 2;
} }
foreach ($packageOrReplacer->getReplaces() as $link) {
if (isset($rootRequires[$link->getTarget()])) {
if ($name !== $packageOrReplacer->getName()) {
$matches[] = $packageOrReplacer->getName() .' (via replace of '.$name.')';
} else {
$matches[] = $packageOrReplacer->getName();
} }
$matches[] = $providedBy->getName() .' (via provide of '.$name.')'; break;
continue;
}
$matches[] = $providedBy->getName();
} }
} }
} }
@ -590,21 +582,21 @@ class PoolBuilder
*/ */
private function unlockPackage(Request $request, $name) private function unlockPackage(Request $request, $name)
{ {
foreach ($this->skippedLoad[$name] as $providedBy) { foreach ($this->skippedLoad[$name] as $packageOrReplacer) {
$providedBy = $providedBy->getName();
// if we unfixed a replaced package name, we also need to unfix the replacer itself // if we unfixed a replaced package name, we also need to unfix the replacer itself
// as long as it was not unfixed yet // as long as it was not unfixed yet
if ($providedBy !== $name && isset($this->skippedLoad[$providedBy])) { if ($packageOrReplacer->getName() !== $name && isset($this->skippedLoad[$packageOrReplacer->getName()])) {
if ($request->getUpdateAllowTransitiveRootDependencies() || (!$this->isRootRequire($request, $name) && !$this->isRootRequire($request, $providedBy))) { $replacerName = $packageOrReplacer->getName();
$this->unlockPackage($request, $providedBy); if ($request->getUpdateAllowTransitiveRootDependencies() || (!$this->isRootRequire($request, $name) && !$this->isRootRequire($request, $replacerName))) {
$this->unlockPackage($request, $replacerName);
if ($this->isRootRequire($request, $providedBy)) { if ($this->isRootRequire($request, $replacerName)) {
$this->markPackageNameForLoading($request, $providedBy, new MatchAllConstraint); $this->markPackageNameForLoading($request, $replacerName, new MatchAllConstraint);
} else { } else {
foreach ($this->packages as $loadedPackage) { foreach ($this->packages as $loadedPackage) {
$requires = $loadedPackage->getRequires(); $requires = $loadedPackage->getRequires();
if (isset($requires[$providedBy])) { if (isset($requires[$replacerName])) {
$this->markPackageNameForLoading($request, $providedBy, $requires[$providedBy]->getConstraint()); $this->markPackageNameForLoading($request, $replacerName, $requires[$replacerName]->getConstraint());
} }
} }
} }

View File

@ -1,5 +1,5 @@
--TEST-- --TEST--
Ensure a partial update of a dependency updates dependencies which provide its requirements. Ensure a partial update of a dependency does NOT update dependencies which provide its requirements.
--COMPOSER-- --COMPOSER--
{ {
@ -44,9 +44,9 @@ update root/req1 --with-dependencies
--EXPECT-LOCK-- --EXPECT-LOCK--
{ {
"packages": [ "packages": [
{"name": "dep/pkg1", "version": "1.2.0", "type": "library", "provide": {"virtual/pkg1": "2.0.0"}}, {"name": "dep/pkg1", "version": "1.0.0", "type": "library", "provide": {"virtual/pkg1": "1.0.0"}},
{"name": "dep/pkg2", "version": "1.2.0", "type": "library", "provide": {"virtual/pkg1": "2.0.0"}}, {"name": "dep/pkg2", "version": "1.0.0", "type": "library", "provide": {"virtual/pkg1": "1.0.0"}},
{"name": "root/req1", "version": "2.0.0", "type": "library", "require": {"virtual/pkg1": "2.*"}}, {"name": "root/req1", "version": "1.0.0", "type": "library", "require": {"virtual/pkg1": "1.*"}},
{"name": "root/req2", "version": "1.0.0", "type": "library", "require": {"dep/pkg1": "1.*", "dep/pkg2": "1.*"}} {"name": "root/req2", "version": "1.0.0", "type": "library", "require": {"dep/pkg1": "1.*", "dep/pkg2": "1.*"}}
], ],
"packages-dev": [], "packages-dev": [],
@ -59,7 +59,7 @@ update root/req1 --with-dependencies
"platform-dev": [] "platform-dev": []
} }
--EXPECT-- --EXPECT--
Installing dep/pkg1 (1.2.0) Installing dep/pkg1 (1.0.0)
Installing dep/pkg2 (1.2.0) Installing dep/pkg2 (1.0.0)
Installing root/req1 (2.0.0) Installing root/req1 (1.0.0)
Installing root/req2 (1.0.0) Installing root/req2 (1.0.0)

View File

@ -110,8 +110,6 @@ update update/pkg1 --with-dependencies
--EXPECT-OUTPUT-- --EXPECT-OUTPUT--
Loading composer repositories with package information Loading composer repositories with package information
<warning>Dependency root/pkg3 is also a root requirement. Package has not been listed as an update argument, so keeping locked at old version. Use --with-all-dependencies (-W) to include root dependencies.</warning> <warning>Dependency root/pkg3 is also a root requirement. Package has not been listed as an update argument, so keeping locked at old version. Use --with-all-dependencies (-W) to include root dependencies.</warning>
<warning>Dependency dep/pkg5 (via provide of root/provided-pkg4) is also a root requirement. Package has not been listed as an update argument, so keeping locked at old version. Use --with-all-dependencies (-W) to include root dependencies.</warning>
<warning>Dependency dep/pkg6 (via provide of root/provided-pkg4) is also a root requirement. Package has not been listed as an update argument, so keeping locked at old version. Use --with-all-dependencies (-W) to include root dependencies.</warning>
<warning>Dependency dep/pkg9 (via replace of root/replaced-pkg8) is also a root requirement. Package has not been listed as an update argument, so keeping locked at old version. Use --with-all-dependencies (-W) to include root dependencies.</warning> <warning>Dependency dep/pkg9 (via replace of root/replaced-pkg8) is also a root requirement. Package has not been listed as an update argument, so keeping locked at old version. Use --with-all-dependencies (-W) to include root dependencies.</warning>
Updating dependencies Updating dependencies
Lock file operations: 0 installs, 2 updates, 0 removals Lock file operations: 0 installs, 2 updates, 0 removals